OnCalculate during weekend MT5

 

Hello,

I always had issues when creating indicators in MT5 that access data from different symbols and timeframes rather than current.

From documentation I found this in a lot of places.

For Expert Advisors and indicators, it is better to use the event model of handling. If during handling of OnTick() or OnCalculate() event, data receipt for the required timeseries failed, you should exit the event handler, relying on the access availability during the next call of the handler.

So, great, during day with markets opened there are no problems, at the first tick some timeseries can fail, and on the next one data are accessed correctly.

But what about weekends, where OnCalculate function is called only once, after OnInit and there are no incoming ticks to "re-trigger" OnCalculate function?

Do I need to work with OnTimer or am I missing something?

 
Fabio Cavalloni:

Hello,

I always had issues when creating indicators in MT5 that access data from different symbols and timeframes rather than current.

From documentation I found this in a lot of places.

For Expert Advisors and indicators, it is better to use the event model of handling. If during handling of OnTick() or OnCalculate() event, data receipt for the required timeseries failed, you should exit the event handler, relying on the access availability during the next call of the handler.

So, great, during day with markets opened there are no problems, at the first tick some timeseries can fail, and on the next one data are accessed correctly.

But what about weekends, where OnCalculate function is called only once, after OnInit and there are no incoming ticks to "re-trigger" OnCalculate function?

Do I need to work with OnTimer or am I missing something?

I think there is no way, just the strategy tester

 
 

The call of ChartSetSymbolPeriod with the same symbol and timeframe can be used to update the chart (similar to the terminal's Refresh command). In its turn, the chart update triggers re-calculation of the indicators attached to it. Thus, you are able to calculate an indicator on the chart even if there are no ticks (e.g., on weekends).

Documentation on MQL5: Chart Operations / ChartSetSymbolPeriod
Documentation on MQL5: Chart Operations / ChartSetSymbolPeriod
  • www.mql5.com
Changes the symbol and period of the specified chart. The function is asynchronous, i.e. it sends the command and does not wait for its execution completion. The command is added to chart messages queue and will be executed after processing of all previous commands. The call of ChartSetSymbolPeriod with the same symbol...
 
Alain Verleyen:
 
Thanks!
Do you suggest to:
Simply call command to trigger indicators reinitalization

switch current chart to required timeseries period and then back to its initial timeframe

Or opening a new "temp" chart and set required symbol and period to it and after first successful call close it?

What do you think will be best option?
Thanks again 
 
Fabio Cavalloni:
Thanks!
Do you suggest to:
switch current chart to required timeseries period and then back to its initial timeframe
Or opening a new "temp" chart and set required symbol and period to it and after first successful call close it?

What do you think will be best option?
Thanks again 

No, read the documentation attentively.

  int shift=iBarShift(_Symbol,PERIOD_H8,D'2019.01.01');         // Just an example of a statement which can fail in MTF
  if(shift==-1)
   {
    printf("MTF error...");
    ChartSetSymbolPeriod(0,NULL,0);
    return(0);
   }
 
Alain Verleyen:

No, read the documentation attentively.

I realized it too late and I modified my message but you already replied...
Thanks again for your help Alain!
Reason: