10X Bars - Directional Trends
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Beardy_Fred

//@version=5
indicator(title="10X Bars", shorttitle="10X", overlay = true)

//INPUTS
len         = input.int(14, "Directional Length")
ADX_T       = input.int(20, "ADX Length")
vol_len     = input.int(20, "Volume Length")
vol_trigger = input.int(50, "Volume % Above Average Trigger", minval=5)

//DMI CALCULATIONS - Tradingview Built-In DMI Indicator
up          = ta.change(high)
down        = -ta.change(low)
plusDM      = na(up) ? na : (up > down and up > 0 ? up : 0)
minusDM     = na(down) ? na : (down > up and down > 0 ? down : 0)
trur        = ta.rma(ta.tr, len)
plus        = fixnan(100 * ta.rma(plusDM, len) / trur)
minus       = fixnan(100 * ta.rma(minusDM, len) / trur)
sum         = plus + minus
adx         = 100 * ta.rma(math.abs(plus - minus) / (sum == 0 ? 1 : sum), len)

//10X CALCULATIONS
D_Up        = (plus > minus) and (adx > ADX_T)
D_Down      = (minus > plus) and (adx > ADX_T)
sideways    = (adx < ADX_T)
Bar_Color   = sideways ? color.new(color.yellow, 0) : D_Up ? color.new(color.green, 0) : D_Down ? color.new(color.red, 0) :  na

//PLOT
barcolor(color=Bar_Color)

//SPIKES ABOVE AVERAGE VOLUME
Avg_Vol     = ta.sma(volume, vol_len)
Vol_Spike   = (1 + (vol_trigger / 100)) * Avg_Vol
plotchar(volume > Vol_Spike, "Volume Spike", char = '◉', location = location.bottom, color = color.new(color.aqua, 0), size = size.tiny)
