Is there an On event of some sort when the candles shift in which ever period M1, M5, M15 e.t.c.
I'm trying to catch the change so I can trigger a one time calculation per change.
This is seems like something obvious but I've had to hack about somethings in the OnTick to get stuff working and I would really like to be using the correct event to make it more robust.
What do you mean by "candles shift"? Do you mean when the current bar closes and a new one opens? Is that it?
If that is the case, then there are several examples here in the forum for detecting a new bar. Basically you just monitor the time of the last or current bar and detect when it changes. You can do the same for the other time-frames as well!
// Check for New Bar static datetime dtBarCurrent = WRONG_VALUE; datetime dtBarPrevious = dtBarCurrent; dtBarCurrent = (datetime) SeriesInfoInteger( _Symbol, _Period, SERIES_LASTBAR_DATE ); bool boolNewBarFlag = ( dtBarCurrent != dtBarPrevious ); if( boolNewBarFlag ) { Print( "... do something ..." ); }
Here is an example for detecting a new day:
// Check for New Day Bar static datetime dtDayCurrent = WRONG_VALUE; datetime dtDayPrevious = dtDayCurrent; dtDayCurrent = (datetime) SeriesInfoInteger( _Symbol, PERIOD_D1, SERIES_LASTBAR_DATE ); bool boolNewDayFlag = ( dtDayCurrent != dtDayPrevious ); if( boolNewDayFlag ) { Print( "... do something ..." ); }
I did not know about the SERIES_LASTBAR_DATE . Thanks for help!

- www.mql5.com

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Is there an On event of some sort when the candles shift in which ever period M1, M5, M15 e.t.c.
I'm trying to catch the change so I can trigger a one time calculation per change.
This is seems like something obvious but I've had to hack about somethings in the OnTick to get stuff working and I would really like to be using the correct event to make it more robust.
Cheers,