Correct the timeshift of the indicator

 
Greetings fellas, I created an indicator that calculate the specific symbol, for example XAUUSD. I want to attach this indicator to XAGUSD but then I found the indicator timeshift is not quite right since XAU open at 01.00 server time and XAG open at 00.00 server time. How to correct the indicator data so that it is similar to the chart timeshift?
 

Use each bar's open time on the current chart to synchronise with the open time of the source symbol.

In the OnCalculate(), use the time of time[] parameter array elements, as a reference for the iBarShift() function, to look up the correct and exact shift for the source symbol's data.

And when no rates data is available for that time index, then leave the buffer element empty.

You can also simply iterate over both symbol's time-series data at the same time, and synchronise them comparing the timestamp as you sequentially proceed with each data element. This in my opinion is much faster and more efficient.

 
Fernando Carreiro #:

Use each bar's open time on the current chart to synchronise with the open time of the source symbol.

In the OnCalculate(), use the time of time[] parameter array elements, as a reference for the iBarShift() function, to look up the correct and exact shift for the source symbol's data.

And when no rates data is available for that time index, then leave the buffer element empty.

You can also simply iterate over both symbol's time-series data at the same time, and synchronise them comparing the timestamp as you sequentially proceed with each data element. This in my opinion is much faster and more efficient.

thank you Mr Fernando, let me try your suggestion

 
A A Adhioermawan:
Greetings fellas, I created an indicator that calculate the specific symbol, for example XAUUSD. I want to attach this indicator to XAGUSD but then I found the indicator timeshift is not quite right since XAU open at 01.00 server time and XAG open at 00.00 server time. How to correct the indicator data so that it is similar to the chart timeshift?

You can find some info on multicurrency indicators in the book: IndSubChartSimple example

MQL5 Book: Creating application programs / Creating custom indicators / Multicurrency and multitimeframe indicators
MQL5 Book: Creating application programs / Creating custom indicators / Multicurrency and multitimeframe indicators
  • www.mql5.com
Until now, we have considered indicators that work with quotes or ticks of the current chart symbol. However, sometimes it is necessary to analyze...
 
Stanislav Korotky #:

You can find some info on multicurrency indicators in the book: IndSubChartSimple example

Hello Mr. Stanislav. Thanks for the reference you gave me