Bollinger band value at nth candle

 

When I use the following code to read the bollinger band lower value at the past candle 1, it works fine.

int handle;
double lower_band[];
ArraySetAsSeries(lower_band,true);
handle=iBands(NULL,0,20,0,2.0,PRICE_CLOSE);
CopyBuffer(handle,2,0,2,lower_band);
Print(lower_band[1]);
But if I use "Print (lower_band[2])" in order to read the same value at past candle 2, it doen't return anything. Could someone please explain a reason for that?
 
rhodium1trading: But if I use "Print (lower_band[2])" in order to read the same value at past candle 2, it doen't return anything. Could someone please explain a reason for that?
  1. Perhaps you should read the manual, especially the examples.
       How To Ask Questions The Smart Way. 2004
          How To Interpret Answers.
             RTFM and STFW: How To Tell You've Seriously Screwed Up.

    They all (including iCustom) return a handle (an int). You get that in OnInit. In OnTick (after the indicator has updated its buffers), you use the handle, shift and count to get the data.
              Technical Indicators - Reference on algorithmic/automated trading language for MetaTrader 5
              Timeseries and Indicators Access / CopyBuffer - Reference on algorithmic/automated trading language for MetaTrader 5
              How to start with MQL5 - General - MQL5 programming forum - Page 3 #22 2020.03.08
              How to start with MQL5 - MetaTrader 5 - General - MQL5 programming forum - Page 7 #61 2020.07.05
              How to call indicators in MQL5 - MQL5 Articles 12 March 2010

  2. Your CopyBuffer call asked for two values. Their indexes are therefor [0 … 1]. Why do you think you can read array index 2?
 
rhodium1trading :

When I use the following code to read the bollinger band lower value at the past candle 1, it works fine.

But if I use "Print (lower_band[2])" in order to read the same value at past candle 2, it doen't return anything. Could someone please explain a reason for that?

First, fix the main mistake:

Reason: