Search code examples
mql4mt4

Event to use in an Expert Advice that triggers when a new bar gets created


Is there any event to use in an Expert Advice that triggers when a new bar is created?

I think OnChartEvent, OnTick, OnTimer doesn't do that.


Solution

  • Yes, the named handlers do something else

    As per MQL4 documentation, built-in OnTick(), OnTimer() et al functions, are pre-defined handlers.

    If needed, may try to create one's own, using built-in szstem variable Bars ( iBars() is rather a heavyweight alternative ):

    bool aNewBarEVENT(){
         static  int anAlreadyObservedBarCOUNT = EMPTY;    // .INIT
         if ( Bars > anAlreadyObservedBarCOUNT ){          // .TEST
                     anAlreadyObservedBarCOUNT = Bars;     // .UPD
                     return( True );                       // .ACK
         }
         return( False );                                  // .NACK
    }
    

    Usage:

    enter image description here