My first attempt appear very unsuccessful. Here is my second attempt. I don't get any exploration probably because of the market conditions where it been down for a while. So I created a swing short. I can capture some swing shorts explorations, apparently not very successful to capture the consolidation and corrections stage. Hope someone can study and point out any of my mistakes.
Swing Long Formulation.
{Cond1. To Test for Pivot Bar which is the highest bar before pullback}
{Cond1:=H < Ref(H,-1) AND Ref(H,-1)>Ref(H,-2) AND Ref(H,-2)>Ref(H,-3);}
PBH:=If(cond1,Ref(H,-1),0);
PBL:=If(cond1,Ref(L,-1),0);
Cond2:=Cond1 AND L>PBH;{Test for if recent bar fall within the PB}
R:=PBH;{Resistance}
SP:=PBL;{Support}
Cond3:=Cond1 AND L < PBL;{Check for condition where the recent bar low fall outside PB low}
LLBH:=If(cond2,H,PBH);{LLB define the recent Lowest Bar}
LLBL:=If(Cond2,L,PBL);
2LBH:=If(cond2,PBH,PBH);{2LB define the 2nd lower bar count after LLB}
2LBL:=If(cond2,PBL,PBL);
SP:=If(LLBL<2LBL,LLBL,2LBL);{New support when condition are met}
R:=If(LLBH<2LBH,2LBH,LLBH);{New resistance when condition are met}
n:=BarsSince(cond1);
{To test recent bar after cond1 are met and not more than 7 bars away, the LLB and 2LB and to determine the new support and resistance}
Cond4:=n<7 AND H<r AND L<llbl;
LLBL:=If(cond4,L,LLBL);
2LBL:=If(cond4,LLBL,2LBL);
LLBH:=If(cond4,H,LLBH);
2LBH:=If(cond4,LLBH,2LBH);
Cond5:=n<7 AND H<r AND L<2LBL AND L>llbl;
2LBL:=If(cond5,L,2LBL);
2LBH:=If(cond5,H,2LBH);
SP:=If(LLBL<2LBL,LLBL,2LBL);{New support when condition are met}
R:=If(LLBH<2LBH,2LBH,LLBH);{New resistance when condition are met
{Cond1. To Test for Pivot Bar which is the lowest bar before pullback}
Cond1:=L>Ref(L,-1) AND Ref(L,-1)>Ref(L,-2) AND Ref(L,-2)>Ref(L,-3);
PBH:=If(cond1,Ref(H,-1),0);
PBL:=If(cond1,Ref(L,-1),0);
Cond2:=Cond1 AND H<PBH;{Test for if recent bar rises but still within the PB}
R:=PBH;{Resistance}
SP:=PBL;{Support}
Cond3:=Cond1 AND H>PBH;{Check for condition where the recent bar high fall outside PB high}
HHBH:=If(cond3,H,PBH);{HHB define the recent Highest Bar}
HHBL:=If(Cond3,L,PBL);
2HBH:=If(cond3,PBH,PBH);{HB define the 2nd higher bar count after HHB}
2HBL:=If(cond3,PBL,PBL);
SP:=If(HHBL>2HBL,HHBL,2HBL);{New support when condition are met}
R:=If(HHBH>2HBH,HHBH,2HBH);{New resistance when condition are met}
n:=BarsSince(cond1);
{To test recent bar after cond1 are met and not more than 7 bars away, the HHB and 2HB and to determine the new support and resistance}
Cond4:=n<7 AND L<s AND h>HHbh;
2HBL:=If(cond4,HHBL,2HBL);
2HBH:=If(cond4,HHBH,2HBH);
HHBL:=If(cond4,L,HHBL);
HHBH:=If(cond4,H,HHBH);
Cond5:=n<7 AND L<s AND H>2HBH AND H<HHbH;
2HBL:=If(cond5,L,2HBL);
2HBH:=If(cond5,H,2HBH);
SP:=If(HHBL<2HBL,HHBL,2HBL);{New support when condition are met}
R:=If(HHBH<2HBH,2HBH,HHBH);{New resistance when condition are met}
cond4 OR cond5