MT5 Futures – Chart candle lags behind current price on tick update

 
Hello everyone,

I'm experiencing an issue when working with FUTURES in MetaTrader 5 (with a live or demo feed). Specifically, when performing even simple calculations on each tick (inside `OnCalculate`), I noticed that the **chart candles do not update in real-time** with the incoming price.

To be clear:  
- The price moves as expected (ticks are received correctly).
- But the candle on the chart lags behind, staying "frozen" for a moment before updating.

Interestingly, this does not happen with CFDs — the chart candles follow the tick price immediately and behave normally.

I managed to work around the issue by triggering my calculations only on new bars (i.e. `if (Time[0] != lastBarTime)`), which solves the lag completely. But I'm curious to understand:

- Why does this lag only happen with Futures?
- Is there any architectural difference in how Futures are handled in MT5 (like data stream, chart rendering, or symbol properties)?
- Are there specific settings or symbol characteristics (e.g., `MARKET_BOOK`, `SYNTHETIC`, etc.) that could affect chart behavior?

Any insight would be greatly appreciated — I’d love to better understand what's going on under the hood.

Thanks in advance!


Follow the example:

int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {      
      datetime cDate = GetCurrentPeriod();
      //Print(lUpdate, cDate);
      if(lUpdate == cDate)
         return(0);         
      lUpdate = cDate;
      Print("Superato");
      RefreshData(PERIOD_D1, time[0]);
      Print("Reset concluso");
          
   return(rates_total);
  }
  
  
void RefreshData(ENUM_TIMEFRAMES _tf, datetime primabarra)
{
   //ArcoTemporale t[];
   ArrayResize(t, pCount); //pCount - zlimit

   Print("RefreshData:" + (pCount));
   for (int i = 0; i < (pCount); i++)
   {
      t[i].Close = 0;
      t[i].Open = 0;
      t[i].Price = 0;
   }
   
   MqlDateTime td;
   for (int i = (pCount) - 1; i >= 0; i--)
   {
      datetime openTime = iTime(_Symbol, _tf, i + 1);
      datetime closeTime;

      TimeToStruct(openTime, td);

      if (td.day_of_week == 0 && _tf != PERIOD_W1 && _tf != PERIOD_MN1)
      {
         t[i].Price = (use == Close) ? iClose(_Symbol, _tf, i + 2) : iOpen(_Symbol, _tf, i + 1);
      }
      else
      {
         t[i].Price = (use == Close) ? iClose(_Symbol, _tf, i + 1) : iOpen(_Symbol, _tf, i);
      }

      t[i].Open = iTime(_Symbol, _tf, i);

      if (i == 0)
         t[i].Close = iTime(_Symbol, _tf, i) + PeriodSeconds(_tf);
      else
         t[i].Close = iTime(_Symbol, _tf, i - 1);
   }   
   lPrice = t[0].Price;
   zlimit = pCount;
}
 
wpala94:
Hello everyone,

I'm experiencing an issue when working with FUTURES in MetaTrader 5 (with a live or demo feed). Specifically, when performing even simple calculations on each tick (inside `OnCalculate`), I noticed that the **chart candles do not update in real-time** with the incoming price.

To be clear:  
- The price moves as expected (ticks are received correctly).
- But the candle on the chart lags behind, staying "frozen" for a moment before updating.

Interestingly, this does not happen with CFDs — the chart candles follow the tick price immediately and behave normally.

I managed to work around the issue by triggering my calculations only on new bars (i.e. `if (Time[0] != lastBarTime)`), which solves the lag completely. But I'm curious to understand:

- Why does this lag only happen with Futures?
- Is there any architectural difference in how Futures are handled in MT5 (like data stream, chart rendering, or symbol properties)?
- Are there specific settings or symbol characteristics (e.g., `MARKET_BOOK`, `SYNTHETIC`, etc.) that could affect chart behavior?

Any insight would be greatly appreciated — I’d love to better understand what's going on under the hood.

Thanks in advance!


Follow the example:

I've seen this repeatedly, even in my CME Futures (MT5) broker's forum. For some reason, I haven't experienced the problem.

Two things off the top of my head:

  1. Connecting MT5 on a centralized futures exchange usually involves a gateway, bridge, or pipe of some kind. In my case, it's all on the backend managed by the broker.
  2. The Last price is generally the hallmark price that futures traders examine. I do know that there are a lot more Last prices than Bid prices in my historic data. Is it possible that your broker configured bars to print on Last instead of Bid in its gateway?
 

I thought so too but I didn't notice anything special, the only thing is that the price update frequency is much higher than CFDs. But how can a function like iClose cause so much delay? Really strange and I don't understand

 

Any support from any moderators?

@all

 
wpala94 #:

Any support from any moderators?

@all

I believe that all of the mods code for CFD's and forex, so they're likely unable to help you.

I took a 2nd look at your code. I see that your master loop is counting backward (i--). Instead of:

   return(rates_total);

Try:

   return(rates_total - 1);
And set your prices as Series.
 

Thanks a lot for the help, unfortunately it didn't solve it :( But if not even the moderators know what's going on or how to handle futures, who can know?
More than anything at the MT4 and MT5 product level, if no one has the situation in hand, how can you encourage other developers to consider these products? I tried to find support elsewhere but the only way is through the forum...

If any moderator would like to address the problem I would be happy to provide some more information,
Thanks so much again for your support Ryan

 
wpala94:
- Why does this lag only happen with Futures?

Have you asked your broker? It could be that reale time quotes are delayed if you don't pay.

 

Goodmorning Carl, thanks for your answer.

When I was talking about delay I didn't mean the difference with real time, but the candle is just behind the current price indicated on the axis. Looking at the image you can see that the candle should be smaller because the price is higher.

Below you can find a video where you can see that the last candle can't keep up with the current price, it's struggling a lot. You have an example of code above, but I also have indicators where in Calculate there is a for (500 interactions) where doing a trivial "iTime(_Symbol,PERIOD_M1,i)" slows everything down


 
wpala94 #:

Goodmorning Carl, thanks for your answer.

When I was talking about delay I didn't mean the difference with real time, but the candle is just behind the current price indicated on the axis. Looking at the image you can see that the candle should be smaller because the price is higher.

Below you can find a video where you can see that the last candle can't keep up with the current price, it's struggling a lot. You have an example of code above, but I also have indicators where in Calculate there is a for (500 interactions) where doing a trivial "iTime(_Symbol,PERIOD_M1,i)" slows everything down


Ah, I see that you're actually not trading futures contracts at all. You're trading CFD's (contracts for difference). The problem is with your CFD dealer.

 
wpala94 #:

When I was talking about delay I didn't mean the difference with real time, but the candle is just behind the current price indicated on the axis. Looking at the image you can see that the candle should be smaller because the price is higher.

Below you can find a video where you can see that the last candle can't keep up with the current price, it's struggling a lot. You have an example of code above, but I also have indicators where in Calculate there is a for (500 interactions) where doing a trivial "iTime(_Symbol,PERIOD_M1,i)" slows everything down


It would be great to clarify what is shown on the chart, specifically what are the ticks during this video, aka time and sales, which can be opened in a separate window in MT5.

I'm asking because the chart can be built on last price, but 2 horizontal lines are most likely ask and bid prices.

 

Hi what you have described is not a problem, it is a feature. 

We take soybean future as an example, most time when it is off the peak trading session, soybean is traded once every 5 minutes or so, your candle stick closing price used the "last price", your bid and ask straight lines are the bid and ask, sometimes bid and ask can both move up and down while nothing has been traded at all.

For example: right now last traded price is 1000, your bid is 999, ask is 1001;

Nothing happens in the next 5 minutes, last traded price is still 1000, but now bid is 1002, ask is 1005. And you will see the mismatch on the chart.