How to select any number of arrays?

 

Hi!


When i need to select the close of the third candle away from current price i use: candle[2].close. In this case i need to write the [2], but what if i want to select the close of the last 100 candles? Do i need to select one by one or is there a better way to do that? 


Currently i am doing this, it works great, but if i need to select a large amount of candles at once it is just not doable. 

MqlRates                      rates[];


int OnInit()
   
{

ArraySetAsSeries(rates, true);
return (INIT_SUCCEEDED);

}



void OnTick()

{
 int candleData =  CopyRates(Symbol(), Period(), 0, 3, rates);


     double candle0O = rates[0].open;
     double candle0C = rates[0].close;

     double candle1L = rates[1].low;
     double candle1H = rates[1].high;

}
 
Leonardo:

Hi!


When i need to select the close of the third candle away from current price i use: candle[2].close. In this case i need to write the [2], but what if i want to select the close of the last 100 candles? Do i need to select one by one or is there a better way to do that? 


Currently i am doing this, it works great, but if i need to select a large amount of candles at once it is just not doable. 

Why are you writing them all in separate variable? You can use and work with the array. 
 
Leonardo: but what if i want to select the close of the last 100 candles? Do i need to select one by one or is there a better way to do that?
  1. Your Copy call only returns three. You need to ask for 100.
  2. Or, drop the Copy/array and just read the candle you want. iClose
Reason: