//+------------------------------------------------------------------+ //| Tendency_Estimate.mq4 | //| Hs | //| http://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Hs" #property link "http://www.mql5.com" #property version "1.00" #property strict #property indicator_separate_window #property indicator_minimum -1 #property indicator_maximum 1 #property indicator_buffers 1 #property indicator_plots 1 //--- plot Label1 #property indicator_label1 "Label1" #property indicator_type1 DRAW_LINE #property indicator_color1 clrForestGreen #property indicator_style1 STYLE_SOLID #property indicator_width1 1 //--- input parameters input int points=100; // Target Points //--- indicator buffers double Label1Buffer[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- indicator buffers mapping SetIndexBuffer(0,Label1Buffer); //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, const int prev_calculated, const datetime &time[], const double &open[], const double &high[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[]) { double dev=points*Point; int counted_bars=prev_calculated; if(counted_bars<0) return(-1); if(counted_bars>0) counted_bars--; int limit = MathMin(rates_total-counted_bars,rates_total-1); // // // // // for(int i=limit; i>=0; i--) { double cprice=open[i]; // starting price double cmax=cprice+dev; double cmin=cprice-dev; double rmax=cprice; double rmin=cprice; bool break_up=false; bool break_down=false; for(int j=i;j>=0;j--) { rmax=MathMax(rmax,high[j]); rmin=MathMin(rmin,low[j]); if((open[j]+high[j]+close[j])>=cmax*3) break_up=true; else break_up=false; if((open[j]+low[j]+close[j])<=cmin*3) break_down=true; else break_down=false; if(break_up || break_down) break; } if(break_up && !break_down) { rmin=(rmin-cprice)/dev; if(rmin<=-1) Label1Buffer[i]=0; else Label1Buffer[i]=rmin+1; } else if(!break_up && break_down) { rmax=(rmax-cprice)/dev; if(rmax>1) Label1Buffer[i]=0; else Label1Buffer[i]=rmax-1; } else { Label1Buffer[i]=NULL; // result in unknown } } return(rates_total); }