# Counting Legs for Two Leg Pullback # mrb 20220212 # This script counts pullbacks to buy on high probability moves # buy point for bull side is second pullback after a swing high # buy point for bull side is second pullback after a swing low ### def SwLo1 = 10000; def SwHi1 = 0; #---> Count Bull Retracement Legs def BullRetrace = if high == high[1] then if high < high[2] and high < high[-1] then 1 else 0 else if high < high[1] and high < high[-1] then 1 else 0; def SwLo2 = if BullRetrace and high < SwLo1 then high else SwLo2[1]; def SwLo = if BullRetrace and high < SwLo2[1] then 1 else 0; def BullCount = if BullRetrace and SwLo then 1 else if BullRetrace then BullCount[1] + 1 else BullCount[1]; def BullCountDisplay = if BullCount == 2 then 1 else 0; #---> Look and Feel BULL Swing AddChartBubble(BullRetrace, low -2, BullCount, if BullCount == 2 then Color.YELLOW else if BullCount == 1 then Color.CYAN else Color.LIGHT_GREEN); Alert(BullRetrace, "BULL SWING", Alert.TICK, Sound.Ring); plot SW = if BullRetrace then low else Double.NaN; SW.SetLineWeight(5); SW.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_DOWN); SW.SetDefaultColor(Color.YELLOW); SW.HideBubble(); #---> Count Bear Retracement Legs def BearRetrace = if low == low[1] then if low < low[2] and low < low[-1] then 1 else 0 else if low > low[1] and low > low[-1] then 1 else 0; def SwHi2 = if BearRetrace and low > SwHi1 then low else SwHi2[1]; def SwHi = if BearRetrace and low > SwHi2[1] then 1 else 0; def BearCount = if BearRetrace and SwHi then 1 else if BearRetrace then BearCount[1] + 1 else BearCount[1]; def BearCountDisplay = if BearCount == 2 then 1 else 0; #---> Look and Feel BEAR Swing AddChartBubble(BearRetrace, high +1, BearCount, if BearCount == 2 then Color.MAGENTA else if BearCount == 1 then Color.WHITE else Color.GRAY); Alert(BearRetrace, "BEAR SWING", Alert.TICK, Sound.Ring); # Alert on a retracementthinkor plot SW1 = if BearRetrace then low else Double.NaN; SW1.SetLineWeight(5); SW1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_UP); SW1.SetDefaultColor(Color.MAGENTA); SW1.HideBubble(); AssignBackgroundColor(if BullCountDisplay then Color.LIGHT_GREEN else if BearCountDisplay then Color.LIGHT_RED else Color.BLACK); # End Code