I still have my reservations about the efficacy of this solution. But during live market hours today it is plotting values required to get to the next step. The last two lines in this code are the values associated with the most recent swing high and low as defined by the plots displayed by the ZigZagStepPattern. Which is not a study. You will only find that under Patterns.
So, if this works at all, you would create a boolean expression comparing the current value of “test3” to the previous bar’s value of “test3”. Likewise for the “test4” plot.
The rest is up to you. Good luck.
declare lower;
input priceH = high;
input priceL = low;
input percentageReversal = 5.0;
input absoluteReversal = 0.0;
input atrLength = 5;
input atrReversal = 1.5;
def zigZag = reference ZigZagHighLow(priceH, priceL, percentageReversal, absoluteReversal, atrLength, atrReversal).ZZ;
def step1 = open[1] >= open and open >= close[1] and open[1] > close[1];
def step2 = open[1] <= open and open <= close[1] and open[1] < close[1]; def upStep1 = step1 and close > open[1];
def upStep2 = step2 and close > close[1];
def downStep1 = step1 and close < close[1];
def downStep2 = step2 and close < open[1];
def UpStep = (upStep1 or upStep1[-1] or upStep2 or upStep2[-1]) and zigZag == low;
def DownStep = (downStep1 or downStep1[-1] or downStep2 or downStep2[-1]) and zigZag == high;
def test1 = if !IsNaN(UpStep) then UpStep else 0;
def test2 = if !IsNaN(DownStep) then DownStep else 0;
rec upStepHigh = if test1 then high else upStepHigh[1];
rec downStepLow = if test2 then low else downStepLow[1];
plot test3 = upStepHigh;
plot test4 = downStepLow;
Thanks Pete! I will play with it and let you know. Also just realized that the zigzaghighlow code changes the drawing if the time interval of an aggregation period is changed..