Knowing when Candles shift

 

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,

 
IanKnowles:

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 ..." ); }
 
Yeah that's what I meant. I did do some searching but didn't know the terminology.

I did not know about the SERIES_LASTBAR_DATE . Thanks for help!
 
IanKnowles: Yeah that's what I meant. I did do some searching but didn't know the terminology. I did not know about the SERIES_LASTBAR_DATE . Thanks for help!
There is an entire Article dedicated to the subject ... The "New Bar" Event Handler ( https://www.mql5.com/en/articles/159 )
The "New Bar" Event Handler
The "New Bar" Event Handler
  • www.mql5.com
MQL5 programming language is capable of solving problems on a brand new level. Even those tasks, that already have such solutions, thanks to object oriented programming can rise to a higher level. In this article we take a specially simple example of checking new bar on a chart, that was transformed into rather powerful and versatile tool. What tool? Find out in this article.
Reason: