How to find a valid or an invalid pivot point

Hi, I use the following code for pivots. I have taken inspiration and copied from aspects of the code from this forum and don't exactly know from where all

 function createPivots(nbar)
{
    // High Pivots
    vPHigh 		= (H > Ref(HHV(H, nbar) , -1)) AND (Ref(HHV(H, nbar), nbar) < H);
    vPHighP0 	= ValueWhen(vPHigh, H);
    vPHighP1 	= IIf(vPHighP0 AND (BarsSince(vPHigh) > nbar), vPHighP0, Null);
    vPHighP2    = IIf(vPHighP0 AND (BarsSince(vPHigh) <= nbar), vPHighP0, Null);
    
    // Low Pivots
    vPLow 		= ((L < Ref(LLV(L, nbar), -1)) AND (Ref(LLV(L, nbar), nbar) > L));
    vPLowP0 	= ValueWhen(vPLow, L);
    vPLowP1 	= IIf(vPLowP0 AND (BarsSince(vPLow) > nbar), vPLowP0, Null );
    vPLowP2    	= IIf(vPLowP0 AND (BarsSince(vPLow) <= nbar), vPLowP0, Null );
    
    
     // High - Low Difference
    vHV 		=  ValueWhen(vPHighP2, vPHighP0);
    vLV 		=  ValueWhen(vPLowP2, vPLowP0);
    
    vDiffHi 	= (C - vHV ) /vHV * 100;
	vDiffLo 	= (C - vLV ) / vLV * 100;

    return vDiffHi;
}   


  AddColumn(createPivots(1),"1DW",1.2);
  AddColumn(createPivots(2),"2DW",1.2);

The issue with above code is when I run an exploration of price %away from the pivots

  • it gives me multiple signals- one (correct-green arrow) when the price has not crossed the pivot i.e Valid Pivot and the other times the price pulls back into the range or pivot but for me, it is not a valid pivot anymore (red arrow)

image

I have tried the cum or sum functions but does not do the job - is there a way to solve this

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.