Hi all, any ideas why my ValueWhen statement 'appears to me to' always return the Array value, regardless of the Expression? My code is below and in my screenshot, you will see the values of the PivotTrue array which are occasionally==1, so why is the LOW value always returned?
LeftPeriodLow = LLV(L,Size+1); // LLv of x bars to the left (plus current bar)
RightPeriodLow = Ref(LeftPeriodLow,Size); // LLv of x bars to the right
PivotTrue = LeftPeriodLow == Low AND RightPeriodLow == Low AND bi+1<(BarCount-Size); // creates an array of TRUE/FALSE at each pivot location
Pivots = ValueWhen(PivotTrue==1,Low); //creates an array of Pivot LOWs
ValueWhen keeps true state till next change to true. So if there is a true state on a bar then its Low (that you inserted as 2nd argument of ValueWhen) is kept for all following bars not having true state. If there is a new true state then that one's Low is chosen next.
Don't know what you are trying to do but If you want to return Low only when there is TRUE at bar then use IIf function instead.
Pivots = IIf(PivotTrue, Low, Null); //creates an array of Pivot LOWs
PlotShapes( PivotTrue * shapeSmallSquare, colorRed, layer = 0, y = Pivots, -12 );
So in upper IIf example Low is available only at bar where PivotTrue is true else Null is returned (if false at bar).