A custom indicator does not redraw its entire history every time a new quote arrives. Its calculation function receives information about available price bars and earlier processing, then decides which values need updating. Poor handling of that handoff can make a convincing indicator unreliable precisely when a trading decision depends on it.
In metatrader 4, OnCalculate is the event handler that performs this work for indicators written in modern MQL4. It receives price-series arrays and two particularly important counters, rates_total and prev_calculated. Understanding their relationship helps distinguish legitimate recalculation from misleading signals.
Misreading prev_calculated Can Leave Old Values on the Chart
The terminal supplies rates_total as the number of bars currently available and prev_calculated as the value returned by the previous OnCalculate call. Returning rates_total is a common way to tell the terminal how far processing has progressed.
A calculation loop that assumes prev_calculated always equals the previous bar count can skip necessary work. When deeper history is downloaded or missing bars are filled, the terminal can reset prev_calculated to zero. Code must recognize that reset and rebuild affected buffers rather than preserve values calculated from an incomplete series.
Array Direction Can Reverse the Meaning of Recent Prices
Price arrays are not safe to interpret by index without checking their indexing direction. MQL4 offers ArrayGetAsSeries and ArraySetAsSeries so indicator logic can explicitly establish whether index zero represents the newest bar.
An indicator comparing close[0] with close[1] may intend to measure the latest movement. If its indexing assumptions are wrong, it can instead compare older observations or write output into the wrong buffer location. Consistent array orientation matters more than the apparent simplicity of the formula.
Updating the Open Bar Can Create Signals That Disappear
Imagine a hypothetical custom momentum indicator on a fifteen-minute silver CFD chart. It flags a breakout when the current bar closes above the preceding ten-bar high, but its code actually tests the changing close price of bar zero on every tick.
At 10:07, silver rises above the threshold and a green arrow appears. By 10:15, the bar closes below the threshold and the arrow disappears after recalculation. An automated strategy that bought when the arrow first appeared could retain a losing position even though the historical chart now shows no signal. The error is not necessarily dishonest repainting; the calculation used an unfinished bar while the trading rule assumed a completed one.
Recalculating Every Bar Can Delay Time-Sensitive Decisions
A full scan of thousands of historical bars on every tick wastes processing time when only the newest values have changed. Reusing previously calculated results can improve responsiveness, especially when several indicators run together.
Efficiency creates its own trap: an overly narrow update window may miss changes in neighboring values used by moving averages or multi-bar conditions. The appropriate loop boundary depends on the indicator’s lookback period and whether the current bar remains mutable. Faster execution is useful only when its output remains correct.
Buffer Values Can Differ From What the Screen Appears to Show
OnCalculate writes numerical results into indicator buffers, which other programs may read through iCustom. Visual styling, empty-value settings and delayed updates can make the chart presentation differ from the raw value retrieved by an expert advisor.
For metatrader 4 strategies, a visible arrow is not sufficient evidence that an automated entry condition receives the intended signal. Before opening a CFD position based on a custom indicator, test its OnCalculate behavior during live ticks, after a history refresh and at bar close; then compare the exact buffer index and value read by the trading algorithm with the signal shown on the chart.

More Stories
What Are the Key Components Reviewed During a Financial Statements Audit?
How an SME Audit Firm Can Simplify Annual Financial Reporting for Business Owners
How to Evaluate the Experience and Expertise of a Singapore Audit Firm