# DECLARATIONS declare upper; # USER INPUTS input resetCountOnDTorDB = yes; input barsBack = 10; # DEFINITIONS AND CALCULATIONS ## Variable List def isFlatTopSBEligible; def isBullSB; def lastBullSBLow; def isHBar; def lastHBarLow; def isPushUp; def lastPushUp; def resetHCount; def isHCountStillReset; def hCount; def isFlatBottomSBEligible; def isBearSB; def lastBearSBHigh; def isLBar; def lastLBarHigh; def isPushDown; def lastPushDown; def resetLCount; def isLCountStillReset; def lCount; ### H Counting isFlatTopSBEligible = fold hFold = 1 to barsBack with dt = Double.NaN while IsNaN(dt) do if GetValue(high, hFold) == high then Double.NaN else if GetValue(high, hFold) > high then yes else no; isBullSB = (high[1] > high and high[-1] > high) #Standard bull SB or (isFlatTopSBEligible and high[-1] > high); #DT to the left lastBullSBLow = if isBullSB then low else lastBullSBLow[1]; isHBar = (low < lastBullSBLow[1] and isBullSB) or (isBullSB and isHCountStillReset); lastHBarLow = CompoundValue(1, if isHBar then low else lastHBarLow[1], low); isPushUp = if isHBar then yes else if isPushUp[1] and high >= high[1] then yes else no; lastPushUp = if isPushUp[1] and !isPushUp then high[1] else if high > lastPushUp[1] then high else lastPushUp[1]; resetHCount = high > lastPushUp[1] or (resetCountOnDTorDB and high == lastPushUp[1]); isHCountStillReset = if !isBullSB and resetHCount then yes else isHCountStillReset[1]; hCount = CompoundValue(1, if isHBar and !resetHCount then hCount[1] + 1 else if resetHCount then 0 else hCount[1], 0); ### L Counting isFlatBottomSBEligible = fold lFold = 1 to barsBack with db = Double.NaN while IsNaN(db) do if GetValue(low, lFold) == low then Double.NaN else if GetValue(low, lFold) < low then yes else no; isBearSB = (low[1] < low and low[-1] < low) #Standard bear SB or (isFlatBottomSBEligible and low[-1] < low); #Db to the left lastBearSBHigh = if isBearSB then high else lastBearSBHigh[1]; isLBar = (high > lastBearSBHigh[1] and isBearSB) or (isBearSB and isLCountStillReset); lastLBarHigh = CompoundValue(1, if isLBar then high else lastLBarHigh[1], high); isPushDown = if isLBar then yes else if isPushDown[1] and low <= low[1] then yes else no; lastPushDown = if isPushDown[1] and !isPushDown then low[1] else if low < lastPushDown[1] then low else lastPushDown[1]; resetLCount = low < lastPushDown[1] or (resetCountOnDTorDB and low == lastPushDown[1]); isLCountStillReset = if !isBearSB and resetLCount then yes else isLCountStillReset[1]; lCount = CompoundValue(1, if isLBar and !resetLCount then lCount[1] + 1 else if resetLCount then 0 else lCount[1], 0); # PLOTS plot hSetup = if hCount <> hCount[1] and hCount <> 0 then hCount else Double.NaN; plot lSetup = if lCount <> lCount[1] and lCount <> 0 then lCount else Double.NaN; # Adding Bubbles for H1, H2, H3, H4 and L1, L2, L3, L4 AddChartBubble(hCount == 1, low, "H1", Color.GREEN, no); # Bubble for H1 AddChartBubble(hCount == 2, low, "H2", Color.GREEN, no); # Bubble for H2 AddChartBubble(hCount == 3, low, "H3", Color.GREEN, no); # Bubble for H3 AddChartBubble(hCount == 4, low, "H4", Color.GREEN, no); # Bubble for H4 AddChartBubble(lCount == 1, high, "L1", Color.RED, yes); # Bubble for L1 AddChartBubble(lCount == 2, high, "L2", Color.RED, yes); # Bubble for L2 AddChartBubble(lCount == 3, high, "L3", Color.RED, yes); # Bubble for L3 AddChartBubble(lCount == 4, high, "L4", Color.RED, yes); # Bubble for L4 # GLOBAL COLOR DEFINITIONS DefineGlobalColor("Blue" , CreateColor(33, 150, 243)); DefineGlobalColor("Green", CreateColor(0, 155, 0)); DefineGlobalColor("Red", CreateColor(225, 105, 105)); DefineGlobalColor("Gray", CreateColor(181, 181, 181)); DefineGlobalColor("White", CreateColor(255, 255, 255)); # FORMATTING hSetup.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW); hSetup.SetDefaultColor(GlobalColor("Green")); hSetup.SetLineWeight(2); hSetup.HideBubble(); lSetup.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE); lSetup.SetDefaultColor(GlobalColor("Red")); lSetup.SetLineWeight(2); lSetup.HideBubble();