I thought that I understand that the parameter "Min bar period before directional change" allows a direction change after this period.
E.G. If the parameter is set to 3 the minimum distance between a peak and a trough must be 3 candles (or more). But as I saw it's not true (see the picture). Then I'd like to know what effect has this parameter.
I also don't understand what effect has the parameter "Max bar period before directional change".
I thought that I understand that the parameter "Min bar period before directional change" allows a direction change after this period.
E.G. If the parameter is set to 3 the minimum distance between a peak and a trough must be 3 candles (or more). But as I saw it's not true (see the picture). Then I'd like to know what effect has this parameter.
I also don't understand what effect has the parameter "Max bar period before directional change".
Thanks, that is a good question!
As it says in the description, the time trigger is secondary to the ATR, and should be regarded as a "soft" constraint. A main objective for the indicator is also to ensure that peaks and troughs are real price minima and maxima, which takes precedence as a "hard" constraint. So in your picture regarding the short segment in the middle, if the zigzag was to say place the trough at the next bar that wouldn't be the smallest price on that segment would it?
What I mean with secondary is that the min period tells the indicator that it "shouldn't" change if the segment duration is less than this, despite the ATR trigger telling it that it "should". The max period tells the indicator that it "shall" change (regardless of the ATR not having been triggered) if there has been that many bars since a new top/bottom was found. Whenever a trend continues higher or lower, this period will reset to 0 but when it triggers it will search the segment from the last high/low for its minimum/maximum price as an extrema in the opposite direction and insert a segment and trend change as such.
Thanks, that is a good question!
As it says in the description, the time trigger is secondary to the ATR, and should be regarded as a "soft" constraint. A main objective for the indicator is also to ensure that peaks and troughs are real price minima and maxima, which takes precedence as a "hard" constraint. So in your picture regarding the short segment in the middle, if the zigzag was to say place the trough at the next bar that wouldn't be the smallest price on that segment would it?
What I mean with secondary is that the min period tells the indicator that it "shouldn't" change if the segment duration is less than this, despite the ATR trigger telling it that it "should". The max period tells the indicator that it "shall" change (regardless of the ATR not having been triggered) if there has been that many bars since a new top/bottom was found. Whenever a trend continues higher or lower, this period will reset to 0 but when it triggers it will search the segment from the last high/low for its minimum/maximum price as an extrema in the opposite direction and insert a segment and trend change as such.
Thank you for your explanation. It wasn't easy to understand your "shouldn't", "should", "shall", "must" and so on. I had to read it several times but now I hope I understand it. The main trigger is ATR but if this trigger happens within the "Min period" it doesn't take into account (temporarily) and the indicator waits for new extremum. But if the new extremum doesn't happen within the "Max period" (a flat trend) then the indicator finds high/low after the last confirmed swing and this high/low is a new swing.
Thank you for your explanation. It wasn't easy to understand your "shouldn't", "should", "shall", "must" and so on. I had to read it several times but now I hope I understand it. The main trigger is ATR but if this trigger happens within the "Min period" it doesn't take into account (temporarily) and the indicator waits for new extremum. But if the new extremum doesn't happen within the "Max period" (a flat trend) then the indicator finds high/low after the last confirmed swing and this high/low is a new swing.
That is correct, and what I think happened in the picture. My terms also found in the code are:
- Shouldn't change: there has been less than "Min period" since a higher high or a lower low was found
- Should change: the length of a counter-trend move is larger than the ATR threshold
- Shall change: there has been more than "Max period" since a higher high or a lower low was found
- Must change: the length of a counter-trend move is larger than the trend's starting point
If both "should and NOT shouldn't", the trend is changed. Alternatively if either "shall or must" the trend is changed in a way which could override the ATR/time constraints.
The "can change" is less important, but makes sure that a trend change by the ATR trigger only happens if the most recent bar is the extremum in a counter-trend move, and not just because the ATR threshold had become smaller over time.
If we want to consider only ATR condition in ATRZigZag indicator, can we consider MinPeriod=0 and MaxPeriod=0
Thanks
Please prepare the mq4 version as well Thanks

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
ATR ZigZag:
Author: Andre Enger