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
One could argue that zig zag logic is rather complicated. In any case, a logic error occurs in the code if the indicator locks the previous state too early. All zig zag indicators are repaintable in a logical sense, otherwise, they wouldn’t work. The key issue is ensuring that a new extreme is confirmed before locking the previous state.
As debugging is a voluminous task and I won’t delve into the code in detail. But I can provide my own code for reference if needed. This never misses and can be used to harvest data into arrays. there are also explanations and print statements for debugging. Maybe this will help.this "sec 1_2"...."sec 2_2" stuff really isn't a a proper comment and doesn't make sense to an outside observer. If you're confident about it, why not put a working code on the codebase? You can say something, but nobody will believe what you're saying. I'm sceptical that a few seconds of time will do anything good to confirm a swing
If anyone wants a non-repainting ZigZag-ish indicator, see attached. The arrows/alerts are generated when each permanent "square" extremum appears. As is usually the case between repainting and non-repainting variants, you are accepting lag to obtain certainty by using this indicator.
I just backtested this, and it's not bad actually, the lag is acceptable...it isn't that much lag which makes this reasonable
I just backtested this, and it's not bad actually, the lag is acceptable...it isn't that much lag which makes this reasonable
Thank you. Truth be told, it's not my logic. No one else could convert the original jumbled up MQL4 code to MQL5 on another forum so I did it at another trader's request. Have you ever seen a programmer write like a human decompiler? I have. Credit to the original file name is in the header. No coder was listed, of course.
1: If you're confident about it, why not put a working code on the codebase? You can say something, but nobody will believe what you're saying.
2: I'm sceptical that a few seconds of time will do anything good to confirm a swing
2: it's not about time, this comment is misleading though... since i built it once on top of m1 timeframe to bugfix it i have left comments like this. Think of state management instead of time. these are the points that are of concern for some zigzag algorithms as shown at the beginning of the thread.
The term "repainting" is a simplification that doesn’t fully capture the technical reality of algorithms like the Zig Zag therefore I used the word repaint in the wrong context and meant the wrong state management. Repainting and false logic are not the same and shouldn’t be confused.
1: I'm almost sure it's old code but it's not an indicator, it's the logic of sequencing high and low extremes without messing up the order. Basically it's the same but instead of drawing a line, data is collected. There are many indicators even in the code base...why one more...
2: it's not about time, this comment is misleading though... since i built it once on top of m1 timeframe to bugfix it i have left comments like this. Think of state management instead of time. these are the points that are of concern for some zigzag algorithms as shown at the beginning of the thread.
The term "repainting" is a simplification that doesn’t fully capture the technical reality of algorithms like the Zig Zag therefore I used the word repaint in the wrong context and meant the wrong state management. Repainting and false logic are not the same and shouldn’t be confused.
I see what you mean. This guy wrote a zigzag for MT4 with similar state management and the code is quite clean:
Code Base
Auto Scale ZigZag
Evgeniy Chumakov, 2024.12.17 13:13
ZigZag with automatic step size detection for changing wave direction.If you want an MT5 version:
Code Base
Autoscaling Zigzag
Conor Mcnamara, 2025.03.02 22:18
A zigzag indicator that uses a single input to adjust the step size for detecting wave direction changesAutoscaling Zigzag
Conor Mcnamara, 2025.03.02 22:18
A zigzag indicator that uses a single input to adjust the step size for detecting wave direction changesi didn't look at your backround, i didn't need to explain it to You but maybe it's still helpful for those who are still working on it....
zigzag is a super good statistics gathering tool in general... I once built a data collector and optimiser on top of zig zag logic. A very effective combination. Unfortunately collects statistics only on y axis.
Now with this topic I got interested again, the idea came up to build additional geometric calculation combinations for better statistical analysis but, that's probably off topic already.
i didn't look at your backround, i didn't need to explain it to You but maybe it's still helpful for those who are still working on it....
zigzag is a super good statistics gathering tool in general... I once built a data collector and optimiser on top of zig zag logic. A very effective combination. Unfortunately collects statistics only on y axis.
Now with this topic I got interested again, the idea came up to build additional geometric calculation combinations for better statistical analysis but, that's probably off topic already.
Maybe consider combining a non-repainting wide set zigzag with a repainting narrow set zigzag. Taking this a bit further, scaling-in based on repaints while non-repaints remain current is possible.💡
On the discussion of static zigzag above, I argue that this is in fact suitable for live trading, the non repainting aspect means that you have a direct location for buy or sell signal. The zigzag won't paint too many legs if the period is high for calculation of the extremes. How it becomes useful for entry indication is that a bottom facing leg marks a support area (ideally) letting you know that the next leg HAS to be upwards as part of the structure. It's still not using math, but extremes based on a period are still extremes, which are useful pivot points. This non repainting structure is preferable for some. But the extremes themselves can be invalidated with a break of the market structure. Similarly in donchian channel.
that's true, no argument at all. It all depends on the strategy. I just use the dynamic version for trading and the static one for collecting statistics and setting levels. All levels based on the static one. The dynamic one is predictive in nature and makes entry faster by simply trying to predict the location of the current extreme after threshold is reached, or even the scale of the next extreme while the running extreme is not yet set in stone...
I just backtested this, and it's not bad actually, the lag is acceptable...it isn't that much lag which makes this reasonable
The lag is simply inversely related to the threshold value, which is calculated to the desired deviation value, of course the lag is larger if we try to use larger values as extreme points. Mathematically it is simply not possible to do it differently... So there is no best zif zag algorithm , there is only a choice between the correct and the incorrect option, nothing more is possible! But who are interested to discuss... Today I just built a new zigzag algorithm that determines basic statistical values and also performs geometric calculations. We get all data only once passing through the raw data, using the (incremental computing) so-called stream processing solution. So we get all the valuable data without using any of additional arrays... Within one move through the source data and in addition to the zigzag movement values (which it would be prudent to store for future processing), the entire statistics are also available in the same pass. The algorithm goes through the history and presents statistics, after which it switches to live processing updating same statistics. In live we compare only the data of the current bar - with the data of previous bar -we use logical layers to manage the rest.... therefore it is extremely effective and optimal... just talking because it's an interesting topic and maybe it will help keep you motivated :)