CopyRates returns -1 and error 4401

 

Hi guys,

I have a problem in my custom indicator. I call CopyRates function for different currency pairs in one time (EURUSD, USDCAD, ... ) with count demand of actual chart and timeframe. In case I've never opened chart with USDCAD (as example), CopyRates always returns -1 and GetLastError function returns 4401. My question is - Is it possible to send request to server without opening all charts for each currency pair? Thank you for reply!

 
Michal_Jurnik:

Hi guys,

I have a problem in my custom indicator. I call CopyRates function for different currency pairs in one time (EURUSD, USDCAD, ... ) with count demand of actual chart and timeframe. In case I've never opened chart with USDCAD (as example), CopyRates always returns -1 and GetLastError function returns 4401. My question is - Is it possible to send request to server without opening all charts for each currency pair? Thank you for reply!

See CheckLoadHistory() script on this page 
Documentation on MQL5: Timeseries and Indicators Access / Organizing Data Access
Documentation on MQL5: Timeseries and Indicators Access / Organizing Data Access
  • www.mql5.com
Timeseries and Indicators Access / Organizing Data Access - Reference on algorithmic/automated trading language for MetaTrader 5
 
angevoyageur:
See CheckLoadHistory() script on this page 

Thank you for reply, I'm a little bit closer. The problem is it that I haven't data when I need them. I have zero data count for every currency pair except I have already displayed. There're two options how to execute the indicator:

  •  In case of work-day is everything ok because market is opened (there are a lot of ticks).
    1. First tick check the history (CopyRates has been executed) 
      1. If it is loaded then indicator will draw chart properly  
      2. If it isn't then indicator will send request to server
        1. Next tick indicator will draw chart properly

  • In case of weekend there's only one tick:

    1. First tick check the history (CopyRates has been executed) 
      1. If it is loaded then indicator will draw chart properly  
      2. If it isn't then indicator will send request to server
    You should see my problem now. I can't use Sleep() in main thread and cycles aren't good idea.
    Reason: