Trouble with iTime(ChartSymbol(ID), ENUM_TIMEFRAMES(timeframe),0);

 

Hi guys, the command

OtherBarZeroTime = iTime(ChartSymbol(ID), ENUM_TIMEFRAMES(timeframe),0);

does not update at all when I loop around charts (30 charts).

The time of the Zero bar is too early for non current bars.

Sometimes it gives me the time of bar one of the chart.

Any solution please?

Thanks.

 

Show your loop. We don't know what ID or timeframe values are.

iTime for the symbol may not be fully updated for the time-frame and symbol the first time that it is called

 
macpee: Hi guys, the command does not update at all when I loop around charts (30 charts). The time of the Zero bar is too early for non current bars. Sometimes it gives me the time of bar one of the chart. Any solution please? Thanks.

When dealing with multi-currency you have to wait for data to update. So you should check for a return of zero (iTime return value) and then proceed to check for the error code.

Forum on trading, automated trading systems and testing trading strategies

Coding

William Roeder, 2022.09.25 17:44

On MT4: Unless the current chart is that specific symbol(s)/TF(s) referenced, you must handle 4066/4073 errors before accessing candle/indicator values.
          Download history in MQL4 EA - MQL4 programming forum - Page 3 #26.4 (2019)

On MT5: Unless the current chart is that specific pair/TF, you must synchronize the terminal Data from the Server before accessing candle/indicator values.
          Error 4806 while using CopyBuffer() - Expert Advisors and Automated Trading - MQL5 programming forum #10 (2020)
          Is it mystical?! It is! - Withdraw - Technical Indicators - MQL5 programming forum (2019)
          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 #2 (2018)
          SymbolInfoInteger doesn't work - Symbols - General - MQL5 programming forum (2019)

 
Fernando Carreiro #:

When dealing with multi-currency you have to wait for data to update. So you should check for a return of zero (iTime return value) and then proceed to check for the error code.

Thanks Fernando Carreiro and Keith Watford. I am getting Error 4066: Requested history data is in update state. 

But I guess that of the current chart had finished updating since.

What can I do to get the correct data from the non-current charts, e.g. iTime, iHigh etc.?

I even tried ChartRedraw(ID) but it did not update.

I just saw this in the link you referred me to. I don't understand how to use it for the update.
bool     download_history(ENUM_TIMEFRAMES period=PERIOD_CURRENT){
   return download_history(_Symbol, period);
}
bool     download_history(SYMBOL symbol, ENUM_TIMEFRAMES period=PERIOD_CURRENT){
   if(period == PERIOD_CURRENT)  period = (ENUM_TIMEFRAMES)_Period;
   ResetLastError();    datetime other = iTime(symbol, period, 0);
   if(_LastError == 0 && other != 0)   return true;
   if(_LastError != ERR_HISTORY_WILL_UPDATED
   && _LastError != ERR_NO_HISTORY_DATA
     )   PrintFormat("iTime(%s,%i) Failed: %i", symbol, period, _LastError);
   return false;
}
What if I use RefreshRates just like using ChartRedraw for the objects
Keith Watford
Keith Watford
  • 2022.11.01
  • www.mql5.com
Trader's profile
 
macpee #: Thanks Fernando Carreiro and Keith Watford. I am getting Error 4066: Requested history data is in update state. But I guess that of the current chart had finished updating since.

What can I do to get the correct data from the non-current charts, e.g. iTime, iHigh etc.? I even tried ChartRedraw(ID) but it did not update. I just saw this in the link you referred me to. I don't understand how to use it for the update. What if I use RefreshRates just like using ChartRedraw for the objects

William's "download_history()" is equivalent to doing a RefreshRates() for that symbol and period. If you don't understand how to use William's code, then I don't know how else to explain it to you.
 
  1. macpee #: . What if I use RefreshRates just like using ChartRedraw for the objects
    RefreshRates updates:
    Predefined variables: Ask, Bars, Bid, Close[], High[], Low[], Open[], Point, Time[], Volume[]
              RefreshRates - Timeseries and Indicators Access - MQL4 Reference
              Predefined Variables - MQL4 Reference
    Also updates: Hour, Minute, and Seconds
              Minute() returns wrong values - or am I wrong? - MQL4 programming forum (2017)

    It has nothing to do with other symbols.

  2. macpee #: What can I do to get the correct data from the non-current charts, e.g. iTime, iHigh etc.?
    Nothing. If the data is not yet available, return and wait until it is.
 
William Roeder #:
  1. RefreshRates updates:
    Predefined variables: Ask, Bars, Bid, Close[], High[], Low[], Open[], Point, Time[], Volume[]
              RefreshRates - Timeseries and Indicators Access - MQL4 Reference
              Predefined Variables - MQL4 Reference
    Also updates: Hour, Minute, and Seconds
              Minute() returns wrong values - or am I wrong? - MQL4 programming forum (2017)

    It has nothing to do with other symbols.

  2. Nothing. If the data is not yet available, return and wait until it is.

I have added:


Sleep (1000);

RefreshRates;

Sleep(1000);

The_Time = iTime(ChartSymbol(ID)....);


in that order and it seems to be working fine for each of all the non-current charts with the ID.

 
macpee #: I have added: Sleep (1000); RefreshRates; Sleep(1000);The_Time = iTime(ChartSymbol(ID)....); in that order and it seems to be working fine for each of all the non-current charts with the ID.

Don't use Sleep as that will block the thread. Return from the OnTick or OnCalculate event handler, and check on the next event.

Also, RefreshRates() will not do anything for other symbols. William has already explained that in the previous post.

 
macpee:

Hi guys, the command

does not update at all when I loop around charts (30 charts).

The time of the Zero bar is too early for non current bars.

Sometimes it gives me the time of bar one of the chart.

Any solution please?

Thanks.

Not sure if this relevant, but don't forget a new bar on your "host" chart, doesn't mean a new bar on other charts. That's because, on the "other" chart, a new bar forms only when a tick is received after the completion of the previous bar. 

So, you could look into MarketInfo(sym,MODE_TIME) which gives the last tick time for a symbol.

Reason: