Indicators: ATRStops_v1.1_Alert
Help, for some reason in the terminal does not draw the upper red line, only the lower blue.
It works fine on most charts. But on two charts it doesn't draw the red line :(
I apologise, I added a screenshot.
For example, on the RTS index chart everything works, but on the RTS futures chart there is only a blue line.
I apologise, I added a screenshot.
For example, everything works on the RTS index chart, but on the RTS futures chart there is only a blue line.
//+------------------------------------------------------------------+ //|ATRStops_v1.1_Alert.mq5 | //|Copyright © 2006, Forex-TSD.com | //| Written by IgorAD,igorad2003@yahoo.co.uk | //| http://finance.groups.yahoo.com/group/TrendLaboratory | //+------------------------------------------------------------------+ //---- indicator authorship #property copyright "Copyright © 2006, Forex-TSD.com " //---- link to author's website #property link "http://www.forex-tsd.com/" //---- indicator version number #property version "1.10" //---- draw indicator in the main window #property indicator_chart_window //---- 4 buffers are used for calculation and drawing of the indicator #property indicator_buffers 4 //---- used 4 graphical constructions #property indicator_plots 4 //+----------------------------------------------+ //|| Parameters of drawing of the bullish indicator | //+----------------------------------------------+ //---- drawing of indicator 1 as a line #property indicator_type1 DRAW_LINE //---- blue colour is used as indicator line colour #property indicator_color1 clrBlue //---- indicator line 1 - solid #property indicator_style1 STYLE_SOLID //---- indicator 1 line thickness is 2 #property indicator_width1 2 //---- display indicator line marker #property indicator_label1 "Upper ATRStops_v1.1" //+----------------------------------------------+ //|| Bearish indicator rendering parameters | //+----------------------------------------------+ //---- drawing of indicator 2 as a line #property indicator_type2 DRAW_LINE //---- IndianRed colour is used as indicator line colour #property indicator_color2 clrIndianRed //---- indicator line 2 - solid #property indicator_style2 STYLE_SOLID //---- indicator 2 line thickness is 2 #property indicator_width2 2 //---- display indicator line marker #property indicator_label2 "Lower ATRStops_v1.1" //+----------------------------------------------+ //|| Parameters of drawing of the bullish indicator | //+----------------------------------------------+ //---- drawing of indicator 3 as an icon #property indicator_type3 DRAW_ARROW //---- colour Blue is used as indicator colour #property indicator_color3 clrBlue //---- thickness of indicator 3 is 4 #property indicator_width3 4 //---- display indicator label #property indicator_label3 "Buy ATRStops_v1.1" //+----------------------------------------------+ //|| Bearish indicator rendering parameters | //+----------------------------------------------+ //---- drawing of indicator 4 as an icon #property indicator_type4 DRAW_ARROW //---- the colour Red is used as indicator colour #property indicator_color4 clrRed //---- thickness of indicator 4 is 4 #property indicator_width4 4 //---- display indicator label #property indicator_label4 "Sell ATRStops_v1.1" //+----------------------------------------------+ //|| Indicator input parameters | //+----------------------------------------------+ input uint Length=10; // Indicator period input uint ATRPeriod=5; // ATR indicator period input double Kv=2.5; // ATR volatility input int Shift=0; // Shift of the indicator horizontally in bars input uint NumberofBar=1; // Bar number for signalling input bool SoundON=true; // Alert resolution input uint NumberofAlerts=2; // Number of alerts input bool EMailON=false; // Enable mailing of the signal input bool PushON=false; // Enable sending a signal to the mobile phone //+----------------------------------------------+ //---- declaration of dynamic arrays, which are further //---- will be used as indicator buffers double ExtMapBufferUp[]; double ExtMapBufferDown[]; double ExtMapBufferUp1[]; double ExtMapBufferDown1[]; //---- declaration of integer variables for indicator handles int ATR_Handle; //---- declaration of integer data start variables int min_rates_total; //+------------------------------------------------------------------+ //| Custom indicator initialisation function | //+------------------------------------------------------------------+ int OnInit() { //---- get ATR indicator handle ATR_Handle=iATR(NULL,0,ATRPeriod); if(ATR_Handle==INVALID_HANDLE) { Print(" Failed to get ATR indicator handle"); return(1); } //---- initialisation of data start variables min_rates_total=int(ATRPeriod+Length); //---- turning dynamic array ExtMapBufferUp[] into indicator buffer SetIndexBuffer(0,ExtMapBufferUp,INDICATOR_DATA); //---- shifting indicator 1 horizontally by Shift PlotIndexSetInteger(0,PLOT_SHIFT,Shift); //---- shifting the start of the indicator drawing countdown 1 PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,min_rates_total); //---- indexing of items in buffers, as in timeseries ArraySetAsSeries(ExtMapBufferUp,true); //---- setting of indicator values that will not be visible on the chart PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,EMPTY_VALUE); //---- turning dynamic array ExtMapBufferDown[] into indicator buffer SetIndexBuffer(1,ExtMapBufferDown,INDICATOR_DATA); //---- shifting indicator 2 horizontally by Shift PlotIndexSetInteger(1,PLOT_SHIFT,Shift); //---- shifting the start of the indicator drawing countdown 2 PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,min_rates_total); //---- indexing of items in buffers, as in timeseries ArraySetAsSeries(ExtMapBufferDown,true); //---- setting of indicator values that will not be visible on the chart PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,EMPTY_VALUE); //---- turning dynamic array ExtMapBufferUp1[] into indicator buffer SetIndexBuffer(2,ExtMapBufferUp1,INDICATOR_DATA); //---- shifting indicator 1 horizontally by Shift PlotIndexSetInteger(2,PLOT_SHIFT,Shift); //---- shift of the indicator drawing start 3 PlotIndexSetInteger(2,PLOT_DRAW_BEGIN,min_rates_total); //---- indexing of items in buffers, as in timeseries ArraySetAsSeries(ExtMapBufferUp1,true); //---- setting of indicator values that will not be visible on the chart PlotIndexSetDouble(2,PLOT_EMPTY_VALUE,EMPTY_VALUE); //---- character for indicator PlotIndexSetInteger(2,PLOT_ARROW,175); //---- turning dynamic array ExtMapBufferDown1[] into indicator buffer SetIndexBuffer(3,ExtMapBufferDown1,INDICATOR_DATA); //---- shifting indicator 2 horizontally by Shift PlotIndexSetInteger(3,PLOT_SHIFT,Shift); //---- shift of the indicator drawing start 4 PlotIndexSetInteger(3,PLOT_DRAW_BEGIN,min_rates_total); //---- indexing of items in buffers, as in timeseries ArraySetAsSeries(ExtMapBufferDown1,true); //---- setting of indicator values that will not be visible on the chart PlotIndexSetDouble(3,PLOT_EMPTY_VALUE,EMPTY_VALUE); //---- character for indicator PlotIndexSetInteger(3,PLOT_ARROW,175); //---- initialisation of the variable for the short indicator name string shortname; StringConcatenate(shortname,"ATRStops_v1.1(",Length,", ",ATRPeriod,", ",DoubleToString(Kv,4),", ",Shift,")"); //--- creating a name to be displayed in a separate subwindow and tooltip IndicatorSetString(INDICATOR_SHORTNAME,shortname); //--- determining the accuracy of displaying the indicator values IndicatorSetInteger(INDICATOR_DIGITS,_Digits); //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, // amount of history in bars on the current tick const int prev_calculated,// amount of history in bars on the previous tick const datetime &time[], const double &open[], const double& high[], // price array of price maxima for indicator calculation const double& low[], // price array of price minima for indicator calculation const double &close[], const long &tick_volume[], const long &volume[], const int &spread[]) { //---- check the number of bars for sufficiency for calculation if(BarsCalculated(ATR_Handle)<rates_total || rates_total<min_rates_total) return(0); //---- local variable declarations double ATR[]; double smin0,smax0; int limit,to_copy,bar,trend0; static double smin1,smax1; static int trend1; //---- indexing of elements in arrays, as in timeseries ArraySetAsSeries(close,true); ArraySetAsSeries(high,true); ArraySetAsSeries(low,true); ArraySetAsSeries(ATR,true); //---- calculating the start limit number for the bar recalculation cycle if(prev_calculated>rates_total || prev_calculated<=0) // check for the first start of indicator calculation { limit=rates_total-min_rates_total-1; // start number for calculation of all bars trend1=0; smin1=-999999; smax1=+999999; } else { limit=rates_total-prev_calculated; // start number for calculating new bars } to_copy=int(limit+Length); //---- copy newly appeared data into arrays if(CopyBuffer(ATR_Handle,0,0,to_copy,ATR)<=0) return(0); //---- main indicator calculation cycle for(bar=limit; bar>=0; bar--) { ExtMapBufferUp[bar]=EMPTY_VALUE; ExtMapBufferDown[bar]=EMPTY_VALUE; ExtMapBufferUp1[bar]=EMPTY_VALUE; ExtMapBufferDown1[bar]=EMPTY_VALUE; smin0=-999999; smax0=+999999; for(int iii=0; iii<int(Length); iii++) { int barx=bar+iii; smin0=MathMax(smin0,high[barx]-Kv*ATR[barx]); smax0=MathMin(smax0,low[barx]+Kv*ATR[barx]); } trend0=trend1; if(close[bar]>smax1) trend0=+1; if(close[bar]<smin1) trend0=-1; if(trend0>0) { if(smin0<smin1) smin0=smin1; ExtMapBufferUp[bar]=smin0; } if(trend0<0) { if(smax0>smax1) smax0=smax1; ExtMapBufferDown[bar]=smax0; } if(ExtMapBufferUp[bar+1]==EMPTY_VALUE && ExtMapBufferUp[bar]!=EMPTY_VALUE) ExtMapBufferUp1[bar]=ExtMapBufferUp[bar]; if(ExtMapBufferDown[bar+1]==EMPTY_VALUE && ExtMapBufferDown[bar]!=EMPTY_VALUE) ExtMapBufferDown1[bar]=ExtMapBufferDown[bar]; if(bar>0) { smin1=smin0; smax1=smax0; trend1=trend0; } } //--- BuySignal("ATRStops_v1.1_Alert",ExtMapBufferUp1,rates_total,prev_calculated,close,spread); SellSignal("ATRStops_v1.1_Alert",ExtMapBufferDown1,rates_total,prev_calculated,close,spread); //--- return(rates_total); } //+------------------------------------------------------------------+ //| Buy signal function| //+------------------------------------------------------------------+ void BuySignal(string SignalSirname, // indicator name text for mail and push signals double &BuyArrow[], // indicator buffer with buy signals const int Rates_total, // current number of bars const int Prev_calculated, // number of bars on the previous tick const double &Close[], // closing price const int &Spread[]) // spread { //--- static uint counter=0; if(Rates_total!=Prev_calculated) counter=0; bool BuySignal=false; bool SeriesTest=ArrayGetAsSeries(BuyArrow); int index; if(SeriesTest) index=int(NumberofBar); else index=Rates_total-int(NumberofBar)-1; if(NormalizeDouble(BuyArrow[index],_Digits) && BuyArrow[index]!=EMPTY_VALUE) BuySignal=true; if(BuySignal && counter<=NumberofAlerts) { counter++; MqlDateTime tm; TimeToStruct(TimeCurrent(),tm); string text=TimeToString(TimeCurrent(),TIME_DATE)+" "+string(tm.hour)+":"+string(tm.min); SeriesTest=ArrayGetAsSeries(Close); if(SeriesTest) index=int(NumberofBar); else index=Rates_total-int(NumberofBar)-1; double Ask=Close[index]; double Bid=Close[index]; SeriesTest=ArrayGetAsSeries(Spread); if(SeriesTest) index=int(NumberofBar); else index=Rates_total-int(NumberofBar)-1; Bid+=Spread[index]*_Point; string sAsk=DoubleToString(Ask,_Digits); string sBid=DoubleToString(Bid,_Digits); string sPeriod=GetStringTimeframe(ChartPeriod()); if(SoundON) Alert("BUY signal \n Ask=",Ask,"\n Bid=",Bid,"\n currtime=",text,"\n Symbol=",Symbol()," Period=",sPeriod); if(EMailON) SendMail(SignalSirname+": BUY signal alert","BUY signal at Ask="+sAsk+", Bid="+sBid+", Date="+text+" Symbol="+Symbol()+" Period="+sPeriod); if(PushON) SendNotification(SignalSirname+": BUY signal at Ask="+sAsk+", Bid="+sBid+", Date="+text+" Symbol="+Symbol()+" Period="+sPeriod); } //--- } //+------------------------------------------------------------------+ //| Sell signal function| //+------------------------------------------------------------------+ void SellSignal(string SignalSirname, // indicator name text for mail and push signals double &SellArrow[], // indicator buffer with buy signals const int Rates_total, // current number of bars const int Prev_calculated, // number of bars on the previous tick const double &Close[], // closing price const int &Spread[]) // spread { //--- static uint counter=0; if(Rates_total!=Prev_calculated) counter=0; bool SellSignal=false; bool SeriesTest=ArrayGetAsSeries(SellArrow); int index; if(SeriesTest) index=int(NumberofBar); else index=Rates_total-int(NumberofBar)-1; if(NormalizeDouble(SellArrow[index],_Digits) && SellArrow[index]!=EMPTY_VALUE) SellSignal=true; if(SellSignal && counter<=NumberofAlerts) { counter++; MqlDateTime tm; TimeToStruct(TimeCurrent(),tm); string text=TimeToString(TimeCurrent(),TIME_DATE)+" "+string(tm.hour)+":"+string(tm.min); SeriesTest=ArrayGetAsSeries(Close); if(SeriesTest) index=int(NumberofBar); else index=Rates_total-int(NumberofBar)-1; double Ask=Close[index]; double Bid=Close[index]; SeriesTest=ArrayGetAsSeries(Spread); if(SeriesTest) index=int(NumberofBar); else index=Rates_total-int(NumberofBar)-1; Bid+=Spread[index]*_Point; string sAsk=DoubleToString(Ask,_Digits); string sBid=DoubleToString(Bid,_Digits); string sPeriod=GetStringTimeframe(ChartPeriod()); if(SoundON) Alert("SELL signal \n Ask=",Ask,"\n Bid=",Bid,"\n currtime=",text,"\n Symbol=",Symbol()," Period=",sPeriod); if(EMailON) SendMail(SignalSirname+": SELL signal alert","SELL signal at Ask="+sAsk+", Bid="+sBid+", Date="+text+" Symbol="+Symbol()+" Period="+sPeriod); if(PushON) SendNotification(SignalSirname+": SELL signal at Ask="+sAsk+", Bid="+sBid+", Date="+text+" Symbol="+Symbol()+" Period="+sPeriod); } //--- } //+------------------------------------------------------------------+ //| Get timeframe as a string| //+------------------------------------------------------------------+ string GetStringTimeframe(ENUM_TIMEFRAMES timeframe) { //---- return(StringSubstr(EnumToString(timeframe),7,-1)); //---- } //+------------------------------------------------------------------+
Hi,
Can you add English language in properties, so we can understand it.
Thanks
The original publication was in the Russian CodeBase in 2017. MetaQuotes is the one that made a translation of the publication.
Original code: https://www.mql5.com/ru/code/17881
So I doubt the original author will do that. You could use Google translate and change the code comments into English yourself.
ATRStops_v1.1_Alert:
A trend indicator implemented as NRTR, with the possibility to generate alerts and send emails or push-notifications.
Author: Nikolay Kositsin