OPEN-SOURCE SCRIPT

Sideways & Breakout Detector + Forecast

64
//version=6
indicator("Sideways & Breakout Detector + Forecast", overlay=true, max_labels_count=500)

// Inputs
lengthATR = input.int(20, "ATR Länge")
lengthMA = input.int(50, "Trend MA Länge")
sqFactor = input.float(1.2, "Seitwärtsfaktor")
brkFactor = input.float(1.5, "Breakoutfaktor")

// ATR / Volatilität
atr = ta.atr(lengthATR)
atrSMA = ta.sma(atr, lengthATR)

// Basislinie / Trend
basis = ta.sma(close, lengthATR)
trendMA = ta.sma(close, lengthMA)

// Seitwärtsbedingung
isSideways = atr < atrSMA * sqFactor

// Breakouts
upperBreak = close > basis + atr * brkFactor
lowerBreak = close < basis - atr * brkFactor

// Vorhergesagter Ausbruch (Forecast)
// Wenn Seitwärtsphase + Kurs nahe obere oder untere Kanalgrenze
forecastBull = isSideways and (close > basis + 0.5 * atr)
forecastBear = isSideways and (close < basis - 0.5 * atr)

// Farben
barcolor(isSideways ? color.new(color.yellow, 40) : na)
barcolor(upperBreak ? color.green : na)
barcolor(lowerBreak ? color.red : na)

// Breakout-Bänder
plot(basis + atr * brkFactor, "Bull Break Zone", color=color.new(color.green, 60))
plot(basis - atr * brkFactor, "Bear Break Zone", color=color.new(color.red, 60))

// Labels (klein)
if isSideways
label.new(bar_index, close, "Seitwärts", color=color.yellow, style=label.style_label_center, size=size.tiny)

if upperBreak
label.new(bar_index, high, "Bull Breakout", color=color.green, style=label.style_label_up, size=size.tiny)

if lowerBreak
label.new(bar_index, low, "Bear Breakout", color=color.red, style=label.style_label_down, size=size.tiny)

// Vorhergesagte Ausbrüche markieren
plotshape(forecastBull, title="Forecast Bull", location=location.abovebar, color=color.new(color.green, 0), style=shape.triangleup, size=size.tiny)
plotshape(forecastBear, title="Forecast Bear", location=location.belowbar, color=color.new(color.red, 0), style=shape.triangledown, size=size.tiny)

// Alerts
alertcondition(isSideways, "Seitwärtsphase", "Der Markt läuft seitwärts.")
alertcondition(upperBreak, "Bull Breakout", "Ausbruch nach oben!")
alertcondition(lowerBreak, "Bear Breakout", "Ausbruch nach unten!")
alertcondition(forecastBull, "Forecast Bull", "Voraussichtlicher Bull-Ausbruch!")
alertcondition(forecastBear, "Forecast Bear", "Voraussichtlicher Bear-Ausbruch!")

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.