Can someone help me to setup fractals and find mistake

 

Hi, Im trying to make my own fractals indicator, its different, as I want it to be "zigzagly", it means there mustnt be a following similar upper or lower fractals, must be a chain like this: lower-upper-lower-upper-lower.....I hope its clear

And also, when we want to draw, for example, a new upper frac and the last frac is the same (upper), we have to check the last one, and if its lower than the new, ther we redraw by deleting last and creating new, else we just do not draw new.

But I guess Im missing something in my code, as it ignores conditions when I want to redraw

Look at example on my attached screenshot, red crosses - wrong fractals, period 5

Files:
6i9f3k.JPG  222 kb
newFracs.mq5  7 kb
Reason: