//+------------------------------------------------------------------+
//| Rj_FiboAverage.mq4 |
//| Copyright � 2011,RJ Rjabkov Alexander |
//| rj-a@mail.ru |
//+------------------------------------------------------------------+
#property copyright "Copyright � 2011,RJ Rjabkov Alexander"
#property link "rj-a@mail.ru"
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 CLR_NONE
extern int NumDay = 2;
extern color ClrLevel = Yellow;
extern color ClrLevelMain = Red;
double MainLine[];
int init() {
IndicatorBuffers(1);
SetIndexBuffer(0, MainLine);
return(0);
}
int deinit() {
for(int d=0; d<=Bars; d++) {
for(int k=0; k<=24; k++) {
ObjectDelete(d+"fibo"+k);
ObjectDelete(d+"value"+k);
}
}
return(0);
}
int start() {
double Fibo[]={423.6,261.8,176.4,138.2,123.6,100,76.4,61.8,50,38.2,23.6,0,-23.6,-38.2,-50,-61.8,-76.4,-100,-123.6,-138.2,-161.8,-176.4,-261.8,-423.6};
int i, cb, j, cDay;
int counted_bars = IndicatorCounted();
if (counted_bars < 0) return(-1);
if (counted_bars > 0) counted_bars--;
cb=Bars-counted_bars;
double point=0.0001;
int cauntarr=ArraySize(Fibo);
//------------------
for(i=cb; i>=0; i--) MainLine[i] = iMA(NULL, PERIOD_D1, 5, 0, 1, 1, i);
for(cDay=0; cDay<=NumDay; cDay++) {
for(j=0; j<cauntarr; j++) {
ObjectDelete(cDay+"fibo"+j);
ObjectDelete(cDay+"value"+j);
double level = MainLine[cDay+1]+(MainLine[cDay+1]*Fibo[j]*point);
int width;
datetime Tm1 = iTime(NULL, PERIOD_D1, cDay);
datetime Tm2 = Tm1+24*3600;
color clr;
if(Fibo[j]==0) {clr=ClrLevelMain; width=2;}
else {clr=ClrLevel; width=1;}
ObjectCreate(cDay+"fibo"+j, OBJ_TREND, 0,Tm1,level,Tm2,level);
ObjectSet(cDay+"fibo"+j, OBJPROP_COLOR, clr);
ObjectSet(cDay+"fibo"+j, OBJPROP_WIDTH, width);
ObjectSet(cDay+"fibo"+j, OBJPROP_BACK, true);
ObjectSet(cDay+"fibo"+j, OBJPROP_RAY, false);
ObjectCreate(cDay+"value"+j, OBJ_TEXT, 0, Tm1, level);
ObjectSetText(cDay+"value"+j, DoubleToStr(Fibo[j], 1)+" %",8,"Tahoma",clr);
}
}
return(0);
}
//+------------------------------------------------------------------+