Post all relevant code. Where do you declare your buffers?
How To Ask Questions The Smart Way. (2004)
Be precise and informative about your problem
How To Ask Questions The Smart Way. (2004)
Be precise and informative about your problem
William Roeder #:
Post all relevant code. Where do you declare your buffers?
How To Ask Questions The Smart Way. (2004)
Be precise and informative about your problem
Post all relevant code. Where do you declare your buffers?
How To Ask Questions The Smart Way. (2004)
Be precise and informative about your problem
Hi William, Attached is complete code.
Thanks.
#property link "https://www.mql5.com" #property version "1.00" #property indicator_separate_window #property indicator_buffers 5 #property indicator_plots 5 //--- plot ATR #property indicator_label1 "ATR" #property indicator_type1 DRAW_LINE #property indicator_color1 clrBlue #property indicator_style1 STYLE_SOLID #property indicator_width1 1 //--- plot Smoothened ATR #property indicator_label2 "ATR Smooth" #property indicator_type2 DRAW_LINE #property indicator_color2 clrBlack #property indicator_style2 STYLE_SOLID #property indicator_width2 1 //--- plot 2nd Smoothened ATR #property indicator_label3 "ATR Smooth2" #property indicator_type3 DRAW_LINE #property indicator_color3 clrRed #property indicator_style3 STYLE_SOLID #property indicator_width3 2 //--- plot Upper level #property indicator_label4 "Upper Level" #property indicator_type4 DRAW_LINE #property indicator_color4 clrSilver #property indicator_style4 STYLE_SOLID #property indicator_width4 1 //--- plot Lower level #property indicator_label5 "Lower Level" #property indicator_type5 DRAW_LINE #property indicator_color5 clrSilver #property indicator_style5 STYLE_SOLID #property indicator_width5 1 //--- input parameters input int ATR_Range=14; //ATR Period input int ATR_Smooth_Range=7; //ATR Smooth Period input int ATR_Smooth_Range2=3; //ATR 2nd Smooth Period input int Look_back_period = 500; //Level high low lookback period //--- indicator buffers int ATRHandle; double ATRBuffer[]; double ATRSBuffer[]; double ATRS2Buffer[]; double U_Level[]; double L_Level[]; #include <MovingAverages.mqh> //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- indicator buffers mapping SetIndexBuffer(0,ATRBuffer,INDICATOR_DATA); SetIndexBuffer(1,ATRSBuffer,INDICATOR_DATA); SetIndexBuffer(2,ATRS2Buffer,INDICATOR_DATA); SetIndexBuffer(3,U_Level,INDICATOR_DATA); SetIndexBuffer(4,L_Level,INDICATOR_DATA); PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,ATR_Range+ATR_Smooth_Range+ATR_Smooth_Range2-1); PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,ATR_Range+ATR_Smooth_Range+ATR_Smooth_Range2-1); PlotIndexSetInteger(2,PLOT_DRAW_BEGIN,ATR_Range+ATR_Smooth_Range+ATR_Smooth_Range2-1); PlotIndexSetInteger(3,PLOT_DRAW_BEGIN,ATR_Range); PlotIndexSetInteger(4,PLOT_DRAW_BEGIN,ATR_Range); IndicatorSetInteger(INDICATOR_DIGITS,_Digits); //Name of Indicator in Indicator window (or data window if indicator is on chart) string shortname = StringFormat("Manjit_ATR, Smoothened (%d) (%d) (%d)",ATR_Range,ATR_Smooth_Range, ATR_Smooth_Range2); IndicatorSetString(INDICATOR_SHORTNAME,0,shortname); //-- Initialising ATR Handle ATRHandle = iATR(_Symbol,_Period,ATR_Range); IndicatorSetInteger(INDICATOR_DIGITS,_Digits); //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Custom indicator de-initialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { IndicatorRelease(ATRHandle); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, const int prev_calculated, const int begin, const double &price[]) { // Copying buffer into ATRBuffer if(CopyBuffer(ATRHandle,0,0,rates_total,ATRBuffer) < 0) { //Sleep(200); return(0); } //--- Performing smoothening using pre-defined moving averages function present in include files SimpleMAOnBuffer(rates_total,prev_calculated,ATR_Range,ATR_Smooth_Range,ATRBuffer,ATRSBuffer); SimpleMAOnBuffer(rates_total,prev_calculated,ATR_Smooth_Range,ATR_Smooth_Range2,ATRSBuffer,ATRS2Buffer); ArraySetAsSeries(ATRBuffer,true); ArraySetAsSeries(U_Level,true); ArraySetAsSeries(L_Level,true); if(Look_back_period >= rates_total) { for( int i=0 ; i<rates_total ; i++ ) { U_Level[i] = ATRBuffer[ArrayMaximum(ATRBuffer,0,WHOLE_ARRAY)]; L_Level[i] = ATRBuffer[ArrayMinimum(ATRBuffer,0,WHOLE_ARRAY)]; } } return(rates_total); } //+------------------------------------------------------------------+
Hello sirs, can anyone please support.
Only copy what is needed.
int OnCalculate(const int rates_total, const int prev_calculated, const int begin, const double &price[]) { // Copying buffer into ATRBuffer int toCopy=(rates_total==prev_calculated)?1:rates_total-prev_calculated; if(CopyBuffer(ATRHandle,0,0,toCopy,ATRBuffer) < 0) { //Sleep(200); return(0); } //--- Performing smoothening using pre-defined moving averages function present in include files SimpleMAOnBuffer(rates_total,prev_calculated,ATR_Range,ATR_Smooth_Range,ATRBuffer,ATRSBuffer); SimpleMAOnBuffer(rates_total,prev_calculated,ATR_Smooth_Range,ATR_Smooth_Range2,ATRSBuffer,ATRS2Buffer); ArraySetAsSeries(ATRBuffer,true); ArraySetAsSeries(U_Level,true); ArraySetAsSeries(L_Level,true); int start=(rates_total==prev_calculated)?0:(!prev_calculated)?rates_total-1-Look_back_period:rates_total-1-prev_calculated; for( int i=start ; i>=0 ; i-- ) { U_Level[i] = ATRBuffer[ArrayMaximum(ATRBuffer,i,Look_back_period)]; L_Level[i] = ATRBuffer[ArrayMinimum(ATRBuffer,i,Look_back_period)]; } return(rates_total); }

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hello Experts.
Requesting your advise and help.
I was trying to plot level for ATR.
The lower level was plotted, but the upper level is not being plotted (although the code is same).
I have wasted whole day to debug, but failed. Plz help.
Chart pic attached