Help with understanding basic plotting

 

Hi, I was trying to plot ATR on a separate window, can someone point me what I'm doing wrong?

//+------------------------------------------------------------------+
//|                                                 ATR GU_scalp.mq4 |
//|                                                        Eddy Eddy |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Eddy Eddy"
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1  DodgerBlue
//--- input parameter
input int c=14; // ATR Period
//--- buffers
double ExtATRBuffer[];


//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   IndicatorBuffers(2);
   IndicatorDigits(Digits);
//--- indicator line
   SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,1,clrAqua);
   SetIndexBuffer(1,ExtATRBuffer);



//---
   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[])
  {
//---

// Define maximum index for the buffer array
   int iMaxIndex = rates_total - 1;
// Main loop — fill in the arrays with data values
   for(int i = rates_total - (prev_calculated < 1 ? 1 : prev_calculated); i >= 0; i--)
     {

      if(i<rates_total-c) //if there are enough bars aviable to calculation then calculate
        {
         ExtATRBuffer[i] = iATR(Symbol(),0,c,0);
        }
      else //else = 0
         ExtATRBuffer[i] = 0;



     };


//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+



Thank's for helping. 

 
  1.    IndicatorBuffers(2);
    
       SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,1,clrAqua);
       SetIndexBuffer(1,ExtATRBuffer);
    

    You only have one array, why are you making it buffer two?

  2.    for(int i = rates_total - (prev_calculated < 1 ? 1 : prev_calculated); i >= 0; i--){
          if(i<rates_total-c) //if there are enough bars aviable to calculation then calculate

    See How to do your lookbacks correctly #9#14 & #19.

  3.          ExtATRBuffer[i] = iATR(Symbol(),0,c,0);
    You are assigning the same value to all bars.
  4. ironhak: I was trying to plot ADR on a separate window, can someone point me what I'm doing wrong?

    You are calling ATR for the current chart. You are not getting ADR which requires the daily chart.

  5. Since the source data is a higher TF, you must reprocess all source bar zero values to get the stair step effect, (one source bar, multiple chart bars.)
              How to do your lookbacks correctly #9 - #14 & #19

  6. On MT4: Unless the current chart is that specific symbol(s)/TF(s) referenced, you must handle 4066/4073 errors before accessing candle/indicator values.
              Download history in MQL4 EA - Forex Calendar - MQL4 programming forum - Page 3 #26.4 (2019)

  7.       else //else = 0
             ExtATRBuffer[i] = 0;
    You must use EMPTY_VALUE, since you didn't change it in init.
 
William Roeder #:
  1. You only have one array, why are you making it buffer two?

  2. See How to do your lookbacks correctly #9#14 & #19.

  3. You are assigning the same value to all bars.
  4. You are calling ADR ATR for the current chart. You are not getting ADR which requires the daily chart.

  5. Since the source data is a higher TF, you must reprocess all source bar zero values to get the stair step effect, (one source bar, multiple chart bars.)
              How to do your lookbacks correctly #9 - #14 & #19

  6. On MT4: Unless the current chart is that specific symbol(s)/TF(s) referenced, you must handle 4066/4073 errors before accessing candle/indicator values.
              Download history in MQL4 EA - Forex Calendar - MQL4 programming forum - Page 3 #26.4 (2019)

  7. You must use EMPTY_VALUE, since you didn't change it in init.

My bad, I mean ATR not ADR. Anyway thank's, I'll study better the loop process.