//+------------------------------------------------------------------+ //| Instantaneous Trend Line by John Ehlers | //| Copyright © 2004, Poul_Trade_Forum | //| Aborigen | //| http://forex.kbpauk.ru/ | //+------------------------------------------------------------------+ #property copyright "JDP" #property link "" #property indicator_separate_window #property indicator_buffers 2 #property indicator_color1 Red #property indicator_color2 Blue //---- buffers extern int Periods=200; extern double PeriodPers=1.0; extern int OffsetDegrees=45; extern bool alert=false; int alerttm=0; int LastTm; double SineWave[]; double LeadSine[]; double RealPart,ImagPart,DCPhase,Period_,tmp; double Pi = 3.1415926535; double Price[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { string short_name; IndicatorBuffers(2); //---- indicator line SetIndexStyle(0,DRAW_LINE,EMPTY,2,Red); SetIndexStyle(1,DRAW_LINE,EMPTY,2,Blue); SetIndexBuffer(0,SineWave); SetIndexBuffer(1,LeadSine); SetIndexEmptyValue(0,0); SetIndexEmptyValue(1,0); //---- name for DataWindow and indicator subwindow label short_name="Sine Wave Indicator"; IndicatorShortName(short_name); SetIndexLabel(0,short_name); //---- SetIndexDrawBegin(0,30); SetIndexDrawBegin(1,30); //---- return(0); } int deinit(){return(0);} int start() { int i,shift,count; if (LastTm < Time[0]) { for (i = 0;i<1000;i++) { SineWave[i] = SineWave[i+1]; LeadSine[i] = LeadSine[i+1]; } LastTm = Time[0]; } for (i = 1001;i>0;i--) { SineWave[i] = SineWave[i-1]; LeadSine[i] = LeadSine[i-1]; } i = 0; for (shift=i; shift>=0;shift--) { Period_ = iCustom(Symbol(),0,"#TickA_SineWavePeriods",Periods,0,shift); Period_ = Period_*PeriodPers; Period_ = NormalizeDouble(Period_,0); RealPart=0.0; ImagPart=0.0; for (count = 0;count<=Period_ - 1;count++) { RealPart = RealPart + MathSin(360*count/Period_*Pi/180) * ((iCustom(Symbol(),0,"#TickPrice",0,(shift+count))+iCustom(Symbol(),0,"#TickPrice",1,(shift+count)))/2);//Close[shift+count]; ImagPart = ImagPart + MathCos(360*count/Period_*Pi/180) * ((iCustom(Symbol(),0,"#TickPrice",0,(shift+count))+iCustom(Symbol(),0,"#TickPrice",1,(shift+count)))/2);//Close[shift+count]; } if (MathAbs(ImagPart) != 0) { DCPhase = 180/Pi*MathArctan(RealPart / ImagPart); } else { if (RealPart > 0) { DCPhase = (Pi / 2); } else { DCPhase = -(Pi/2); } } if (MathAbs(ImagPart) < 0) //(MathAbs(ImagPart) < 0.0001) { if (RealPart>0) { DCPhase = DCPhase+90; } else { if (RealPart <0) { DCPhase = DCPhase-90; } else { DCPhase = 0; } } } DCPhase=DCPhase+90; if (ImagPart < 0) DCPhase = DCPhase + 180;//(ImagPart < 0.0001) DCPhase = DCPhase + 180; if (DCPhase > 360) DCPhase = DCPhase - 360; // if (Period_ > 0) Trendline = Trendline / (Period_ + 2); // Value11[0] = 0.33*(Price[shift] + 0.5*(Price[shift] - Price[shift+3])) + 0.67*Value11[1]; SineWave[shift]=MathSin(DCPhase*Pi/180); LeadSine[shift]=MathSin((DCPhase+OffsetDegrees)*Pi/180); } return(0); }
Sample
Analysis
Market Information Used:
Series array that contains open time of each bar
Indicator Curves created:
Implements a curve of type DRAW_LINE
Indicators Used:
Custom Indicators Used:
#TickA_SineWavePeriods
#TickPrice
Order Management characteristics:
Other Features: