3+ Consecutive Bars Accelerating Up or Down

来自BPAX Lab

Overview[编辑 | 编辑源代码]

Pine script[编辑 | 编辑源代码]

//@version=5

indicator("3 CCBA", overlay=true)

// * overlay = true will prevent the indicator from showing in seperate panel

goodTrendBarThreshold = 0.8

okTrendBarThreshold = 0.5

// * 3 bull bars

allBLB = (close > open) and (close[1] > open[1]) and (close[2] > open[2])

// * current bar closed above 80%; -1 bar closed above 50%; -2 bar closed above 50%

allBLBOkBody = ((close - low) / (high - low) >= goodTrendBarThreshold) and ((close[1] - low[1]) / (high[1] - low[1]) >= okTrendBarThreshold) and ((close[2] - low[2]) / (high[2] - low[2]) >= okTrendBarThreshold)

// * all 3 bars closed above 80% of bar size, i.e. good trending BLBCH

allBLBCH = ((close - low) / (high - low) >= goodTrendBarThreshold) and ((close[1] - low[1]) / (high[1] - low[1]) >= goodTrendBarThreshold) and ((close[2] - low[2]) / (high[2] - low[2]) >= goodTrendBarThreshold)

// * all 3 bars body is bigger than 50% of bar size

noDojiBLB = ((close - open) / (high - low) >= okTrendBarThreshold) and ((close[1] - open[1]) / (high[1] - low[1]) >= okTrendBarThreshold) and ((close[2] - open[2]) / (high[2] - low[2]) >= okTrendBarThreshold)

// * bar sizes are increasing

allBLBA = ((close[2] - open[2]) <= (close[1] - open[1])) and ((close[1] - open[1]) <= (close - open))

threeCCBLBA = allBLB and allBLBOkBody and noDojiBLB and allBLBA

threeCCBLBCH = allBLB and allBLBCH and noDojiBLB

// * 3 bear bars

allBRB = (close < open) and (close[1] < open[1]) and (close[2] < open[2])

// * current bar closed below 80%; -1 bar closed below 50%; -2 bar closed below 50%

allBRBOkBody = ((high - close) / (high - low) >= goodTrendBarThreshold) and ((high[1] - close[1]) / (high[1] - low[1]) >= okTrendBarThreshold) and ((high[2] - close[2]) / (high[2] - low[2]) >= okTrendBarThreshold)

// * all 3 bars closed below 80% of bar size, i.e. good trending BRBCL

allBRBCL = ((high - close) / (high - low) >= goodTrendBarThreshold) and ((high[1] - close[1]) / (high[1] - low[1]) >= goodTrendBarThreshold) and ((high[2] - close[2]) / (high[2] - low[2]) >= goodTrendBarThreshold)

// * all 3 bars body is bigger than 50% of bar size

noDojiBRB = ((open - close) / (high - low) >= okTrendBarThreshold) and ((open[1] - close[1]) / (high[1] - low[1]) >= okTrendBarThreshold) and ((open[2] - close[2]) / (high[2] - low[2]) >= okTrendBarThreshold)

// * bar sizes are increasing

allBRBA = ((open[2] - close[2]) <= (open[1] - close[1])) and ((open[1] - close[1]) <= (open - close))

threeCCBRBA = allBRB and allBRBOkBody and noDojiBRB and allBRBA

threeCCBRBCL = allBRB and allBRBCL and noDojiBRB

allConditions = threeCCBLBA or threeCCBLBCH or threeCCBRBA or threeCCBRBCL

alertcondition(allConditions, title='3 CCBA!', message= '3 CCBA!')

plot(series=close)