Update value every second ONtick()

 

Hello I'm running an EA on 5min timeframe and my issue is that the values inside the OnTick() section are only updating when a new 5min bar appears.
For example I display some values on the label :  https://ibb.co/4WdL3Kb

and thethe values only update each 5 min.
Is there is a way to have an update every second for example ?

Thank you for your help !  

 
Kl JJ: Hello I'm running an EA on 5min timeframe and my issue is that the values inside the OnTick() section are only updating when a new 5min bar appears.For example I display some values on the label :  https://ibb.co/4WdL3Kb. and thethe values only update each 5 min. Is there is a way to have an update every second for example ? Thank you for your help !  

Yes! On each new tick, check the timestamp of the tick. When the timestamp changes (on every second), react to the event a new second.

void OnTick() {
   // Retrieve data for most recent tick
      MqlTick oTick;
      if( SymbolInfoTick( _Symbol, oTick ) ) {
         // Detect a new timestamp (every second) for current tick
            static datetime dtTimeCurrent  = WRONG_VALUE;
                   datetime dtTimePrevious = dtTimeCurrent;
                            dtTimeCurrent  = oTick.time;
                   bool     bTimeNew       = dtTimeCurrent != dtTimePrevious;
         // Process for new time (second) event
            if( bTimeNew ) {
               // Do something
            };
      };
};
 

If you use OnTick, remember that there will be no updates if there is no ticks. There can be minutes between ticks during the Asian session. Think weekend, market holidays.

Instead, enable the timer and use OnTimer and update the time.
          how can i detect that 10 seconds to bar close? MT4/EA - MQL5 programming forum (2020)
          Indicators: Zero Lag Timer - Indices - Articles, Library comments - MQL5 programming forum

 

Thanks for your answers.

I would like to use the OnTImer function.

I try something like this :

int OnInit()
{

EventSetTimer(1);
}

OnTimer{

The code inside OnTick()

}

But it still doesn't update every second, Have I done something wrong ?

 
Kl JJ #: But it still doesn't update every second, Have I done something wrong ?

What code inside?
     How To Ask Questions The Smart Way. (2004)
          Be precise and informative about your problem

We can't see your broken code.