Adaptive Channel Breakout
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © peacefulLizard50262

//@version=5
indicator("Adaptive Channel Breakout", overlay = true)
import peacefulLizard50262/peacefulIndicators/1 as p

src        = input.source(close, "Source")
ma_length  = input.int(10, "Length", 1)
vol_length = input.int(10, "Volatility Length", 1)
multiplier = input.float(2, "multiplier", 1)

alerts     = input.bool(false, "Alerts")
priceLable = input.bool(false, "Use Price instead of Up/Down")

[upper, lower, trend] = p.acb(src, ma_length, vol_length, multiplier)

colour = trend ? color.green : color.red

level = trend ? lower : upper

plot(level, "ACB", colour, style = plot.style_linebr)

up = trend and not trend[1]
down = not trend and trend[1]

if priceLable and up
    label.new(bar_index, close, str.tostring(close), yloc = yloc.belowbar,style = label.style_label_up, color = color.green, textcolor = color.white)
if priceLable and down
    label.new(bar_index, close, str.tostring(close), yloc = yloc.abovebar,style = label.style_label_down, color = color.red, textcolor = color.white)

plotshape(priceLable ? na : up, "Up", shape.labelup, location.belowbar, color.green, 0, "Up", color.white)
plotshape(priceLable ? na : down, "Down", shape.labeldown, location.abovebar, color.red, 0, "Down", color.white)

if up and alerts
    alert("Trending Up at " + str.tostring(close))

if down and alerts
    alert("Trending Down at " + str.tostring(close))