Metatrader 5 indicator graph sometimes does not show at startup when off market hours

 

Hi

after several investigations, there is a bug which sometimes results in graph not showing at startup when these conditions are met:

  1. terminal startup
  2. off market hours ( no ticks received )
  3. history already saved on disk


In these conditions, OnCalculate is called several times until symbol series are synchronized ( 3 times here )

OnInit INIT_SUCCEEDED
line #112 OnCalculate: rates_start=8155  prev_calculated=0  rates_total=8180
line #109 LoadHistory: WS30 Loaded Bars= 0 / 788 (2025.12.18 01:00:00)
line #113 LoadHistory: WS30 NO SERIES_TERMINAL_FIRSTDATE
line #117 OnCalculate: WS30 1970.01.01 00:00:00
line #112 OnCalculate: rates_start=8155  prev_calculated=0  rates_total=8180
line #109 LoadHistory: WS30 Loaded Bars= 0 / 788 (2025.12.18 01:00:00)
line #113 LoadHistory: WS30 NO SERIES_TERMINAL_FIRSTDATE
line #117 OnCalculate: WS30 1970.01.01 00:00:00
line #112 OnCalculate: rates_start=8155  prev_calculated=0  rates_total=8180
line #109 LoadHistory: WS30 Loaded Bars= 8180 / 788 (2025.12.18 01:00:00)
line #117 OnCalculate: WS30 2025.12.18 01:00:00
line #134 OnCalculate: return 8180

The third and last call, indicator buffers are corretly calculated, OnCalculate returns 8180

Despite the indicator buffer is calculated, MT5 does not always show the graph, until I click on the indicator windows ( drag, resize, ... ) with no additionnal OnCalculate call. ( then the graph is finally displayed )


Note the bug never happens when I delete the history folder before launching MT5 ( in such case OnCalculate is called only 1 time when the history is correctly loaded )

OnInit INIT_SUCCEEDED
line #112 OnCalculate: rates_start=8155  prev_calculated=0  rates_total=8180
line #109 LoadHistory: WS30 Loaded Bars= 8180 / 788 (2025.12.18 01:00:00)
line #117 OnCalculate: WS30 2025.12.18 01:00:00
line #134 OnCalculate: return 8180


The only workaround I've found to fix this bug is to call ChartRedraw() manually.

void OnTimer()
{
   ChartRedraw();
   EventKillTimer();
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
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[])
{

   if( dtHistSymbol1 == 0 )
   {
      dtHistSymbol1 = LoadHistory( _Symbol, _Period, 0 );
      DebugPrint(_Symbol +" "+ (string)dtHistSymbol1);
      if( dtHistSymbol1 == 0 ) return prev_calculated;
      EventSetTimer(1);
   }
......


I think there is a bug in the timing at terminal's startup.


Maybe you have an explaination about this strange behavior and issue.


Documentation on MQL5: Event Handling Functions / Language Basics
Documentation on MQL5: Event Handling Functions / Language Basics
  • www.mql5.com
The MQL5 language provides processing of some predefined events . Functions for handling these events must be defined in a MQL5 program; function...
 

Check build 5572 which fixed a critical bug.

If it happens again, please provide a source code that compiles to reproduce the issue.

 
Alain Verleyen #:

Check build 5572 which fixed a critical bug.

If it happens again, please provide a source code that compiles to reproduce the issue.


Hi Alain

just upgraded to 5572

The bug is still here (but not each time), even if the startup timing is different ( only 2 OnCalculate calls instead of 3 at startup )


Funny part is that entering the Help \ About menu force the graph to show up without any additionnal OnCalculate call.


Not a big deal.

I will make a minimal code to share it here.


Thank you