Stockbee Momentum Burst
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © shaaah10

//@version=5
indicator(title="Stockbee", overlay=true)

// INPUT
var string GP1 = 'MOMENTUM BURST'
input_bull = input.bool(defval=true, title="Bullish", group = GP1)
input_bear = input.bool(defval=true, title="Bearish", group = GP1)

var string GP2 = 'THRESHOLD'
input_percent = input.bool(defval=true, title="Percent", group = GP2)
input_dollar = input.bool(defval=true, title="Dollar", group = GP2)

var string GP3 = 'MOMENTUM FILTER'
input_momentum_bull = input.bool(defval=false, title="EMA 10 > 20", group = GP3)
input_momentum_bear = input.bool(defval=false, title="EMA 10 < 20", group = GP3)
input_momentum_divide = input.bool(defval=false, title="Linked", tooltip = "This will override all other momentum filters, bullish candles will be displayed when EMA 10 > 20 and bearish candles when EMA 10 < 20", group = GP3)

var string gp4 = "REVERSAL"
input_bull_r = input.bool(defval = true, title="Bullish", group = gp4)
input_bear_r = input.bool(defval = true, title="Bearish", group = gp4)
input_remove = input.bool(defval = false, title="Remove P/V", tooltip = "Check to remove the price and volume requirement", group = gp4)
label_size = input.string("auto", "Label Size", options = ["huge", "large", "normal", "small", "tiny", "auto"], group = gp4)

// BULLISH
bullish_pt = (close/close[1]>=1.04) and (close>open) and ((close-open)>=(close[1]-open[1])) and (close>close[1]) and (volume>=100000) and (volume>volume[1])
bullish_db = (close-open>=0.9) and (close>open) and ((close-open)>=(close[1]-open[1])) and (close>close[1]) and (volume>=100000)
bullish_hod = (close-low)/(high-low)>=0.7
bullish_linear = close[1]/close[2]<=1.02

bull_percent = bullish_pt and bullish_hod and bullish_linear
bull_dollar = bullish_db and bullish_hod and bullish_linear

// BEARISH
bearish_pt = (close/close[1]<=0.96) and (close<open) and (close<close[1]) and (volume>=100000) and (volume>volume[1])
bearish_db = (open-close>=0.9) and (close<open) and (close<close[1]) and (volume>=100000)
bearish_re = math.abs(open-close) >= math.abs(open[1]-close[1])
bearish_lod = (close-low)/(high-low)<=0.3
bearish_linear = close[1]/close[2]>=0.98
volume_length = ta.lowest(volume, 3)
min_volume = volume_length >= 100000

bear_percent = bearish_pt and bearish_linear and min_volume and bearish_re and bearish_lod
bear_dollar = bearish_db and bearish_linear and min_volume and bearish_re and bearish_lod

//BULLISH
l_minl5 = low == ta.lowest(low, 5)
ol_co = (open-low) > (close-open)
cl_hl = ((close-low)/(high-low)) >= 0.6
vol = volume >= 900000
price = close >= 10
volume_length_r = ta.lowest(volume, 3)
vol_avg = volume_length >= 1000000

bullish_reversal = l_minl5 and ol_co and cl_hl and vol and price and vol_avg
bullish_reversal_bypass = l_minl5 and ol_co and cl_hl

//BEARISH
bear_vol = volume >= 1000000
bear_price = close >= 10
bear_volavg = volume_length_r >= 1000000
bear_change = (close[0]/close[1]) > 0.99
bear_clhl = ((close-low)/(high-low)) <= 0.8
bear_rsi = ta.rsi(close, 3) >= 80

bearish_reversal = bear_vol and bear_price and bear_volavg and bear_change and bear_clhl and bear_rsi
bearish_reversal_bypass = bear_change and bear_clhl and bear_rsi

// MOMENTUM FILTER
bull_momentum = ta.ema(close, 10) > ta.ema(close, 20)
bear_momentum = ta.ema(close, 10) < ta.ema(close, 20)

// COLOR BAR
color_percent = bull_percent ? color.rgb(27, 94 ,32) : bear_percent ? color.rgb(178, 40, 51) : na
color_dollar = bull_dollar ? color.green : bear_dollar ? color.red : na
color_neutral = close > open ? color.rgb(200, 230, 201, 30) : close < open ? color.rgb(252, 203, 205, 30) : na

color_bar = if ((input_bull and input_percent and bull_percent) or (input_bear and input_percent and bear_percent) == true)
    color_percent
else if ((input_bull and input_dollar and bull_dollar) or (input_bear and input_dollar and bear_dollar) == true)
    color_dollar
else
    color_neutral

// COLOR FILTER
color_momentum_combo = bull_momentum or bear_momentum ? color_bar : color_neutral
color_momentum_bull = bull_momentum ? color_bar : color_neutral
color_momentum_bear = bear_momentum ? color_bar : color_neutral
color_momentum_divide = bull_momentum and input_bull and ((input_percent and bull_percent) or (input_dollar and bull_dollar)) ? color_bar : bear_momentum and input_bear and ((input_bear and bear_percent) or (input_bear and bear_dollar)) ? color_bar : color_neutral

print_color = if (input_momentum_divide == true)
    color_momentum_divide
else if (input_momentum_bull and input_momentum_bear == true)
    color_momentum_combo
else if (input_momentum_bull == true)
    color_momentum_bull
else if (input_momentum_bear == true)
    color_momentum_bear
else
    color_bar

// PLOT MOMENTUM BURST
barcolor(print_color)

// PLOT REVERSAL
if ((input_bull_r and bullish_reversal == true) and (input_remove == false))
    label_bull = label.new(bar_index[0], high, style=label.style_triangleup, size=label_size), label.set_yloc(label_bull, yloc.belowbar), label.set_color(label_bull, color.green), label.set_tooltip(label_bull, "Bullish Reversal")

if ((input_bear_r and bearish_reversal == true) and (input_remove == false))
    label_bear = label.new(bar_index[0], high, style=label.style_triangledown, size=label_size), label.set_yloc(label_bear, yloc.abovebar), label.set_color(label_bear, color.red), label.set_tooltip(label_bear, "Bearish Reversal")

if (input_bull_r and bullish_reversal_bypass and input_remove)
    label_bull_bypass = label.new(bar_index[0], high, style=label.style_triangleup, size=label_size), label.set_yloc(label_bull_bypass, yloc.belowbar), label.set_color(label_bull_bypass, color.green), label.set_tooltip(label_bull_bypass, "Bullish Reversal")

if (input_bear_r and bearish_reversal_bypass and input_remove)
    label_bear_bypass = label.new(bar_index[0], high, style=label.style_triangledown, size=label_size), label.set_yloc(label_bear_bypass, yloc.abovebar), label.set_color(label_bear_bypass, color.red), label.set_tooltip(label_bear_bypass, "Bearish Reversal")