In the 1980s and 1990s, programmers faced hardware constraints that forced them into particular software design choices.
Before MT4 or MT5 ever existed, early retail trading platforms (like MetaStock and Omega Research ProSuite/TradeStation) in the 90s featured a conceptual function usually named Zigzag(ChangeAmount, Method).
Computers back then had a fraction of the memory and processing power we have today. To calculate a trend line, programmers couldn't afford to run elegant, stateful objects or deep memory arrays. They had to rely on raw mathematical loops that worked with what is called a multi-pass reduction sieve.
Pass 1 (The Sieve): Dump every possible local mathematical peak into a generic array to narrow down the dataset.
Pass 2 (The Clean-up): Crawl through that array and start hacking away elements that don't fit a hard-coded geometric rule.
Because it was designed as a visual mapping tool for offline charts rather than a real-time execution engine for automated trading systems, the original authors didn't care about repainting.
The standard Zigzag that people are accustomed to today is efficient in how it balances memory management, depth loops, backsteps, and caching to protect the CPU. It is a masterpiece of low-level optimization.
Yet, it it can fail fundamentally at being an effective real-time trading tool.
In the worst scenario, it places a bet (draws a line), gets new data two bars later, panics, erases its old bet, and pretends it was pointing at the current prices the whole time.
A pure state machine zigzag with regime locks is conceptually much simpler, and far more reliable for modern trading. It has absolute unidirectional focus: If it is in one search state (searching for a peak), it doesn't care about lower lows; it is single-mindedly searching for the peak. It works on closed boundaries: by ignoring intra-bar noise or locking decisions to the close of the bar, it never has to use a "Backstep" to erase its own history. The trading world is filled with these legacy code traps: complex algorithms written for the constraints of 1995 hardware that programmers blindly copy-paste into 2026 systems.
Many of the zigzag indicators that still float around today are batch-processing systems pretending to be a real-time streaming system. Instead of processing market data bar-by-bar from left to right like a true unidirectionally focused state machine, it groups chunks of bars together, dumps them into a processing hopper, and runs sorting algorithms on the entire batch.
The Real-Time Data Storage Problem
A wave-based indicator requires persistent state memory storing global variables like ExtremeWave, currentState, and lastPivotBar inside the platform's memory across restarts.
In 1990, charting software didn't have robust, persistent databases tracking individual indicator states. If a trader refreshed a chart, changed timeframes, or lost their internet connection for 5 minutes, those running variables would instantly vanish into thin air. History was stored as a flat file of closed bars (Open, High, Low, Close). Live ticks were just thrown at the screen in real-time.
If a massive spike occurred on a live bar:
- The state machine would process the live tick, see the massive spike, and permanently change its internal state variable.
- If you refreshed the chart 5 minutes later, the platform would throw away the live tick cache and reload the data from the hard drive's bar file.
- If the broker's historical server smoothed out or adjusted that bad data spike in the official bar file, the indicator would suddenly calculate a different result on the refresh than it did live.
MQL5 completely solved this by standardizing the OnCalculate pipeline. Whether a bar happened 10 years ago or 10 milliseconds ago, it is fed to your script through the exact same structured arrays (high[], low[], close[]). The terminal ensures that historical data processing matches live tick processing perfectly.
By using an artificial boundary like Depth = 12, the programmers built a stateless safety net. If the chart crashed or refreshed, the indicator didn't need to know what happened three hours ago. It only needed to look at the static, visible batch of the last 12 bars on the screen to instantly recalculate everything. It was a brilliant hack in the 1990s for a world with unstable data feeds and low RAM.
The Traditional Charting Mindset
Technical analysis in the 20th century was heavily influenced by fixed-period math. Traders were obsessed with cycles and time-based constants. Original authors behind the Zigzag wanted a tool that would isolate macro waves of a specific scale relative to the visible chart. By tying the lookback to a fixed number of bars (Depth), the indicator naturally adapted to the visual zoom of the timeframe. A lookback Depth of 12 on a Daily chart looks for swings spanning a couple of weeks; on a 5-minute chart, it looks for swings spanning an hour.
By throwing away an artificial lookback window and letting a state machine dynamically track the market's organic waves, you can have high quality indicators that are very reliable in real-time trading, more simple in design, and you can skip thirty years of legacy over-engineering.


