Volume Sentiment
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © grnghost

//@version=5
indicator("Volume Senitment", "V Sent", overlay = false, precision = 1)

group1 = "Volume Thrust"
vlookback = input.int(9, "Volume Sum Period =", minval =  1, group = group1)
ma_len = input.int(13, "Moving Average Length =", minval =  2, group = group1)

group2 = "Strong Volume"
vma_len = input.int(18,"Volume MA Length", 2, group = group2)
thresh = input.float(45, "Strong Volume Threshold (% over MA)", minval = 1, step = 0.5, group = group2)


group3 = "Display"
cbmo = input.bool(false, "Color by Momentum", group = group3)
show_ma = input.bool(false, "Show Moving Average", group = group3) 
show_str = input.bool(true, "Show Strong Volume Signal", group = group3) 
show_sig = input.bool(false, "Show Trade Signals", group = group3)

up_bar = close > hl2 // close > open  
dn_bar = close < hl2 //close < open 

u_vol = up_bar ? volume : 0
d_vol = dn_bar ? volume : 0

up_vol = math.sum(u_vol,vlookback)
dn_vol = math.sum(d_vol,vlookback)

thrust = 100*(up_vol - dn_vol)/(up_vol + dn_vol)
thrust_ln = ta.sma(thrust,2)
thrust_ma = ta.sma(thrust, ma_len)

//Stong Volume
vma = ta.sma(volume, vma_len)
strong = volume > (1 + (thresh/100))*vma
str_col = strong and close < open ? color.new(color.red,30) : strong and close > open ? color.new(color.green,30) : na
var plot_col = color.blue

if cbmo == true
    plot_col := ta.change(thrust,2) < 0 and thrust < 0 ? color.new(color.red,30) : thrust < 0 ? #FFCDD2 : ta.change(thrust,2) > 0 and thrust > 0 ? color.new(color.green,30) : thrust > 0 ? #B2DFDB : na
else 
    plot_col := thrust < 0 ? color.new(color.red,30) : color.new(color.green,30)

long = ta.crossover(thrust, 0)
short = ta.crossunder(thrust, 0)

plot(math.abs(thrust), "Thrust", color = plot_col, style = plot.style_columns) //strong ? str_col :
plot(ta.sma(math.abs(thrust), ma_len), "Moving Average", color = show_ma ? color.yellow : na)
hline(70, "High Line", color = color.gray, linestyle = hline.style_dashed)
hline(30, "Mid Line", color = color.gray, linestyle = hline.style_dashed)
hline(0, "Zero Line", color = color.gray, linestyle = hline.style_solid)

plotshape(show_str ? strong : na, "Strong Volume Signal", style = shape.triangleup, location = location.top, color = color.orange, display = display.pane)
plotshape(show_sig ? long : na , "Bull Volume", style = shape.triangleup, location = location.bottom, color = color.yellow, display = display.pane)
plotshape(show_sig ? short : na, "Bear Volume", style = shape.triangledown, location = location.bottom, color = color.yellow, display = display.pane)

alertcondition(strong != strong[1]? strong : na, "Strong Volumen Alert", "Increased activity, take action.")

