Hey does anyone know why this zigzag indicator is behaving like this. Not marking proper swings?
shown by red arrows.
zigzag values are - 7,5,3
timeframe 5 minute
is there any solution to avoid this fake swings or weird swings?
You are right, zigzag indicator is far from perfect indeed (what do you expect from a free indicator). It repaints/depends entirely on past price action.
Looking for something more reliable/predictable? - your next stop is Freelance section.
You can also search in the Market and Codebase for Indicator that meets your quality criteria.
- 2025.03.01
- www.mql5.com
Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893
Sac D:
Hey does anyone know why this zigzag indicator is behaving like this. Not marking proper swings?
shown by red arrows.
zigzag values are - 7,5,3
timeframe 5 minute
is there any solution to avoid this fake swings or weird swings?
This is normal for the built-in zigzag. It also recalculates (may redraw) its 3 recent points with each tick.
I have seen the source code of dozens of custom zigzags, but they are all based on the built-in zigzag and inherit its redrawing of 3 recent points and the probability of 2 swing highs or 2 swing lows in a row. I haven't seen a single custom zigzag that wasn't based on the built-in zigzag.
Don't try to hire a freelancer to "fix" the built-in zigzag. Few people are able to fully understand how it works (from what people write on the forum and from the source code I've seen), and no one can "fix" something that works as intended.
Hey does anyone know why this zigzag indicator is behaving like this. Not marking proper swings?
shown by red arrows.
zigzag values are - 7,5,3
timeframe 5 minute
is there any solution to avoid this fake swings or weird swings?
A solution would be to :
- accept there will be one repainting leg until a new one starts.
- absolute symmetry in rules between history and live behavior.
- accept strict rules will result in small "legs" too.
Between those two swing lows there was a swing high that was cancelled. The swing high was canceled because that's how it works, the logic of the zigzag means that a new high can cancel the previous high if it is too close. Nobody can fix that because that's not a bug.
Between those two swing lows there was a swing high that was cancelled. The swing high was canceled because that's how it works, the logic of the zigzag means that a new high can cancel the previous high if it is too close. Nobody can fix that because that's not a bug.
yep
and if it was altered it would look like this which many would reject again because you'd have to accept smaller legs (a) and that you dont know where the red leg will stop (b)
although in this case the mini legs could be generalized but at the moment in time the red leg started and not before
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.struct S_ZZ_Parameters { int dir; double cur_L; double cur_H; double prev_L; double prev_H; datetime cur_L_time; datetime cur_H_time; datetime cur_L_rsi; datetime cur_H_rsi; int extrem; }; struct S_Hypermodel_ZZ_Training_Data { double zz_arr []; datetime zz_time[]; //int zz_rsi []; }; template <typename D, typename T/*, typename I*/> void F_ZZ_data_mining_algorithm_for_machine_learning(const int datasize, S_ZZ_Parameters &par, const double dev, const D &src_L[], const D &src_H[], const T &src_T[], /*I &src_R[],*/ D &arr[], T &time_arr[]/*, I &rsi_arr[]*/) { int startindex = 2; par.extrem = 0; if (src_L[0] < src_H[1]) { //Print("startindex if :",startindex); par.prev_L = par.cur_L = src_L[0]; par.prev_H = par.cur_H = src_H[1]; par.dir = 1; } else { //Print("startindex if else :",startindex); par.prev_H = par.cur_H = src_H[0]; par.prev_L = par.cur_L = src_L[1]; par.dir = 2; } //Print("startindex ELSE :",startindex); for(int idx = startindex; idx < datasize - 1; idx++){ switch(par.dir){ case 1 : // Last was a low - goal is high if (src_L[idx] <= par.cur_L)// SEC 1-1 / FOUND NEW LOW / CONFIRMS IF SEC 2-1 OR SEC 1-2 EXECUTES NEXT { //Print("1 - 1 : idx: ",idx," par.extrem: ",par.extrem); par.cur_L = src_L [idx]; par.cur_L_time = src_T [idx]; //par.cur_L_rsi = src_R[idx]; par.extrem = idx; //Print("1 - 1 end: idx: ",idx," par.extrem: ",par.extrem); arr [par.extrem] = par.cur_L; time_arr [par.extrem] = par.cur_L_time; //rsi_arr [par.extrem] = par.cur_L_rsi; break; } if (src_H[idx] > (par.cur_L + dev))// SEC 1-2 / TRYING TO FIND NEW HIGH / CONFIRMS ONLY IF SEC 2-2 QUICKLY EXECUTES NEXT { //Print("1 - 2 : idx: ",idx," par.extrem: ",par.extrem); par.prev_H = par.cur_H; par.cur_H = src_H [idx]; par.cur_H_time = src_T [idx]; //par.cur_H_rsi = src_R[idx]; par.extrem = idx; //Print("1 - 2 : end idx: ",idx," par.extrem: ",par.extrem); arr [par.extrem] = par.cur_H; time_arr [par.extrem] = par.cur_H_time; //rsi_arr [par.extrem] = par.cur_H_rsi; par.dir = 2; // new high found } break; case 2: // Last was a high - goal is low if (src_H[idx] >= par.cur_H)// SEC 2-1 / FOUND NEW HIGH / CONFIRMS IF SEC 1-1 OR SEC 2-2 EXECUTES NEXT { //Print("2 - 1 : idx: ",idx," par.extrem: ",par.extrem); par.cur_H = src_H [idx]; par.cur_H_time = src_T [idx]; //par.cur_H_rsi = src_R[idx]; par.extrem = idx; //Print("2 - 1 : end idx: ",idx," par.extrem: ",par.extrem); arr [par.extrem] = par.cur_H; time_arr [par.extrem] = par.cur_H_time; //rsi_arr [par.extrem] = par.cur_H_rsi; break; } if (src_L[idx] < (par.cur_H - dev))// SEC 2-2 / TRYIMG TO FIND NEW LOW / CONFIRMS ONLY IF SEC 1-2 QUICKLY EXECUTES NEXT { //Print("2 - 2 : idx: ",idx," par.extrem: ",par.extrem); par.prev_L = par.cur_L; par.cur_L = src_L [idx]; par.cur_L_time = src_T [idx]; //par.cur_L_rsi = src_R[idx]; par.extrem = idx; //Print("2 - 2 : end idx: ",idx," par.extrem: ",par.extrem); arr [par.extrem] = par.cur_L; time_arr [par.extrem] = par.cur_L_time; //rsi_arr [par.extrem] = par.cur_L_rsi; par.dir = 1; // new low found } break; } } }
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.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
shown by red arrows.
zigzag values are - 7,5,3
timeframe 5 minute
is there any solution to avoid this fake swings or weird swings?