Wrong value of current iOpen(PERIOD_D1)

 

Hello guys,

I've a multi-currency EA that use the open of daily candle for some calclations. I've coded it as 

SymbolSelect(oSy,true);
Sleep(1000);
RefreshRates();

iOpen(oSy,PERIOD_D1,0)

Most of times the value obtained from iOpen is right, but sometimes occurs that value is wrong and it is taken from yesterday candle, like I was written iOpen(oSy,PERIOD_D1,1).

Have anyone had a problem like this?

Why it occurs?

Thanks to all!

 
  1. After Sleep and between server calls the market will have changed. You must update your variables. To use any pre-defined variables and series arrays you must call RefreshRates In your post You aren't using any of them.
              RefreshRates - Timeseries and Indicators Access - MQL4 Reference

  2. On MT4: Unless the current chart is that specific pair/TF referenced, you must handle 4066/4073 errors before accessing prices.
              Download history in MQL4 EA - MQL4 and MetaTrader 4 - MQL4 programming forum

    On MT5: Unless the chart is that specific pair/TF, you must Synchronize the terminal Data from the Server.
              Timeseries and Indicators Access /  Data Access - Reference on algorithmic/automated trading language for MetaTrader 5
              Synchronize Server Data with Terminal Data - Symbols - General - MQL5 programming forum

 
William Roeder:
  1. After Sleep and between server calls the market will have changed. You must update your variables. To use any pre-defined variables and series arrays you must call RefreshRates In your post You aren't using any of them.
              RefreshRates - Timeseries and Indicators Access - MQL4 Reference

  2. On MT4: Unless the current chart is that specific pair/TF referenced, you must handle 4066/4073 errors before accessing prices.
              Download history in MQL4 EA - MQL4 and MetaTrader 4 - MQL4 programming forum

    On MT5: Unless the chart is that specific pair/TF, you must Synchronize the terminal Data from the Server.
              Timeseries and Indicators Access /  Data Access - Reference on algorithmic/automated trading language for MetaTrader 5
              Synchronize Server Data with Terminal Data - Symbols - General - MQL5 programming forum

I've used RefreshRates() comand after the sleep command in order to have current and fresh data when accessing daily open with iOpen command. Probably the issue is realted to history that need to be downlaoded for each pair on which my EA works. Do you think that opening a D1 chart for all my symbols and close them will be enough to synchronize history?

Is there a command to force History synchronization? (When I switch from a pair chart to another one often I see that message about history synchronization in logs).
Thanks!!
 
Fabio Cavalloni: I've used RefreshRates() comand before the sleep command

You updated the predefined variables, then slept, so now they are out of sync. Moronic.

Fabio Cavalloni: Is there a command to force History synchronization?

What part of #1 № 2 didn't you read?

 
William Roeder:

You updated the predefined variables, then slept, so now they are out of sync. Moronic.

What part of #1 № 2 didn't you read?

Thanks for your kindness, man! Maybe you need to read again my message to understand that I refreshed variables after sleep command. The code is right, I mad a mistake in writing the phrase

Anyway, the problem is solved.