Where to define CopyRates ? In OnTick() or OnInit()

 

I have been trying to make an EA, I used CopyRates in the OnInit function. And I noticed the values weren't refreshing as new tick data came or the new candle formed. So is it advised to place it in OnInit fuction?

Thanks for help

 

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.

It clearly shows not OnInit.

Don't try to use any price (or indicator) or server related functions in OnInit (or on load or in OnTimer before you've received a tick), as there may be no connection/chart yet:

  1. Terminal starts.
  2. Indicators/EAs are loaded. Static and globally declared variables are initialized. (Do not depend on a specific order.)
  3. OnInit is called.
  4. For indicators OnCalculate is called with any existing history.
  5. Human may have to enter password, connection to server begins.
  6. New history is received, OnCalculate called again.
  7. New tick is received, OnCalculate/OnTick is called. Now TickValue, TimeCurrent, account information and prices are valid.