I'm attempting to make a filter for identifying a number of bars since a pivot high or low. I have provided the code below. The issue is that currently I have not figured out the logic that properly identifies the pivot high or pivot low and to start counting from that pivot high or pivot low. Any suggestions?
private int BarsSinceHigh = 0;
private int BarsSinceLow = 0;
private bool BarCount1 = true;
private bool BarCount2 = true;
if(MIN(Low,16) < Low) //How do instead create a condition to identify the pivot low?
if(BarsSinceLow >= 8)
BarCount1 = true;
if(MAX(High,16) > High) How do instead create a condition to identify the pivot High?
There are basically two methods of identifying highs and lows. One is based on the lookback period, the other one on the minimum deviation.
Lookback period: A pivot of strength 8 would be a candle with a higher high than the 8 preceding and 8 following candles. The pivot high or low would be unconfirmed, if such a candle has just plotted. Confirmation of the pivot high or low will be 8 bars later, if the provisory piovt high or low has not been taken out. I would mark that high or low already when a new candle has a higher high or lower low than the 8 preceding bars. Then keep it, if it is confirmed. To count the candles that have passed from this pivot just collect the CurrentBar, when the pivot is identified. Store the value somewhere. N bars later, you can call CurrentBar again and compare it with the stored value. The difference will be N.
Zigzag : A more elegant way to identify highs and lows is a zigzag indicator which is based on a minimum deviation. You can for example use the zigzag indicator of NinjaTrader and simply access the highs and lows.