how can an indicator line pass from a candle high to its low ?

 

I am making an indicator to identify tops and bottoms of price movement and connect them just like the zigzag indicator

actually there are three buffers: tops[] , bottoms[],and zigzag[] which is the combination of tops and bottoms

my problem is that sometimes the same candle  qualifies to be have a top at candle high and a bottom at candle low which can happen when price spikes in both directions

that means that for that candle the  tops[] buffer has a reading  , the bottoms[] buffer has a reading ,and zigzag[] buffer should has two readings !!

that is my problem 

how can the zigzag buffer has two readings for the same candle ?

how can the indicator line passes from the high of a candle to its low ? 

any solution ?

 
dergham:

any solution ?

https://www.mql5.com/en/code/263
 
nicholishen:
https://www.mql5.com/en/code/263

thank you friend

I have different rules for peaks and bottoms

I just want the indicator line to have the ability to pass from the candle high (if it qualifies as top) to its low (if it qualifies as bottom) 

 
dergham:

thank you friend

I have different rules for peaks and bottoms

I just want the indicator line to have the ability to pass from the candle high (if it qualifies as top) to its low (if it qualifies as bottom) 

Yes, I know, and you'll find the example code in the linked indicator. :)
Reason: