Need help to plot line in every pivot

#1
Hi All,
I am trying plot line on every pivot and below is the formula I am using for it
Code:
HPH = Ref(H,-3) < Ref(H,0) AND Ref(H,-2) < Ref(H,0) AND Ref(H,-1) < Ref(H,0) AND Ref(H,1) < Ref(H,0) AND Ref(H,2) < Ref(H,0) AND Ref(H,3) < Ref(H,0);
LPL = Ref(L,-3) > Ref(L,0) AND Ref(L,-2) > Ref(L,0) AND Ref(L,-1) > Ref(L,0) AND Ref(L,1) > Ref(L,0) AND Ref(L,2) > Ref(L,0) AND Ref(L,3) > Ref(L,0);
HPHV = ValueWhen(HPH,H,0);
LPLV = ValueWhen(LPL,L,0);
Plot(HPHV, "PH", colorBlue,styleStaircase|styleThick|styleDashed);
Plot(LPLV, "PL", colorBlue,styleStaircase|styleThick|styleDashed);
and the output comes as below.


So after pivot 1, the same line should be extended till pivot 2 bar. Here it is not the case. Someone Please help me?

Thanks
 
Last edited:

amitrandive

Well-Known Member
#2
Hi All,
I am trying plot line on every pivot and below is the formula I am using for it
Code:
HPH = Ref(H,-3) < Ref(H,0) AND Ref(H,-2) < Ref(H,0) AND Ref(H,-1) < Ref(H,0) AND Ref(H,1) < Ref(H,0) AND Ref(H,2) < Ref(H,0) AND Ref(H,3) < Ref(H,0);
LPL = Ref(L,-3) > Ref(L,0) AND Ref(L,-2) > Ref(L,0) AND Ref(L,-1) > Ref(L,0) AND Ref(L,1) > Ref(L,0) AND Ref(L,2) > Ref(L,0) AND Ref(L,3) > Ref(L,0);
HPHV = ValueWhen(HPH,H,0);
LPLV = ValueWhen(LPL,L,0);
Plot(HPHV, "PH", colorBlue,styleStaircase|styleThick|styleDashed);
Plot(LPLV, "PL", colorBlue,styleStaircase|styleThick|styleDashed);
and the output comes as below.


So after pivot 1, the same line should be extended till pivot 2 bar. Here it is not the case. Someone Please help me?

Thanks
Try this improved formula

Code:
LB= Param("Look Back Periods",10,1,30,1);
R=ValueWhen(Cross(MA(C,LB),C),HHV(H,LB),1);
S=ValueWhen(Cross(C,MA(C,LB)),LLV(L,LB),1);
Color=IIf(O>C,colorBlack,colorYellow);
Plot (R,"Resz",22,8+16);
Plot (s,"Supp",19,8+16);
Plot (C,"Close",color,64,32);
GraphXSpace=4;
 
#3
Try this improved formula

Code:
LB= Param("Look Back Periods",10,1,30,1);
R=ValueWhen(Cross(MA(C,LB),C),HHV(H,LB),1);
S=ValueWhen(Cross(C,MA(C,LB)),LLV(L,LB),1);
Color=IIf(O>C,colorBlack,colorYellow);
Plot (R,"Resz",22,8+16);
Plot (s,"Supp",19,8+16);
Plot (C,"Close",color,64,32);
GraphXSpace=4;
Thanks Amit for the reply. Still it looks value hardcoded right? I tried below code earlier and it extending to next 10 bars as I fixed. So now have to find out number of bars between previous and current pivot and need to extend accordingly. Please correct if I wrong. But don't know how to count that even I tried barssince

Code:
Plot(HPHV, "", colorBlue,styleStaircase|styleThick|styleDashed, Null, Null, 10);
Plot(LPLV, "", colorBlue,styleStaircase|styleThick|styleDashed, Null, Null, 10);
 

amitrandive

Well-Known Member
#4
Thanks Amit for the reply. Still it looks value hardcoded right? I tried below code earlier and it extending to next 10 bars as I fixed. So now have to find out number of bars between previous and current pivot and need to extend accordingly. Please correct if I wrong. But don't know how to count that even I tried barssince

Code:
Plot(HPHV, "", colorBlue,styleStaircase|styleThick|styleDashed, Null, Null, 10);
Plot(LPLV, "", colorBlue,styleStaircase|styleThick|styleDashed, Null, Null, 10);
You can change lookback period in parameters
Code:
LB= Param("Look Back Periods",10,1,30,1);
 
#5
You can change lookback period in parameters
Code:
LB= Param("Look Back Periods",10,1,30,1);
Amit I am sorry. Really I don't understand.Hence, am attaching complete code here.Could you please help?
Code:
_SECTION_BEGIN("Analysis");
HPH = Ref(H,-3) < Ref(H,0) AND Ref(H,-2) < Ref(H,0) AND Ref(H,-1) < Ref(H,0) AND Ref(H,1) < Ref(H,0) AND Ref(H,2) < Ref(H,0) AND Ref(H,3) < Ref(H,0);
LPL = Ref(L,-3) > Ref(L,0) AND Ref(L,-2) > Ref(L,0) AND Ref(L,-1) > Ref(L,0) AND Ref(L,1) > Ref(L,0) AND Ref(L,2) > Ref(L,0) AND Ref(L,3) > Ref(L,0);
HPHV = ValueWhen(HPH,H,0);
LPLV = ValueWhen(LPL,L,0);
Plot(HPHV, "", colorBlue,styleStaircase|styleThick|styleDashed, Null, Null, 10);
Plot(LPLV, "", colorBlue,styleStaircase|styleThick|styleDashed, Null, Null, 10);
_SECTION_END();
 

amitrandive

Well-Known Member
#6
Amit I am sorry. Really I don't understand.Hence, am attaching complete code here.Could you please help?
Code:
_SECTION_BEGIN("Analysis");
HPH = Ref(H,-3) < Ref(H,0) AND Ref(H,-2) < Ref(H,0) AND Ref(H,-1) < Ref(H,0) AND Ref(H,1) < Ref(H,0) AND Ref(H,2) < Ref(H,0) AND Ref(H,3) < Ref(H,0);
LPL = Ref(L,-3) > Ref(L,0) AND Ref(L,-2) > Ref(L,0) AND Ref(L,-1) > Ref(L,0) AND Ref(L,1) > Ref(L,0) AND Ref(L,2) > Ref(L,0) AND Ref(L,3) > Ref(L,0);
HPHV = ValueWhen(HPH,H,0);
LPLV = ValueWhen(LPL,L,0);
Plot(HPHV, "", colorBlue,styleStaircase|styleThick|styleDashed, Null, Null, 10);
Plot(LPLV, "", colorBlue,styleStaircase|styleThick|styleDashed, Null, Null, 10);
_SECTION_END();
tradewell

I just gave you a simplified code , where you can change the parameters of the lookback period.
By the way there are a lot of such codes freely available on the net, if you just Google right for it.

No need to reinvent the wheel.
This is as far as my limited knowledge of AFL goes.
 
#8
Amit I am sorry. Really I don't understand.Hence, am attaching complete code here.Could you please help?
Code:
_SECTION_BEGIN("Analysis");
HPH = Ref(H,-3) < Ref(H,0) AND Ref(H,-2) < Ref(H,0) AND Ref(H,-1) < Ref(H,0) AND Ref(H,1) < Ref(H,0) AND Ref(H,2) < Ref(H,0) AND Ref(H,3) < Ref(H,0);
LPL = Ref(L,-3) > Ref(L,0) AND Ref(L,-2) > Ref(L,0) AND Ref(L,-1) > Ref(L,0) AND Ref(L,1) > Ref(L,0) AND Ref(L,2) > Ref(L,0) AND Ref(L,3) > Ref(L,0);
HPHV = ValueWhen(HPH,H,0);
LPLV = ValueWhen(LPL,L,0);
Plot(HPHV, "", colorBlue,styleStaircase|styleThick|styleDashed|[COLOR="Red"]styleSwingDots[/COLOR]);
Plot(LPLV, "", colorBlue,styleStaircase|styleThick|styleDashed|[COLOR="red"]styleSwingDots[/COLOR]);
_SECTION_END();
The issue has been resolved by adding one more style to the plot function Now someone could you please help to this hourly pivots to 5 minutes frame? thanks
 

Similar threads