question about ERR_HISTORY_WILL_UPDATED (4066 )

 

I use a indicator to calc index base on other period data, if the period chart is not open yet, iMAOnArray(...) will return incorect data, just as same as ArrayCopySeries,

my question is: if I don't open a chart of the period, after the first calling return error, the flollowing calling will also get error? or it could always get corect data after that?

if the indicator continue request data in a certain interval, the request will never fail any more?

I don't know metatrader how to setup the receive queue. Is it work in this way:

once a symbol/period data request has been send, metatrader will register the symbol/period to receive data, and never remove it before quit the program, even I closed all chart?

 

I've been studying this issue also. The way it appears to work is:

  1. MetaTrader only actively updates the history on charts that are open, at the time frame of the chart. Other charts and other TFs are not updated.
  2. When ArrayCopySeries() etc. is called, it will trigger a request for history data and then return without waiting for the data to arrive.
  3. It sets the error status to ERR_HISTORY_WILL_UPDATED which must be checked with a call to GetLastError().
  4. If this error is seen, the handling is to wait for a while such as 10 seconds, then repeat the call to ArrayCopySeries() to get the data.
  5. I have noticed that if the call to ArrayCopySeries is repeated before sufficient time has passed, the call will succeed and not generate an error 4066, but the data will not be current.
  6. Note that you cannot use Sleep() within an indicator, it will not work. Use some other method of marking the passage of time such as calling TimeCurrent() and storing the value.
  7. I have confirmed that when ArrayCopySeries() on one TF is called it does not trigger an update at any other TF. Thus if you refer to multiple TFs it might be most efficient to call ArrayCopySeries() on all of them at once rather than sequentially, then the wait period on all of them can be overlapped. I have not tested that this works yet.
  8. I believe it is being too optimistic to expect MT to continue to update a TF simply because it was requested one time. You will have to repeat this process each time a new bar is added at the TF. It is not necessarily a burdensome requirement, because new bars are not added very often at higher TFs. At M15 it would need to be repeated once every 15 minutes. I have not confirmed this with tests yet. EDIT: I did a test and the results show that after ArrayCopySeries is made, subsequent calls to iBars show the value is increasing over time (without a repeat of error 4066), so it means that MT continues to update that TF once it has been asked for.
 
This info has been very useful and now my code works again, thank you so much!!
Reason: