How CopyRates Works

 

Im new to this forum and mql5.

Let's say I want to work  (do some calculation) with last 100 candles everytime a new candle appears.

MqlRates rates[]; 
   ArraySetAsSeries(rates,true); 
   int copied=CopyRates(Symbol(),0,0,100,rates); 
   if(copied>0) 
     { //do something

}

Is calling copyrates function each time a new candle appears ok?

Only the last (newest) candle data is changed.

Isn't copying all the existing data again is a waste(memory, efficency) ?

Please tell me you understand what I'm saying.

Should I follow another approch like using a LinkedList or something?

Thanks

 
  1. Don't worry about efficiency unless you can prove it with the profiler.
  2. Don't do per tick what you can do once per bar. If you determine a trigger price, ignore all lesser prices until you reach it or get  new bar.