//+------------------------------------------------------------------+ //| ExTrend.mq4 | //| Copyright © 2006, Alex Sidd (Executer) | //| http://www.metaquotes.net/ | //+------------------------------------------------------------------+ #property copyright "Copyright © 2006, Alex Sidd (Executer)" #property link "mailto:work_st@mail.ru" //---- #property indicator_separate_window #property indicator_minimum -0.5 #property indicator_maximum 0.5 #property indicator_buffers 2 #property indicator_color1 Green #property indicator_color2 Red //---- double TrBufferUp[]; double TrBufferDn[]; //---- double FractUp1 = 0; double FractUp2 = 0; double FractDn1 = 0; double FractDn2 = 0; datetime FTimeUp1,FTimeUp2,FTimeDn1,FTimeDn2,curTime; //+------------------------------------------------------------------+ //| ExTrend initialization function | //+------------------------------------------------------------------+ int init() { string short_name; IndicatorBuffers(2); SetIndexStyle(0,DRAW_LINE); SetIndexBuffer(0,TrBufferUp); SetIndexDrawBegin(0,1); SetIndexStyle(1,DRAW_LINE); SetIndexBuffer(1,TrBufferDn); SetIndexDrawBegin(1,1); short_name="ExTrend"; IndicatorShortName(short_name); SetIndexLabel(0,"Up_Line"); SetIndexLabel(1,"Down_Line"); //---- return(0); } //+------------------------------------------------------------------+ //| deinitialization function | //+------------------------------------------------------------------+ int deinit() { ObjectDelete("FractalLineUp"); ObjectDelete("FractalLineDn"); //---- return(0); } //+------------------------------------------------------------------+ //| Level Calculate Function | //| функция взята из FractalLines Indicator | //+------------------------------------------------------------------+ double LevelCalculate(double Price1,double Time1,double Price2, double Time2,double NewTime) { double level; if(Time2!=Time1) // На всякий случай, чтобы не было деления на 0. { level=(NewTime-Time1); level=level*(Price2-Price1); level=level/double(Time2-Time1)+Price1; } else return(Price2); return(level); } //+------------------------------------------------------------------+ //| Executer Trend Indicator | //+------------------------------------------------------------------+ int start() { int i,counted_bars=IndicatorCounted(); double Fup,Fdn,positive,negative; i=Bars-counted_bars; if(counted_bars==0) i-=4; while(i>=0) { negative = 0; positive = 0; Fup = iFractals(NULL, 0, MODE_UPPER, i + 3); Fdn = iFractals(NULL, 0, MODE_LOWER, i + 3); if(Fup>0) { if(FractUp1==0 && FractUp2==0) { FractUp1 = Fup; FTimeUp1 = Time[i+3]; } if(FractUp1!=0 && FractUp2==0 && FTimeUp1!=Time[i+3]) { FractUp2 = Fup; FTimeUp2 = Time[i+3]; } if(FractUp1!=0 && FractUp2!=0 && FTimeUp2!=Time[i+3]) { FractUp1 = FractUp2; FTimeUp1 = FTimeUp2; FractUp2 = Fup; FTimeUp2 = Time[i+3]; } } if(Fdn>0) { if(FractDn1==0 && FractDn2==0) { FractDn1 = Fdn; FTimeDn1 = Time[i+3]; } if(FractDn1!=0 && FractDn2==0 && FTimeDn1!=Time[i+3]) { FractDn2 = Fdn; FTimeDn2 = Time[i+3]; } if(FractDn1!=0 && FractDn2!=0 && FTimeDn2!=Time[i+3]) { FractDn1 = FractDn2; FTimeDn1 = FTimeDn2; FractDn2 = Fdn; FTimeDn2 = Time[i+3]; } } if(FractUp1!=0 && FractUp2!=0) { double lvlup=LevelCalculate(FractUp1,FTimeUp1,FractUp2,FTimeUp2,Time[i]); ObjectCreate("FractalLineUp",OBJ_TREND,0,FTimeUp1,FractUp1,FTimeUp2,FractUp2); ObjectSet("FractalLineUp",OBJPROP_TIME1,FTimeUp1); ObjectSet("FractalLineUp",OBJPROP_PRICE1,FractUp1); ObjectSet("FractalLineUp",OBJPROP_TIME2,FTimeUp2); ObjectSet("FractalLineUp",OBJPROP_PRICE2,FractUp2); double y = (double(FTimeUp2 - FTimeUp1) )/ (240*60); double x = (FractUp2 - FractUp1)*(240); // if(x==0) x=1; positive=MathArctan(x/y); //*180/3.14; //) } if(FractDn1!=0 && FractDn2!=0) { double lvldn=LevelCalculate(FractDn1,FTimeDn1,FractDn2,FTimeDn2,Time[i]); ObjectCreate("FractalLineDn",OBJ_TREND,0,FTimeDn1,FractDn1,FTimeDn2,FractDn2); ObjectSet("FractalLineDn",OBJPROP_TIME1,FTimeDn1); ObjectSet("FractalLineDn",OBJPROP_PRICE1,FractDn1); ObjectSet("FractalLineDn",OBJPROP_TIME2,FTimeDn2); ObjectSet("FractalLineDn",OBJPROP_PRICE2,FractDn2); double a = (double(FTimeDn2 - FTimeDn1)) / (240*60); double b = (FractDn2 - FractDn1)*(240); // if(b==0) b=1; negative=MathArctan(b/a); //*180/3.14; } TrBufferUp[i+3]=positive; //+negative; TrBufferDn[i+3]= negative; i--; } return(0); } //+------------------------------------------------------------------+