Breakout Identifier + Pivots with pos/neg/neu candles
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © creksar_stock
//@version=5

indicator("Breakout Signals with Pivots", "Breakout indication", overlay = true)
//toggles n other source stuff
bc_src = close
bo_src = open

gap = input.int(250, "Signal Gap", 2, 500)

//define average tru range - defines the range in which a breakout would NOT occur in
atrLen = input.int(14, "atr length", minval = 1)
atrMultiplier = input.int(2, "atr multiplier", minval = 1)
average_true_range = ta.atr(atrLen)

//define average volatility for time frame
volLen = input.int(14, "volatility length", minval = 1)
volMultiplier = input.int(2, "volatility multiplier", minval = 1)
//volatility = standard deviation -> hi-stdev = high volatility vice versa
volatility = ta.stdev(bc_src, volLen)

//breakout calc.
bool BearBreakout = ta.crossover(bc_src, high - atrMultiplier * average_true_range) and volatility < volMultiplier * volatility[1]
bool BullBreakout = ta.crossunder(bc_src, low + atrMultiplier * average_true_range) and volatility < volMultiplier * volatility[1]

//inputs for drawing plots
bo_type = BearBreakout or BullBreakout

Bear_col = input.color(color.new(#2cff37,30))
Bull_col = input.color(color.new(#ff2c2c, 30))

//line signal
//xloc.barindex to pull time at a location, request price at specific time 
blLine = BullBreakout ? line.new(bar_index + 25, high, bar_index, high, color = color.red, width = 2) : na
brLine = BearBreakout ? line.new(bar_index + 25, low, bar_index, low, color = color.green, width = 2) : na

hiLoBox = box.new(bar_index - 1, high[1], bar_index, low, border_color = na, bgcolor = color.new(#FFFFFF,70))
line.set_x2(brLine, bar_index)
line.set_x2(blLine, bar_index)
box.set_right(hiLoBox, bar_index)

boxColor = high > high[1] ? color.green : low < low[1] ? color.red : color.silver
box.set_bgcolor(hiLoBox, color.new(boxColor, 80))
//help = BearBreakout ? line.new(bar_index + 25, low, bar_index, low, color = color.green, width = 2) : BullBreakout ? line.new(bar_index + 25, high, bar_index, high, color = color.red, width = 2) : na

if BearBreakout
    label.new(bar_index, low - gap, "Bear Breakout", color = Bear_col, style = label.style_triangleup, size = size.auto)
else if BullBreakout
    label.new(bar_index, high + gap, "Bear Breakout", color = Bull_col, style = label.style_triangledown, size = size.auto)
plot(na)
//line.new(bar_index - 1, low, bar_index, low, color = color.green, width = 2)
//line.new(bar_index - 1, high, bar_index, high, color = color.red, width = 2)

