c++mql5

Does ATR indicator include the current bar


I understand from the MQL4 documentation on the ATR indicator, that it can return the the value of the indicator for the current bar if 0 is used for the shift argument. However, when looking at the MQL5 documentation for the indicator, I notice that there doesn't appear to be any way to determine this. Possibly, this is because the indicator is intended to be used in conjunction with CopyBuffer like so:

// Note that error handling has been omitted in this code
double values[];
int handle = iATR(Symbol(), PERIOD_D1, 10);
CopyBuffer(handle, 0, 0, 1, values);

In this example, I'm retrieving the daily ATR for a period of 10 days and copying the first value of this buffer into an array. So, is values[0] the ATR value for the current day, or the ATR value for the previous day?


Solution

  • According to @PaulB, index 0 always represents the current bar. Ergo, this code:

    double values[];
    int handle = iATR(Symbol(), PERIOD_D1, 10);
    CopyBuffer(handle, 0, 0, 1, values);
    

    was retrieving the Daily ATR for the current day, which includes the current bar. In order to fix this, I simply had to change the shift from 0 to 1, like so:

    double values[];
    int handle = iATR(Symbol(), PERIOD_D1, 10);
    CopyBuffer(handle, 0, 1, 1, values);
    

    which retrieves the daily ATR for the previous day.