Declare Lower;
# GLOBAL DEFINITIONS
DefineGlobalColor("InsideBarUp", Color.GRAY);
DefineGlobalColor("InsideBarFLAT", Color.Light_GRAY);
DefineGlobalColor("InsideBarDown", Color.DARK_GRAY);
DefineGlobalColor("twoUpClUp", Color.Green);
DefineGlobalColor("twoUpFLAT", Color.Light_Green);
DefineGlobalColor("twoUpClDn", Color.DarK_Green);
DefineGlobalColor("twoDnClUp", Color.Red);
DefineGlobalColor("twoDnFLAT", Color.Light_RED);
DefineGlobalColor("twoDnClDn", Color.Dark_Red);
DefineGlobalColor("OutsideBarUp", Color.Yellow);
DefineGlobalColor("OUTSIDEBARFLAT", Color.ORANGE);
DefineGlobalColor("OutsideBarDown", Color.Dark_Orange);
#Inputs
input agg = AggregationPeriod.FIVE_MIN;
input agg2 = AggregationPeriod.THIRTY_MIN;
input agg3 = AggregationPeriod.HOUR;
input agg4 = AggregationPeriod.TWO_Hours;
input agg5 = AggregationPeriod.FOUR_HOURs;
input agg6 = AggregationPeriod.Day;
Input Dotsize = 3;
Input APC = 1;
input Show_Legend = yes;
AddLabel(if Show_Legend then yes else no, "Color Coding: ", Color.LIGHT_GRAY);
AddLabel(if Show_Legend then yes else no, “Inside Bar Up”, GlobalColor("InsideBarUp”));
AddLabel(if Show_Legend then yes else no, “Inside Bar Flat”, GlobalColor("InsideBarFlat”));
AddLabel(if Show_Legend then yes else no, “Inside Bar Dn”, GlobalColor("InsideBarDown”));
AddLabel(if Show_Legend then yes else no, “Outside Bar Up”, GlobalColor("OutsideBarUp”));
AddLabel(if Show_Legend then yes else no, “Outside Bar Flat”, GlobalColor("OutsideBarFlat”));
AddLabel(if Show_Legend then yes else no, “OutSide Bar Dn”, GlobalColor("OutSideBarDown”));
AddLabel(if Show_Legend then yes else no, “twoUpClUp”, GlobalColor("twoUpClUp”));
AddLabel(if Show_Legend then yes else no, “twoUpFlat”, GlobalColor("twoUpFlat”));
AddLabel(if Show_Legend then yes else no, “twoUpClDn”, GlobalColor("twoUpClDn”));
AddLabel(if Show_Legend then yes else no, “twoDnClUp”, GlobalColor("twoDnClUp”));
AddLabel(if Show_Legend then yes else no, “twoDnFlat”, GlobalColor("twoDnFlat”));
AddLabel(if Show_Legend then yes else no, “twoDnClDn”, GlobalColor("twoDnClDn”));
AddLabel(if Show_Legend then yes else no, “Reversal Up”, Color.CYAN);
AddLabel(if Show_Legend then yes else no, “Reversal Down”, Color.MAGENTA);
def o = Open(Period = AGG);
def C = Close(Period =AGG);
def H = High(Period = AGG);
def L = Low(Period =AGG);
def o2 = Open(Period = AGG2);
def C2 = Close(Period =AGG2);
def H2 = High(Period = AGG2);
def L2 = Low(Period =AGG2);
def o3 = Open(Period = AGG3);
def C3 = Close(Period =AGG3);
def H3 = High(Period = AGG3);
def L3 = Low(Period =AGG3);
def o4 = Open(Period = AGG4);
def C4 = Close(Period =AGG4);
def H4 = Open(Period = AGG4);
def L4 = Close(Period =AGG4);
def O5 = Open(Period = AGG5);
def C5 = Close(Period =AGG5);
def H5 = High(Period = AGG5);
def L5 = Low(Period =AGG5);
def O6 = Open(Period = AGG6);
def C6 = Close(Period =AGG6);
def H6 = Open(Period = AGG6);
def L6 = Close(Period =AGG6);
#Aggregation1
def insidebar = (H < H[1] and L > L[1]) or (H == H[1] and L > L[1]) or (H < H[1] and L == L[1]) or (H == H[1] and L == L[1]);
def outsidebar = H > H[1] and L < L[1];
def InsidebarFlat = insidebar and O == C;
def OutsidebarFlat = Outsidebar and O == C;
def insidebarup = insidebar and O < C;
def twoup = H > H[1] and L >= L[1];
def twoupFlat = twoup and O == C;
def twoupClUp = H > H[1] and L >= L[1] and O < C;
def twoupClDn = H > H[1] and L >= L[1] and O > C;
def outsidebarup = outsidebar and O < C;
def insidebardown = insidebar and O > C;
def twodown = H <= H[1] and L < L[1];
def twodownFlat = twodown and O == C;
def twodownCLDn = H <= H[1] and L < L[1] and O > C;
def twodownCLUp = H <= H[1] and L < L[1] and O <C;
def outsidebardown = outsidebar and O > C;
def pivot_high = H >= Highest(H[1], 6) and H > Highest(H[-2], 2);
def pivot_low = L <= Lowest(L[1], 6) and L < Lowest(L[-2], 2);
def Double_ones = InsideBar[1] and Insidebar;
def Double_TwoUp = twoUp[1] and twoup;
def Double_TwoDn = twoDown[1] and twoDown;
#------------------------------------
# DEFINE REVERSALS (Basic four plus RevStrat)
#------------------------------------
# Bullish
def TwoOneTwoBull = twoup and insidebar[1] and twodown[2];
def TwoTwoBull = twoup and twodown[1];
def ThreeBull = outsidebarup and (twodown[1] or insidebar[1] or outsidebardown[1]);
def ThreeOneTwoBull = twoup and insidebar[1] and outsidebardown[2] and pivot_low[2];
def RevStratBull = (twoup and twodown[1] and insidebar[2]) or (outsidebarup and insidebar[1]);
def BullRev = TwoOneTwoBull or TwoTwoBull or ThreeBull or ThreeOneTwoBull or RevStratBull;
# Bearish
def TwoOneTwoBear = twodown and insidebar[1] and twoup[2];
def TwoTwoBear = twodown and twoup[1];
def ThreeBear = outsidebardown and (twoup[1] or insidebar[1] or outsidebarup[1]);
def ThreeOneTwoBear = twodown and insidebar[1] and outsidebarup[2] and pivot_high[2];
def RevStratBear = (twodown and twoup[1] and insidebar[2]) or (outsidebardown and insidebar[1]);
def BearRev = TwoOneTwoBear or TwoTwoBear or ThreeBear or ThreeOneTwoBear or RevStratBear;
#Aggregation 2
def Binsidebar = (H2 < H2[1] and L2 > L2[1]) or (H2 == H2[1] and L2 > L2[1]) or (H2 < H2[1] and L2 == L2[1]) or (H2 == H2[1] and L2 == L2[1]);
def Boutsidebar = H2 > H2[1] and L2 < L2[1];
def Binsidebarup = Binsidebar and O2 < C2;
def Btwoup = H2 > H2[1] and L2 >= L2[1];
def BtwoupClUp = H2 > H2[1] and L2 >= L2[1] and O2 < C2;
def BtwoupClDn = H2 > H2[1] and L2 >= L2[1] and O2 > C2;
def Boutsidebarup = Boutsidebar and O2 < C2;
def Binsidebardown = Binsidebar and O2 > C2;
def Btwodown = H2 <= H2[1] and L2 < L2[1];
def BtwodownCLDn = H2 <= H2[1] and L2 < L2[1] and O2 > C2;
def BtwodownCLUp = H2 <= H2[1] and L2 < L2[1] and O2 <C2;
def Boutsidebardown = Boutsidebar and O2 > C2;
def BInsidebarFlat = Binsidebar and O2 == C2;
def BOutsidebarFlat = BOutsidebar and O2 == C2;
def BtwoupFlat = Btwoup and O2 == C2;
def BtwodownFlat = Btwodown and O2 == C2;
def Bpivot_high = H2 >= Highest(H2[1], 6) and H2 > Highest(H2[-2], 2);
def Bpivot_low = L2 <= Lowest(L2[1], 6) and L2 < Lowest(L2[-2], 2);
Def BDouble_ones = BInsideBar[1] and BInsidebar;
def BDouble_TwoUp = BtwoUp[1] and Btwoup;
def BDouble_TwoDn = BtwoDown[1] and BtwoDown;
# Bullish
def BTwoOneTwoBull = Btwoup and Binsidebar[1] and Btwodown[2];
def BTwoTwoBull = Btwoup and Btwodown[1];
def BThreeBull = Boutsidebarup and (Btwodown[1] or Binsidebar[1] or Boutsidebardown[1]);
def BThreeOneTwoBull = Btwoup and Binsidebar[1] and Boutsidebardown[2] and Bpivot_low[2];
def BRevStratBull = (Btwoup and Btwodown[1] and Binsidebar[2]) or (Boutsidebarup and Binsidebar[1]);
def BBullRev = BTwoOneTwoBull or BTwoTwoBull or BThreeBull or BThreeOneTwoBull or BRevStratBull;
# Bearish
def BTwoOneTwoBear = Btwodown and Binsidebar[1] and Btwoup[2];
def BTwoTwoBear = Btwodown and Btwoup[1];
def BThreeBear = Boutsidebardown and (Btwoup[1] or Binsidebar[1] or Boutsidebarup[1]);
def BThreeOneTwoBear = Btwodown and Binsidebar[1] and Boutsidebarup[2] and Bpivot_high[2];
def BRevStratBear = (Btwodown and Btwoup[1] and Binsidebar[2]) or (Boutsidebardown and Binsidebar[1]);
def BBearRev = BTwoOneTwoBear or BTwoTwoBear or BThreeBear or BThreeOneTwoBear or BRevStratBear;
#Aggregation 3
def Cinsidebar = (H3 < H3[1] and L3 > L3[1]) or (H3 == H3[1] and L3 > L3[1]) or (H3 < H3[1] and L3 == L3[1]) or (H3 == H3[1] and L3 == L3[1]);
def Coutsidebar = H3 > H3[1] and L3 < L3[1];
def Cinsidebarup = Cinsidebar and O3 < C3;
def Ctwoup = H3 > H3[1] and L3 >= L3[1];
def CtwoupClUp = H3 > H3[1] and L3 >= L3[1] and O3 < C3;
def CtwoupClDn = H3 > H3[1] and L3 >= L3[1] and O3 > C3;
def Coutsidebarup = Coutsidebar and O3 < C3;
def Cinsidebardown = Cinsidebar and O3 > C3;
def Ctwodown = H3 <= H3[1] and L3 < L3[1];
def CtwodownCLDn = H3 <= H3[1] and L3 < L3[1] and O3 > C3;
def CtwodownCLUp = H3 <= H3[1] and L3 < L3[1] and O3 <C3;
def Coutsidebardown = Coutsidebar and O3 > C3;
def CInsidebarFlat = Cinsidebar and O3 == C3;
def COutsidebarFlat = COutsidebar and O3 == C3;
def CtwoupFlat = Ctwoup and O3 == C3;
def CtwodownFlat = Ctwodown and O3 == C3;
def Cpivot_high = H3 >= Highest(H3[1], 6) and H3 > Highest(H3[-2], 2);
def Cpivot_low = L3 <= Lowest(L3[1], 6) and L3 < Lowest(L3[-2], 2);
def CDouble_ones = CInsideBar[1] and CInsidebar;
def CDouble_TwoUp = CtwoUp[1] and Ctwoup;
def CDouble_TwoDn = CtwoDown[1] and CtwoDown;
# Bullish
def CTwoOneTwoBull = Ctwoup and Cinsidebar[1] and Ctwodown[2];
def CTwoTwoBull = Ctwoup and Ctwodown[1];
def CThreeBull = Coutsidebarup and (Ctwodown[1] or Cinsidebar[1] or Coutsidebardown[1]);
def CThreeOneTwoBull = Ctwoup and Cinsidebar[1] and Coutsidebardown[2] and Cpivot_low[2];
def CRevStratBull = (Ctwoup and Ctwodown[1] and Cinsidebar[2]) or (Coutsidebarup and Cinsidebar[1]);
def CBullRev = CTwoOneTwoBull or CTwoTwoBull or CThreeBull or CThreeOneTwoBull or CRevStratBull;
# Bearish
def CTwoOneTwoBear = Ctwodown and Cinsidebar[1] and Ctwoup[2];
def CTwoTwoBear = Ctwodown and Ctwoup[1];
def CThreeBear = Coutsidebardown and (Ctwoup[1] or Cinsidebar[1] or Coutsidebarup[1]);
def CThreeOneTwoBear = Ctwodown and Cinsidebar[1] and Coutsidebarup[2] and Cpivot_high[2];
def CRevStratBear = (Ctwodown and Ctwoup[1] and Cinsidebar[2]) or (Coutsidebardown and Cinsidebar[1]);
def CBearRev = CTwoOneTwoBear or CTwoTwoBear or CThreeBear or CThreeOneTwoBear or CRevStratBear;
#Aggregation 4
def Dinsidebar = (H4 < H4[1] and L4 > L4[1]) or (H4 == H4[1] and L4 > L4[1]) or (H4 < H4[1] and L4 == L4[1]) or (H4 == H4[1] and L4 == L4[1]);
def Doutsidebar = H4 > H4[1] and L4 < L4[1];
def Dinsidebarup = Dinsidebar and O4 < C4;
def Dtwoup = H4 > H4[1] and L4 >= L4[1];
def DtwoupClUp = H4 > H4[1] and L4 >= L4[1] and O4 < C4;
def DtwoupClDn = H4 > H4[1] and L4 >= L4[1] and O4 > C4;
def Doutsidebarup = Doutsidebar and O4 < C4;
def Dinsidebardown = Dinsidebar and O4 > C4;
def Dtwodown = H4 <= H4[1] and L4 < L4[1];
def DtwodownCLDn = H4 <= H4[1] and L4 < L4[1] and O4 > C4;
def DtwodownCLUp = H4 <= H4[1] and L4 < L4[1] and O4 < C4;
def Doutsidebardown = Doutsidebar and O4 > C4;
def DInsidebarFlat = Dinsidebar and O4 == C4;
def DOutsidebarFlat = DOutsidebar and O4 == C4;
def DtwoupFlat = Dtwoup and O4 == C4;
def DtwodownFlat = Dtwodown and O4 == C4;
def Dpivot_high = H4 >= Highest(H4[1], 6) and H4 > Highest(H4[-2], 2);
def Dpivot_low = L4 <= Lowest(L4[1], 6) and L4 < Lowest(L4[-2], 2);
def DDouble_ones = DInsideBar[1] and DInsidebar;
def DDouble_TwoUp = DtwoUp[1] and Dtwoup;
def DDouble_TwoDn = DtwoDown[1] and DtwoDown;
# Bullish
def DTwoOneTwoBull = Dtwoup and Dinsidebar[1] and Dtwodown[2];
def DTwoTwoBull = Dtwoup and Dtwodown[1];
def DThreeBull = Doutsidebarup and (Dtwodown[1] or Dinsidebar[1] or Doutsidebardown[1]);
def DThreeOneTwoBull = Dtwoup and Dinsidebar[1] and Doutsidebardown[2] and Dpivot_low[2];
def DRevStratBull = (Dtwoup and Dtwodown[1] and Dinsidebar[2]) or (Doutsidebarup and Dinsidebar[1]);
def DBullRev = DTwoOneTwoBull or DTwoTwoBull or DThreeBull or DThreeOneTwoBull or DRevStratBull;
# Bearish
def DTwoOneTwoBear = Dtwodown and Dinsidebar[1] and Dtwoup[2];
def DTwoTwoBear = Dtwodown and Dtwoup[1];
def DThreeBear = Doutsidebardown and (Dtwoup[1] or Dinsidebar[1] or Doutsidebarup[1]);
def DThreeOneTwoBear = Dtwodown and Dinsidebar[1] and Doutsidebarup[2] and Dpivot_high[2];
def DRevStratBear = (Dtwodown and Dtwoup[1] and Dinsidebar[2]) or (Doutsidebardown and Dinsidebar[1]);
def DBearRev = DTwoOneTwoBear or DTwoTwoBear or DThreeBear or DThreeOneTwoBear or DRevStratBear;
#Aggregation 5
def Einsidebar = (H5 < H5[1] and L5 > L5[1]) or (H5 == H5[1] and L5 > L5[1]) or (H5 < H5[1] and L5 == L5[1]) or (H5 == H5[1] and L5 == L5[1]);
def Eoutsidebar = H5 > H5[1] and L5 < L5[1];
def Einsidebarup = Einsidebar and O5 < C5;
def Etwoup = H5 > H5[1] and L5 >= L5[1];
def EtwoupClUp = H5 > H5[1] and L5 >= L5[1] and O5 < C5;
def EtwoupClDn = H5 > H5[1] and L5 >= L5[1] and O5 > C5;
def Eoutsidebarup = Eoutsidebar and O5 < C5;
def Einsidebardown = Einsidebar and O5 > C5;
def Etwodown = H5 <= H5[1] and L5 < L5[1];
def EtwodownCLDn = H5 <= H5[1] and L5 < L5[1] and O5 > C5;
def EtwodownCLUp = H5 <= H5[1] and L5 < L5[1] and O5 <C5;
def Eoutsidebardown = Eoutsidebar and O5 > C5;
def EInsidebarFlat = Einsidebar and O5 == C5;
def EOutsidebarFlat = EOutsidebar and O5 == C5;
def EtwoupFlat = Etwoup and O5 == C5;
def EtwodownFlat = Etwodown and O5 == C5;
def Epivot_high = H5 >= Highest(H5[1], 6) and H5 > Highest(H5[-2], 2);
def Epivot_low = L5 <= Lowest(L5[1], 6) and L5 < Lowest(L5[-2], 2);
def EDouble_ones = EInsideBar[1] and EInsidebar;
def EDouble_TwoUp = EtwoUp[1] and Etwoup;
def EDouble_TwoDn = EtwoDown[1] and EtwoDown;
# Bullish
def ETwoOneTwoBull = Etwoup and Einsidebar[1] and Etwodown[2];
def ETwoTwoBull = Etwoup and Etwodown[1];
def EThreeBull = Eoutsidebarup and (Etwodown[1] or Einsidebar[1] or Eoutsidebardown[1]);
def EThreeOneTwoBull = Etwoup and Einsidebar[1] and Eoutsidebardown[2] and Epivot_low[2];
def ERevStratBull = (Etwoup and Etwodown[1] and Einsidebar[2]) or (Eoutsidebarup and Einsidebar[1]);
def EBullRev = ETwoOneTwoBull or ETwoTwoBull or EThreeBull or EThreeOneTwoBull or ERevStratBull;
# Bearish
def ETwoOneTwoBear = Etwodown and Einsidebar[1] and Etwoup[2];
def ETwoTwoBear = Etwodown and Etwoup[1];
def EThreeBear = Eoutsidebardown and (Etwoup[1] or Einsidebar[1] or Eoutsidebarup[1]);
def EThreeOneTwoBear = Etwodown and Einsidebar[1] and Eoutsidebarup[2] and Epivot_high[2];
def ERevStratBear = (Etwodown and Etwoup[1] and Einsidebar[2]) or (Eoutsidebardown and Einsidebar[1]);
def EBearRev = ETwoOneTwoBear or ETwoTwoBear or EThreeBear or EThreeOneTwoBear or ERevStratBear;
#Aggregation 6
def finsidebar = (H6 < H6[1] and L6 > L6[1]) or (H6 == H6[1] and L6 > L6[1]) or (H6 < H6[1] and L6 == L6[1]) or (H6 == H6[1] and L6 == L6[1]);
def foutsidebar = H6 > H6[1] and L6 < L6[1];
def finsidebarup = finsidebar and O6 < C6;
def ftwoup = H6 > H6[1] and L6 >= L6[1];
def ftwoupClUp = H6 > H6[1] and L6 >= L6[1] and O6 < C6;
def ftwoupClDn = H6 > H6[1] and L6 >= L6[1] and O6 > C6;
def foutsidebarup = foutsidebar and O6 < C6;
def finsidebardown = finsidebar and O6 > C6;
def ftwodown = H6 <= H6[1] and L6 < L6[1];
def ftwodownCLDn = H6 <= H6[1] and L6 < L6[1] and O6 > C6;
def ftwodownCLUp = H6 <= H6[1] and L6 < L6[1] and O6 <C6;
def foutsidebardown = foutsidebar and O6 > C6;
def FInsidebarFlat = Finsidebar and O6 == C6;
def FOutsidebarFlat = FOutsidebar and O6 == C6;
def FtwoupFlat = Ftwoup and O6 == C6;
def FtwodownFlat = Ftwodown and O6 == C6;
def fpivot_high = H6 >= Highest(H6[1], 6) and H6 > Highest(H6[-2], 2);
def fpivot_low = L6 <= Lowest(L6[1], 6) and L6 < Lowest(L6[-2], 2);
def FDouble_ones = FInsideBar[1] and FInsidebar;
def FDouble_TwoUp = FtwoUp[1] and Ftwoup;
def FDouble_TwoDn = FtwoDown[1] and FtwoDown;
# Bullish
def FTwoOneTwoBull = Ftwoup and Finsidebar[1] and Ftwodown[2];
def FTwoTwoBull = Ftwoup and Ftwodown[1];
def FThreeBull = Foutsidebarup and (Ftwodown[1] or Finsidebar[1] or Foutsidebardown[1]);
def FThreeOneTwoBull = Ftwoup and Finsidebar[1] and Foutsidebardown[2] and Fpivot_low[2];
def FRevStratBull = (Ftwoup and Ftwodown[1] and Finsidebar[2]) or (Foutsidebarup and Finsidebar[1]);
def FBullRev = FTwoOneTwoBull or FTwoTwoBull or FThreeBull or FThreeOneTwoBull or FRevStratBull;
# Bearish
def FTwoOneTwoBear = Ftwodown and Finsidebar[1] and Ftwoup[2];
def FTwoTwoBear = Ftwodown and Ftwoup[1];
def FThreeBear = Foutsidebardown and (Ftwoup[1] or Finsidebar[1] or Foutsidebarup[1]);
def FThreeOneTwoBear = Ftwodown and Finsidebar[1] and Foutsidebarup[2] and Fpivot_high[2];
def FRevStratBear = (Ftwodown and Ftwoup[1] and Finsidebar[2]) or (Foutsidebardown and Finsidebar[1]);
def FBearRev = FTwoOneTwoBear or FTwoTwoBear or FThreeBear or FThreeOneTwoBear or FRevStratBear;
#BarTypes
Def BarType = If InsideBarUp then 1.1 else If InsideBarFlat then 1 else If InsideBarDown then -1 else If OutsideBarUp then 3.1 else If OutsideBarFlat then 3 else If OutsideBarDown then -3 else If twoUpClDn then 2 else If twoUpFlat then 2.1 else If twoUpClUp then 2.2 else If twoDownCLUp then -2 else If twoDownFlat then -2.1 else if twoDownCLDn then -2.2 else Double.NaN;
Def BBarType = If BInsideBarUp then 1.1 else If BInsideBarFlat then 1 else If BInsideBarDown then -1 else If BOutsideBarUp then 3.1 else If BOutsideBarFlat then 3 else If BOutsideBarDown then -3 else If BtwoUpClDn then 2 else If BtwoUpFlat then 2.1 else If BtwoUpClUp then 2.2 else If BtwoDownCLUp then -2 else If BtwoDownFlat then -2.1 else if BtwoDownCLDn then -2.2 else Double.NaN;
Def CBarType = If CInsideBarUp then 1.1 else If CInsideBarFlat then 1 else If CInsideBarDown then -1 else If COutsideBarUp then 3.1 else If COutsideBarFlat then 3 else If COutsideBarDown then -3 else If CtwoUpClDn then 2 else If CtwoUpFlat then 2.1 else If CtwoUpClUp then 2.2 else If CtwoDownCLUp then -2 else If CtwoDownFlat then -2.1 else if CtwoDownCLDn then -2.2 else Double.NaN;
Def DBarType = If DInsideBarUp then 1.1 else If DInsideBarFlat then 1 else If DInsideBarDown then -1 else If DOutsideBarUp then 3.1 else If DOutsideBarFlat then 3 else If DOutsideBarDown then -3 else If DtwoUpClDn then 2 else If DtwoUpFlat then 2.1 else If DtwoUpClUp then 2.2 else If DtwoDownCLUp then -2 else If DtwoDownFlat then -2.1 else if DtwoDownCLDn then -2.2 else Double.NaN;
Def EBarType = If EInsideBarUp then 1.1 else If EInsideBarFlat then 1 else If EInsideBarDown then -1 else If EOutsideBarUp then 3.1 else If EOutsideBarFlat then 3 else If EOutsideBarDown then -3 else If EtwoUpClDn then 2 else If EtwoUpFlat then 2.1 else If EtwoUpClUp then 2.2 else If EtwoDownCLUp then -2 else If EtwoDownFlat then -2.1 else if EtwoDownCLDn then -2.2 else Double.NaN;
Def FBarType = If FInsideBarUp then 1.1 else If FInsideBarFlat then 1 else If FInsideBarDown then -1 else If FOutsideBarUp then 3.1 else If FOutsideBarFlat then 3 else If FOutsideBarDown then -3 else If FtwoUpClDn then 2 else If FtwoUpFlat then 2.1 else If FtwoUpClUp then 2.2 else If FtwoDownCLUp then -2 else If FtwoDownFlat then -2.1 else if FtwoDownCLDn then -2.2 else Double.NaN;
#Plots
plot Strat1_Dot = if IsNaN(C) then Double.NaN else 1;
Strat1_Dot.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
Strat1_Dot.SetLineWeight(DotSize);
Strat1_Dot.AssignValueColor(if BarType == 1.1 then Color.Gray else if BarType == 1 then Color.Light_Gray else if BarType == -1 then Color.Dark_Gray else if BarType == 2.2 then Color.Green else if BarType == 2.1 then Color.Light_Green else if BarType == 2 then Color.Dark_Green else if BarType == -2 then Color.Red else if BarType == -2.1 then Color.Light_Red else if BarType == -2.2 then Color.Dark_Red else if BarType == 3.1 then Color.Yellow else if BarType == -3 then Color.Dark_Orange else if BarType == 3 then Color.Orange else Color.Black);
plot Strat2_Dot = if IsNaN(C) then Double.NaN else 2;
Strat2_Dot.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
Strat2_Dot.SetLineWeight(DotSize);
Strat2_Dot.AssignValueColor(if BBarType == 1.1 then Color.Gray else if BBarType == 1 then Color.Light_Gray else if BBarType == -1 then Color.Dark_Gray else if BBarType == 2.2 then Color.Green else if BBarType == 2.1 then Color.Light_Green else if BBarType == 2 then Color.Dark_Green else if BBarType == -2 then Color.Red else if BBarType == -2.1 then Color.Light_Red else if BBarType == -2.2 then Color.Dark_Red else if BBarType == 3.1 then Color.Yellow else if BBarType == -3 then Color.Dark_Orange else if BBarType == 3 then Color.Orange else Color.Black);
plot Strat3_Dot = if IsNaN(C) then Double.NaN else 3;
Strat3_Dot.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
Strat3_Dot.SetLineWeight(DotSize);
Strat3_Dot.AssignValueColor(if CBarType == 1.1 then Color.Gray else if CBarType == 1 then Color.Light_Gray else if CBarType == -1 then Color.Dark_Gray else if CBarType == 2.2 then Color.Green else if CBarType == 2.1 then Color.Light_Green else if CBarType == 2 then Color.Dark_Green else if CBarType == -2 then Color.Red else if CBarType == -2.1 then Color.Light_Red else if CBarType == -2.2 then Color.Dark_Red else if CBarType == 3.1 then Color.Yellow else if CBarType == -3 then Color.Dark_Orange else if CBarType == 3 then Color.Orange else Color.Black);
plot Strat4_Dot = if IsNaN(C) then Double.NaN else 4;
Strat4_Dot.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
Strat4_Dot.SetLineWeight(DotSize);
Strat4_Dot.AssignValueColor(if DBarType == 1.1 then Color.Gray else if DBarType == 1 then Color.Light_Gray else if DBarType == -1 then Color.Dark_Gray else if DBarType == 2.2 then Color.Green else if DBarType == 2.1 then Color.Light_Green else if DBarType == 2 then Color.Dark_Green else if DBarType == -2 then Color.Red else if DBarType == -2.1 then Color.Light_Red else if DBarType == -2.2 then Color.Dark_Red else if DBarType == 3.1 then Color.Yellow else if DBarType == -3 then Color.Dark_Orange else if DBarType == 3 then Color.Orange else Color.Black);
plot Strat5_Dot = if IsNaN(C) then Double.NaN else 5;
Strat5_Dot.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
Strat5_Dot.SetLineWeight(DotSize);
Strat5_Dot.AssignValueColor(if EBarType == 1.1 then Color.Gray else if EBarType == 1 then Color.Light_Gray else if EBarType == -1 then Color.Dark_Gray else if EBarType == 2.2 then Color.Green else if EBarType == 2.1 then Color.Light_Green else if EBarType == 2 then Color.Dark_Green else if EBarType == -2 then Color.Red else if EBarType == -2.1 then Color.Light_Red else if EBarType == -2.2 then Color.Dark_Red else if EBarType == 3.1 then Color.Yellow else if EBarType == -3 then Color.Dark_Orange else if EBarType == 3 then Color.Orange else Color.Black);
plot Strat6_Dot = if IsNaN(C) then Double.NaN else 6;
Strat6_Dot.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
Strat6_Dot.SetLineWeight(DotSize);
Strat6_Dot.AssignValueColor(if FBarType == 1.1 then Color.Gray else if FBarType == 1 then Color.Light_Gray else if FBarType == -1 then Color.Dark_Gray else if FBarType == 2.2 then Color.Green else if FBarType == 2.1 then Color.Light_Green else if FBarType == 2 then Color.Dark_Green else if FBarType == -2 then Color.Red else if FBarType == -2.1 then Color.Light_Red else if FBarType == -2.2 then Color.Dark_Red else if FBarType == 3.1 then Color.Yellow else if FBarType == -3 then Color.Dark_Orange else if FBarType == 3 then Color.Orange else Color.Black);
plot ASignal_Dot = if IsNaN(C) then Double.NaN else 8;
ASignal_Dot.SetPaintingStrategy(PaintingStrategy.Squares);
ASignal_Dot.SetLineWeight(DotSize);
ASignal_Dot.AssignValueColor(if BullRev then Color.CYAN else if BearRev then Color.MAGENTA else if Double_Ones then Color.Light_Green else if Double_twoup then Color.green else if Double_twoDn then Color.Dark_Red else Color.Black);
plot BSignal_Dot = if IsNaN(C) then Double.NaN else 9;
BSignal_Dot.SetPaintingStrategy(PaintingStrategy.Squares);
BSignal_Dot.SetLineWeight(DotSize);
BSignal_Dot.AssignValueColor(if BBullRev then Color.CYAN else if BBearRev then Color.MAGENTA else if BDouble_Ones then Color.Light_Green else if BDouble_twoup then Color.green else if BDouble_twoDn then Color.Dark_Red else Color.Black);
plot CSignal_Dot = if IsNaN(C) then Double.NaN else 10;
CSignal_Dot.SetPaintingStrategy(PaintingStrategy.Squares);
CSignal_Dot.SetLineWeight(DotSize);
CSignal_Dot.AssignValueColor(if CBullRev then Color.CYAN else if CBearRev then Color.MAGENTA else if CDouble_Ones then Color.Light_Green else if CDouble_twoup then Color.green else if CDouble_twoDn then Color.Dark_Red else Color.Black);
plot DSignal_Dot = if IsNaN(C) then Double.NaN else 11;
DSignal_Dot.SetPaintingStrategy(PaintingStrategy.Squares);
DSignal_Dot.SetLineWeight(DotSize);
DSignal_Dot.AssignValueColor(if DBullRev then Color.CYAN else if DBearRev then Color.MAGENTA else if DDouble_Ones then Color.Light_Green else if DDouble_twoup then Color.green else if DDouble_twoDn then Color.Dark_Red else Color.Black);
plot ESignal_Dot = if IsNaN(C) then Double.NaN else 12;
ESignal_Dot.SetPaintingStrategy(PaintingStrategy.Squares);
ESignal_Dot.SetLineWeight(DotSize);
ESignal_Dot.AssignValueColor(if EBullRev then Color.CYAN else if EBearRev then Color.MAGENTA else if EDouble_Ones then Color.Light_Green else if EDouble_twoup then Color.green else if EDouble_twoDn then Color.Dark_Red else Color.Black);
plot FSignal_Dot = if IsNaN(C) then Double.NaN else 13;
FSignal_Dot.SetPaintingStrategy(PaintingStrategy.Squares);
FSignal_Dot.SetLineWeight(DotSize);
FSignal_Dot.AssignValueColor(if FBullRev then Color.CYAN else if FBearRev then Color.MAGENTA else if FDouble_Ones then Color.Light_Green else if FDouble_twoup then Color.green else if FDouble_twoDn then Color.Dark_Red else Color.Black);
AssignPriceColor(if APC == 1 and BarType == 1.1 then Color.Gray else if APC == 1 and BarType == 1 then Color.Light_Gray else if APC == 1 and BarType == -1 then Color.Dark_Gray else if APC == 1 and BarType == 2.2 then Color.Green else if APC == 1 and BarType == 2.1 then Color.Light_Green else if APC == 1 and BarType == 2 then Color.Dark_Green else if APC == 1 and BarType == -2 then Color.Red else if APC == 1 and BarType == -2.1 then Color.Light_Red else if APC == 1 and BarType == -2.2 then Color.Dark_Red else if APC == 1 and BarType == 3.1 then Color.Yellow else if APC == 1 and BarType == -3 then Color.Orange else if APC == 1 and BarType == 3 then Color.Dark_Orange else
if APC == 2 and BBarType == 1.1 then Color.Gray else if APC == 2 and BBarType == 1 then Color.Light_Gray else if APC == 2 and BBarType == -1 then Color.Dark_Gray else if APC == 2 and BBarType == 2.2 then Color.Green else if APC == 2 and BBarType == 2.1 then Color.Light_Green else if APC == 2 and BBarType == 2 then Color.Dark_Green else if APC == 2 and BBarType == -2 then Color.Red else if APC == 2 and BBarType == -2.1 then Color.Light_Red else if APC == 2 and BBarType == -2.2 then Color.Dark_Red else if APC == 2 and BBarType == 3.1 then Color.Yellow else if APC == 2 and BBarType == -3 then Color.Dark_Orange else if APC == 2 and BBarType == 3 then Color.Orange else
if APC == 3 and CBarType == 1.1 then Color.Gray else if APC == 3 and CBarType == 1 then Color.Light_Gray else if APC == 3 and CBarType == -1 then Color.dark_Gray else if APC == 3 and CBarType == 2.2 then Color.Green else if APC == 3 and CBarType == 2.1 then Color.Light_Green else if APC == 3 and CBarType == 2 then Color.Dark_Green else if APC == 3 and CBarType == -2 then Color.Red else if APC == 3 and CBarType == -2.1 then Color.Light_Red else if APC == 3 and CBarType == -2.2 then Color.Dark_Red else if APC == 3 and CBarType == 3.1 then Color.Yellow else if APC == 3 and CBarType == -3 then Color.Dark_Orange else if APC == 3 and CBarType == 3 then Color.Orange else
if APC == 4 and DBarType == 1.1 then Color.Gray else if APC == 4 and DBarType == 1 then Color.Light_Gray else if APC == 4 and DBarType == -1 then Color.Dark_Gray else if APC == 4 and DBarType == 2.2 then Color.Green else if APC == 4 and DBarType == 2.1 then Color.Light_Green else if APC == 4 and DBarType == 2 then Color.Dark_Green else if APC == 4 and DBarType == -2 then Color.Red else if APC == 4 and DBarType == -2.1 then Color.Light_Red else if APC == 4 and DBarType == -2.2 then Color.Dark_Red else if APC == 4 and DBarType == 3.1 then Color.Yellow else if APC == 4 and DBarType == -3 then Color.Dark_Orange else if APC == 4 and DBarType == 3 then Color.Orange else
if APC == 5 and EBarType == 1.1 then Color.Gray else if APC == 5 and EBarType == 1 then Color.Light_Gray else if APC == 5 and EBarType == -1 then Color.Dark_Gray else if APC == 5 and EBarType == 2.2 then Color.Green else if APC == 5 and EBarType == 2.1 then Color.Light_Green else if APC == 5 and EBarType == 2 then Color.Dark_Green else if APC == 5 and EBarType == -2 then Color.Red else if APC == 5 and EBarType == -2.1 then Color.Light_Red else if APC == 5 and EBarType == -2.2 then Color.Dark_Red else if APC == 5 and EBarType == 3.1 then Color.Yellow else if APC == 5 and EBarType == -3 then Color.Dark_Orange else if APC == 5 and EBarType == 3 then Color.Orange else
if APC == 6 and FBarType == 1.1 then Color.Gray else if APC == 6 and FBarType == 1 then Color.Light_Gray else if APC == 6 and FBarType == -1 then Color.Dark_Gray else if APC == 6 and FBarType == 2.2 then Color.Green else if APC == 6 and FBarType == 2.1 then Color.Light_Green else if APC == 6 and FBarType == 2 then Color.Dark_Green else if APC == 6 and FBarType == -2 then Color.Red else if APC == 6 and FBarType == -2.1 then Color.Light_Red else if APC == 6 and FBarType == -2.2 then Color.Dark_Red else if APC == 6 and FBarType == 3.1 then Color.Yellow else if APC == 6 and FBarType == -3 then Color.Dark_Orange else if APC == 6 and FBarType == 3 then Color.Orange else Color.current);
# HAMMER
input Hammer_length = 30;
input Hammer_trendSetup = 3;
input Hammer_bodyFactor = 0.3;
input Hammer_shadowFactor = 2.0;
Assert(Hammer_bodyFactor >= 0, "'body factor' must not be negative: " + Hammer_bodyFactor);
Assert(Hammer_shadowFactor >= 0, "'shadow factor' must not be negative: " + Hammer_shadowFactor);
def Hammer_BodyHeight = BodyHeight();
def Hammer_AverageBodyHeight = Average(Hammer_BodyHeight, Hammer_length);
def Hammer_ErrMargin = 0.25 * Hammer_AverageBodyHeight;
def Hammer_IsShort = Hammer_BodyHeight <= Hammer_bodyFactor * Hammer_AverageBodyHeight;
def Hammer = IsDescending(C, Hammer_trendSetup)[1] and
Hammer_IsShort and
H - Max(O, C) <= Hammer_ErrMargin and
Min(O, C) - L > Hammer_shadowFactor * Hammer_BodyHeight;
# SHOOTER
input Star_length = 30;
input Star_trendSetup = 3;
input Star_bodyFactor = 0.3;
input Star_shadowFactor = 2.0;
Assert(Star_bodyFactor >= 0, "'body factor' must not be negative: " + Star_bodyFactor);
Assert(Star_shadowFactor >= 0, "'shadow factor' must not be negative: " + Star_shadowFactor);
def Star_BodyHeight = BodyHeight();
def Star_AverageBodyHeight = Average(Star_BodyHeight, Star_length);
def Star_ErrMargin = 0.25 * Star_AverageBodyHeight;
def Star_IsShort = Star_BodyHeight <= Star_bodyFactor * Star_AverageBodyHeight;
def ShootingStar = IsAscending(C, Star_trendSetup)[1] and
Star_IsShort and
Min(O, C) - L <= Star_ErrMargin and
H - Max(O, C) > Star_shadowFactor * Star_BodyHeight;
# -------------------------
# ACTIONABLE SIGNALS
# -------------------------
def InsideUp = insidebar[1] and C crosses above H[1] and C > H[1];
def InsideDown = insidebar[1] and C crosses below L[1] and C < L[1];
def KickingBull = O >= H[1] and C > O;
def KickingBear = O <= L[1] and C < O;
def HammerRev = Hammer[1] and C crosses above H[1] and C > H[1];
def ShooterRev = ShootingStar[1] and C crosses below L[1] and C < L[1];
def MomoStar = IsDescending(C, Star_trendSetup)[2] and
Star_IsShort[1] and
Min(O[1], C[1]) - L[1] <= Star_ErrMargin and
H[1] - Max(O[1], C[1]) > Star_shadowFactor * Star_BodyHeight and
C crosses below L[1] and C < L[1];
def MomoHammer = IsAscending(C, Hammer_trendSetup)[2] and
Hammer_IsShort[1] and
H[1] - Max(O[1], C[1]) <= Hammer_ErrMargin and
Min(O[1], C[1]) - L[1] > Hammer_shadowFactor * Hammer_BodyHeight and
C crosses above H[1] and C > H[1];
input RangeAVG = AverageType.SIMPLE;
input RangeLength = 13;
input MeasuredMove_Sensitivity = 50;
def MMS = MeasuredMove_Sensitivity / 100;
def ATR = MovingAverage(RangeAVG, TrueRange(H, C, L), RangeLength);
def MeasuredUp = (TrueRange(H[2], C[2], L[2]) > MMS * ATR) and IsAscending(C, 2) and insidebar[1] and C crosses above H[1];
def MeasuredDown = (TrueRange(H[2], C[2], L[2]) > MMS * ATR) and IsDescending(C, 2) and insidebar[1] and C crosses below L[1];
def ActionableUp = InsideUp or KickingBull or RevStratBull or HammerRev or MomoHammer or MeasuredUp;
def ActionableDown = InsideDown or KickingBear or RevStratBear or ShooterRev or MomoStar or MeasuredDown;
# -------------------------
# SIGNAL ALERTS
# -------------------------
AddLabel(ActionableUp or ActionableDown, ("ACTIONABLE: " + if InsideUp then ”Inside Up” else if KickingBull then ”Kicking Bull” else if RevStratBull then “Rev Strat Bull” else if HammerRev then ”Hammer Rev” else if MomoHammer then ”Momentum Hammer” else if MeasuredUp then “Measured Move Up” else if InsideDown then “Inside Down” else if KickingBear then “Kicking Bear” else if RevStratBear then “Rev Strat Bear” else if ShooterRev then "Shooter Rev" else if MomoStar then "Momentum Star" else if MeasuredDown then " Measured Move Down" else ""), if ActionableUp then Color.CYAN else if ActionableDown then Color.MAGENTA else Color.BLACK);