Timeframe Synchronizing Issue

 

Below is an image of a chart with a custom indicator I wrote.

The chart is H4 chart and the indicator is hard programmed to PERIOD_H4 for the indicator. The indicator is working fine on H4 as was programmed to do so.


GBY/JPY H4 chart with indicator: No issue here, all is working fine

Everything is fine on the H4 chart above, I've placed the green vertical lines to show the alignment of the bars in the chart to the indicator.

The synchronizing issue is in the next chart. The chart below is in M30 period, the 2 vertical green lines below are the last 2 green lines in the H4 chart above.

The indicator is still working as if it were still on a H4 timeframe, is there a way to align the indicator to the correct time it should be on while being on a different timeframe?

As shown below (yellow arrows), the last 2 red indicator triggers (H4) should be at the 2 green line position respectively on the 30min timeframe.


GBP/JPY 30M: Timing problem

My thanks to anyone who can help me out with this issue.

Below is my indicator for your reference.

Files:
sm4hv1.mq4  3 kb
Reason: