Max Bars in Chart vs Max Bars in History: What Actually Lightens an MT4 Terminal

Max Bars in Chart vs Max Bars in History: What Actually Lightens an MT4 Terminal

11 November 2026, 14:21
Boris Armenteros
0
8

When MT4 freezes or hangs, two of the terminal's own settings decide how much price history it loads and stores, and one of them sets how many bars every indicator works through. A few of the commands you might go looking for are not in the terminal at all. This post covers both, with a small MQL4 indicator that shows how the bar limit reaches your code.

Two bar limits, two different jobs

Tools > Options > Charts holds two values that look alike but do different things:

  • Max bars in chart caps how many bars each chart loads when it opens. Those bars, with every indicator calculated on them, cost processor time and memory.
  • Max bars in history only caps how many bars are saved to disk when a chart closes.

If the terminal struggles with several charts open, the first one is the setting to lower. It applies when a chart opens, so after lowering it, close and reopen your charts or restart MT4.

There is no cache to clear

MT4 has no command that clears a cache. What builds up is price history, and the two settings above control how much of it the terminal handles. Lower values leave the terminal less to load and store.

How the bar limit reaches your indicator

The MQL4 documentation for OnCalculate() says that rates_total "corresponds to the number of bars available in the chart", and that prev_calculated "contains a value returned by OnCalculate() during previous call". The terminal also sets prev_calculated to zero when the price data has changed since the last call, for example when a deeper history was downloaded or gaps were filled.

Put together: whenever prev_calculated is zero, the indicator recalculates every bar the chart holds, and Max bars in chart is the ceiling on that pass. On the other calls, an indicator that uses prev_calculated only touches the bars that are new. One that loops over all rates_total bars on every call repeats that full pass on every call, on every chart it is attached to.

Here is the pattern, with two log lines that make the setting visible:

#property strict
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 clrDodgerBlue

double MedianBuffer[];

int OnInit()
  {
   SetIndexBuffer(0, MedianBuffer);
   SetIndexStyle(0, DRAW_LINE);
   ArraySetAsSeries(MedianBuffer, true);
   printf("%s: Max bars in chart = %d", __FUNCTION__, TerminalInfoInteger(TERMINAL_MAXBARS));
   return(INIT_SUCCEEDED);
  }

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[])
  {
   ArraySetAsSeries(high, true);   // index 0 = newest bar
   ArraySetAsSeries(low, true);

   int limit = rates_total - prev_calculated;   // bars not calculated yet
   if(prev_calculated > 0)
     {
      limit++;                                  // recalculate the forming bar too
     }
   else
     {
      printf("%s: full pass over %d bars", __FUNCTION__, rates_total);
     }

   for(int i = limit - 1; i >= 0; i--)
     {
      MedianBuffer[i] = (high[i] + low[i]) / 2.0;
     }
   return(rates_total);                          // becomes prev_calculated on the next call
  }

TerminalInfoInteger() with TERMINAL_MAXBARS returns "the maximal bars count on the chart", so the indicator logs the limit in effect at start-up, and every full pass logs how many bars it covered. When a terminal is slow, those two log lines show what it is working with before anyone starts guessing.

Stopping an EA: the Navigator is not the chart

Running too many Expert Advisors at once can make the platform unstable. To stop one you do not need, remove it from its chart through the chart's right-click menu, under Expert Advisors, or close the chart it runs on. Deleting the EA in the Navigator window does not stop a copy that is already running on a chart.

Commands that are not in the terminal

Three things you might look for in the terminal's menus are not there:

  • "Check for updates": the Help menu has no such command. To see which build you run, open Help > About, and if it is old, download the current installer from your broker. Updates often include bug fixes and performance improvements.
  • "Visual mode": this is not a terminal setting. It is a checkbox of the Strategy Tester.
  • "Clear the cache": as above, there is no such command. The bar limits are what you control.

One switch that does exist: if you do not read the news feed inside the terminal, go to Tools > Options > Server and uncheck Enable news.

The rest of the checklist

The remaining causes sit outside the terminal:

  • A wired connection is more stable than Wi-Fi.
  • Task Manager on Windows shows CPU, memory and disk usage. If the machine is short of resources, close the programs you do not need.
  • A VPS located near your broker's server reduces latency, and it can be configured to start MT4 automatically when it boots.

If the problem persists after all of this, your broker's support team is the next contact. The full guide, with each step in more detail, is on our site: How to prevent MT4 terminal from crashing, freezing or hanging.