You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
If the high isn't fully formed yet and a new high appears, the new high cancels out the previous high.
If there was a low between those two highs, then you get a zigzag leg connecting the two lows.
This is a special case that sometimes arises. The leg connecting two lows is a display issue, not a behavior issue.
If the high isn't fully formed yet and a new high appears, the new high cancels out the previous high. If there was a low between those two highs, then you get a zigzag leg connecting the two lows.
Although, in theory, one could try to anticipate this case in the algorithm: a new high should not cancel out the previous one if there is a low between them.
I've had the idea of writing an article about developing an advanced version of the built-in zigzag in my head for a long time. That is, keeping the algorithm but adding additional features. I already have some experience with this and some ideas.
Now I've got an additional idea - to add this feature and the ability to enable/disable it in the settings:
Forum on trading, automated trading systems and testing trading strategies
Possible bug in the ZigZag indicator (MT5)
Vladislav Boyko, 2026.07.30 09:56
a new high should not cancel out the previous one if there is a low between them.
I won't have time for this in the next couple of months, but I'll implement it sooner or later.
I've had the idea of writing an article about developing an advanced version of the built-in zigzag in my head for a long time. That is, keeping the algorithm but adding additional features. I already have some experience with this and some ideas.
Now I've got an additional idea - to add this feature and the ability to enable/disable it in the settings:
I won't have time for this in the next couple of months, but I'll implement it sooner or later.
This is what makes a zigzag a zigzag. One of the fundamental principles of the algorithm.
This is a special case that sometimes arises. The leg connecting two lows is a display issue, not a behavior issue.
Ask an AI agent 😁
I tinkered with an AI agent before and found that it can't code working zigzags at all, and even if you give it a working zigzag code, it will break it for you. It seems that the AI is more efficient at coding more straightforward indicators like an ATR or moving average.
IMHO, MQL5 Lite AI's strongest suit is converting/rewriting indicator code from other languages.
One thing that I learned rather quickly is to prompt the prepositional phrase, "without editing my original indicator code." 😬
Hello MQL Team, or anyone around,
I would like to report what appears to be an issue with the standard ZigZag indicator.
I loaded a ZigZag (Depth = 480, Deviation = 5, Backstep = 3) on the EURUSD H1 chart. A depth of 480 corresponds to approximately 20 trading days (24 hours × 5 trading days per week).
The indicator correctly plotted a downward segment between:
(All times are MetaQuotes-Demo server time.)
From that point onward, however, the indicator unexpectedly draws a new segment directly from that low (1.13240) to the next low formed on 28 July, 13:00 — 1.13533.
This behaviour seems incorrect for two reasons:
Could you please confirm whether this is the expected behaviour of the standard ZigZag algorithm, or whether it is a bug?
Thank you in advance for your assistance.
Kind regards,
I analyzed the standard ZigZag.mq5 source code regarding your issue. The drawing bug when setting a large InpDepth (like 480) is caused by a hardcoded lookback limit of 100 bars inside the OnCalculate function.
The Solution: You can easily fix this by modifying two lines in your ZigZag.mq5 file to remove the hardcoded limits.The Root Cause:When a new tick arrives, the default code tries to find the last 3 extremes ( ExtRecalc = 3 ) to resume its calculation. However, it restricts the search to only the last 100 bars ( rates_total - 100 ). If your InpDepth is 480, it is mathematically impossible to find 3 extremes within just 100 bars. The loop gives up, the starting point of the calculation gets corrupted, and the indicator draws incorrectly (e.g., connecting a high to a high).
Fix 1: Ensure enough bars exist before starting.
Original:
if(rates_total<100)
return(0);
Modified:
if(rates_total<InpDepth)
return(0);
Fix 2: Remove the 100-bar lookback limit.
Allow the while loop to search as far back as necessary to find the last 3 extremes.
Original:
while(extreme_counter<ExtRecalc && i>rates_total-100)
Modified:
while(extreme_counter<ExtRecalc && i>=0)
This is probably a known issue, but applying this fix should resolve it.