//+------------------------------------------------------------------+ //| TrendLineArrows.mq4 | //| Copyright 2018, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2018, MetaQuotes Software Corp." #property link "https://www.mql5.com" #property version "1.00" #property strict #property indicator_buffers 2 #property indicator_chart_window #property indicator_color1 clrBlue #property indicator_color2 clrYellow #property indicator_width1 2 #property indicator_width2 2 input int LookBack=20; input int XDelay=5; input int ConsecutiveBar=3; input bool ShowTrendLines=true; double upBuffer[],dnBuffer[]; datetime prevShift=0; string cid="tlArr"; string tlup,tldn; datetime expired=D'2020.07.10'; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- indicator buffers mapping SetIndexBuffer(0,upBuffer); SetIndexStyle(0,DRAW_ARROW); SetIndexArrow(0,233); SetIndexBuffer(1,dnBuffer); SetIndexStyle(1,DRAW_ARROW); SetIndexArrow(1,234); prevShift=0; tlup=cid+"up"; tldn=cid+"dn"; //--- return(INIT_SUCCEEDED); } void OnDeinit(const int reason) { ObjectsDeleteAll(0,cid); } //+------------------------------------------------------------------+ //| 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[]) { //--- int limit=rates_total-prev_calculated; if(prev_calculated==0) { limit=(rates_total-prev_calculated)-(LookBack+1); } for(int i=limit; i>=1; i--) { upBuffer[i]=EMPTY_VALUE; dnBuffer[i]=EMPTY_VALUE; int shift=iBarShift(Symbol(),0,prevShift); if(shift >= XDelay+1) { prevShift=time[i]; int hhigh=iHighest(Symbol(),0,MODE_HIGH,LookBack,i); int lhigh=iLowest(Symbol(),0,MODE_HIGH,LookBack,i); int hlow=iHighest(Symbol(),0,MODE_LOW,LookBack,i); int llow=iLowest(Symbol(),0,MODE_LOW,LookBack,i); if(hhigh > lhigh) { string name=tldn; datetime t1=time[hhigh]; datetime t2=time[lhigh]; double p1=high[hhigh]; double p2=high[lhigh]; color c=clrRed; DrawTrend(name,t1,p1,t2,p2,c); } if(llow > hlow) { string name=tlup; datetime t1=time[llow]; datetime t2=time[hlow]; double p1=low[llow]; double p2=low[hlow]; color c=clrLime; DrawTrend(name,t1,p1,t2,p2,c); } } if(ObjectGet(tlup,OBJPROP_PRICE1)>0) { int counter=0; for(int j=i; j=0.0) break; double val=ObjectGetValueByTime(0,tlup,time[j]); if(close[j]>val) break; counter++; } if(counter == ConsecutiveBar) { double val1=ObjectGetValueByTime(0,tlup,time[ConsecutiveBar+i]); double val2=ObjectGetValueByTime(0,tlup,time[ConsecutiveBar+1+i]); double val3=ObjectGetValueByTime(0,tlup,time[ConsecutiveBar+2+i]); if(close[i+ConsecutiveBar]>val1 || (close[i+ConsecutiveBar+2] > val3 && close[i+ConsecutiveBar+1] <= val2 && close[i+ConsecutiveBar+1] > open[i+ConsecutiveBar+1])) { double diff=high[i]-low[i]; double perc=diff*0.2; if(perc < Point) perc=Point; dnBuffer[i]=high[i]+perc; if(ShowTrendLines) { datetime t1=(datetime)ObjectGetInteger(0,tlup,OBJPROP_TIME1); datetime t2=(datetime)ObjectGetInteger(0,tlup,OBJPROP_TIME2); double p1=ObjectGet(tlup,OBJPROP_PRICE1); double p2=ObjectGet(tlup,OBJPROP_PRICE2); DrawTrend(tlup+(string)prevShift,t1,p1,t2,p2,clrGray); } } } } if(ObjectGet(tldn,OBJPROP_PRICE1)>0) { int counter=0; for(int j=i; j= val2 && close[i+ConsecutiveBar+1] < open[i+ConsecutiveBar+1])) { double diff=high[i]-low[i]; double perc=diff*0.2; if(perc < Point) perc=Point; upBuffer[i]=low[i]-perc; if(ShowTrendLines) { datetime t1=(datetime)ObjectGetInteger(0,tldn,OBJPROP_TIME1); datetime t2=(datetime)ObjectGetInteger(0,tldn,OBJPROP_TIME2); double p1=ObjectGet(tldn,OBJPROP_PRICE1); double p2=ObjectGet(tldn,OBJPROP_PRICE2); DrawTrend(tldn+(string)prevShift,t1,p1,t2,p2,clrGray); } } } } } //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+ void DrawTrend(string name, datetime t1, double p1, datetime t2, double p2, color c) { ObjectCreate(0,name,OBJ_TREND,0,0,0); ObjectSet(name,OBJPROP_PRICE1, p1); ObjectSet(name,OBJPROP_PRICE2, p2); ObjectSet(name,OBJPROP_TIME1, t1); ObjectSet(name,OBJPROP_TIME2, t2); ObjectSetInteger(0,name,OBJPROP_COLOR,c); ObjectSetInteger(0,name,OBJPROP_RAY,TRUE); ObjectSetInteger(0,name,OBJPROP_SELECTABLE,false); } //+------------------------------------------------------------------+