// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/

// CrocVibes by Telgos

// Danke für die Grundlagen und Basisversion: amper04, ray_duke, husky, Audidriver13│

//@version=5
indicator("Croc Vibes V3.6 by Telgos", overlay=true)

// === Inputs ===
// --- Gruppe: Chart-Signale ---
wolke_Line_rot = input.source(title="Wolke Linie Pink", defval=close, group="Chart-Signale")
blauer_punkt_long  = input.source(title="Blauer Punkt Long", defval=close, group="Chart-Signale")
blauer_punkt_short = input.source(title="Blauer Punkt Short", defval=close, group="Chart-Signale")
hellgruener_punkt_long = input.source(title="Hellgruener Punkt Long", defval=close, group="Chart-Signale")
cloud_punkt_long = input.source(title="Cloud Punkt Long", defval=close, group="Chart-Signale")
red_devil_long = input.source(title="Red Devil Long", defval=close, group="Chart-Signale")
bb_kombi_long = input.source(title="BB Kombi long", defval=close, group="Chart-Signale")
lollipop_long = input.source(title="Lollipop long", defval=close, group="Chart-Signale")
aw_rocket_long = input.source(title="AW-Rocket long", defval=close, group="Chart-Signale")
bgrl_signal = input.source(title="Black Green Rocket Long", defval=close, group="Chart-Signale")
rotes_plus = input.source(title="Rotes Plus", defval=close, group="Chart-Signale")

// --- Gruppe: Lochstreifen ---
status_g = input.source(title="Status (1) Grün", defval=close, group="Lochstreifen")
status_r = input.source(title="Status (2) Rot", defval=close, group="Lochstreifen")
wolke_g = input.source(title="Wolke (1) Grün", defval=close, group="Lochstreifen")
wolke_r = input.source(title="Wolke (3) Rot", defval=close, group="Lochstreifen")
trend_s = input.source(title="Trend (1) Schwarz", defval=close, group="Lochstreifen")
trend_r = input.source(title="Trend (2) Rot", defval=close, group="Lochstreifen")
trend_g = input.source(title="Trend (3) Grün", defval=close, group="Lochstreifen")
setter_r = input.source(title="Setter (Trend 5) Rot", defval=close, group="Lochstreifen")
setter_g = input.source(title="Setter (Trend 6) grün", defval=close, group="Lochstreifen")
welle_g = input.source(title="Welle (1) grün", defval=close, group="Lochstreifen")
welle_gg = input.source(title="Welle (2) dunkelgrün", defval=close, group="Lochstreifen")
welle_r = input.source(title="Welle (4) Rot", defval=close, group="Lochstreifen")
welle_rr = input.source(title="Welle (6) dunkelRot", defval=close, group="Lochstreifen")
kerze_g = input.source(title="Kerzenfarbe (1) Gruen", defval=close, group="Lochstreifen")
kerze_s = input.source(title="Kerzenfarbe (2) Schwarz", defval=close, group="Lochstreifen")
kerze_r = input.source(title="Kerzenfarbe (3) Rot", defval=close, group="Lochstreifen")

// --- Gruppe: MSI ---
src1 = input.source(close, "Day OverBought 1", group="MSI")

// --- Gruppe: Allgemeine Einstellungen ---
show_blue_dot_labels = input.bool(true, title="Blaue Punkte Labels anzeigen", group="Allgemeine Einstellungen")
swing_lookback = input.int(5, title="Swing-Lookback", minval=1, group="Allgemeine Einstellungen")
label_offset_mult = input.float(3.0, title="Label Abstand (ATR Multiplikator)", minval=0.1, step=0.1, group="Allgemeine Einstellungen")

// Signal_close zu Übergeben macht keinen Sinn
signal_close = close

// === Logik ===
atr = ta.atr(16)
baerische_welle = (welle_rr > 0 or welle_r > 0)
bullische_welle = (welle_gg > 0 or welle_g > 0)

// === Pearl Diver ===
allRed = (status_r > 0) and (kerze_r > 0) and (wolke_r > 0) and (trend_r > 0) and (setter_r > 0) and baerische_welle
kerzeSG_l = (status_r > 0) and ((kerze_s > 0) or (kerze_g > 0)) and (wolke_r > 0) and (trend_r > 0) and (setter_r > 0) and baerische_welle
isPearlLong = kerzeSG_l and allRed[1] and allRed[2]

allGreen = (status_g > 0) and (kerze_g > 0) and (wolke_g > 0) and (trend_g > 0) and (setter_g > 0) and bullische_welle
kerzeSG_s = (status_g > 0) and ((kerze_s > 0) or (kerze_r > 0)) and (wolke_g > 0) and (trend_g > 0) and (setter_g > 0) and bullische_welle
isPearlShort = kerzeSG_s and allGreen[1] and allGreen[2]

// === Stephan-Setup (V2-Logik) ===
stephan_zusatzbedingung_erfuellt = (cloud_punkt_long > 0) or
                                   (red_devil_long > 0) or
                                   (lollipop_long > 0) or
                                   (bb_kombi_long > 0) or
                                   (aw_rocket_long > 0) or
                                   (bgrl_signal > 0)
stephan_setup = not na(src1) and (wolke_g > 0) and (trend_s > 0) and (setter_r > 0) and stephan_zusatzbedingung_erfuellt

// === Ulti Rally (V2-kompatibel) ===
Kerze_in_wolke_gr = signal_close - wolke_Line_rot
ulti_rally = (hellgruener_punkt_long > 0) and (Kerze_in_wolke_gr > 0) and (status_r > 0) and (kerze_r > 0) and (setter_r > 0) and not baerische_welle

// === BGRL ===
is_bgrl = bgrl_signal > 0

// === Rotes Plus ===
is_rotes_plus = (rotes_plus > 0) and (wolke_g > 0)

// === Blaue Punkte ===
highest_swing = ta.highest(high, swing_lookback)
lowest_swing = ta.lowest(low, swing_lookback)
isBlueShortFulfilled = (wolke_g > 0 and blauer_punkt_short > high and high == highest_swing)
isBlueLongFulfilled = (wolke_r > 0 and blauer_punkt_long < low and low == lowest_swing)
punkt_erfuellt = isBlueShortFulfilled or isBlueLongFulfilled

// === Alerts ===
alertcondition(isPearlLong, title="Pearl Long", message="Pearl Diver erkannt")
alertcondition(isPearlShort, title="Pearl Short", message="Oyster Farmer erkannt")
alertcondition(ulti_rally, title="Ulti Rally", message="Ulti Rally erkannt")
alertcondition(stephan_setup, title="Stephan Setup", message="Stephan Setup erkannt")
alertcondition(is_bgrl, title="BGRL", message="Black Green Rocket Long erkannt")
alertcondition(is_rotes_plus, title="Rotes Kreuz bei grüner Wolke", message="Rotes Kreuz erkannt")

// === Labels ===
if isPearlLong
    label.new(bar_index, low - atr * label_offset_mult, text="Pearl Diver", style=label.style_label_up, color=color.purple, textcolor=color.white, size=size.small)
if isPearlShort
    label.new(bar_index, high + atr * label_offset_mult, text="Oyster Farmer", style=label.style_label_down, color=color.purple, textcolor=color.white, size=size.small)
if ulti_rally
    label.new(bar_index, low - atr * label_offset_mult, text="Ulti", style=label.style_label_up, color=color.aqua, textcolor=color.white, size=size.small)
if stephan_setup
    label.new(bar_index, low - atr * label_offset_mult, text="Stephan", style=label.style_label_up, color=color.teal, textcolor=color.white, size=size.small)
if is_bgrl
    label.new(bar_index, low - atr * label_offset_mult, text="BGRL", style=label.style_label_up, color=color.black, textcolor=color.white, size=size.small)
if is_rotes_plus
    label.new(bar_index, high + atr * label_offset_mult, text="Rotes Kreuz", style=label.style_label_down, color=color.red, textcolor=color.white, size=size.small)

// === Blaue Punkt Labels ===
if isBlueShortFulfilled and show_blue_dot_labels
    label.new(bar_index, high + atr * label_offset_mult, text="Blauer erfüllt", style=label.style_label_down, color=color.blue, textcolor=color.white, size=size.small)
if isBlueLongFulfilled and show_blue_dot_labels
    label.new(bar_index, low - atr * label_offset_mult, text="Blauer erfüllt", style=label.style_label_up, color=color.blue, textcolor=color.white, size=size.small)
if wolke_g > 0 and blauer_punkt_short > high and not punkt_erfuellt and show_blue_dot_labels
    label.new(bar_index, high + atr * label_offset_mult, text="Ein Hoch kommt noch", style=label.style_label_down, color=color.blue, textcolor=color.white, size=size.small)
if wolke_g > 0 and blauer_punkt_short < low and show_blue_dot_labels
    label.new(bar_index, low - atr * label_offset_mult, text="Tief verpasst", style=label.style_label_up, color=color.blue, textcolor=color.white, size=size.small)
if wolke_r > 0 and blauer_punkt_long < low and not punkt_erfuellt and show_blue_dot_labels
    label.new(bar_index, low - atr * label_offset_mult, text="Ein Tief kommt noch", style=label.style_label_up, color=color.blue, textcolor=color.white, size=size.small)
if wolke_r > 0 and blauer_punkt_long > high and show_blue_dot_labels
    label.new(bar_index, high + atr * label_offset_mult, text="Hoch verpasst", style=label.style_label_down, color=color.blue, textcolor=color.white, size=size.small)

// === Shapes für Screener/Backtest ===
plotshape(isPearlLong, title="Pearl Long", location=location.abovebar, color=color.new(color.purple, 100), style=shape.labelup, size=size.tiny)
plotshape(isPearlShort, title="Pearl Short", location=location.belowbar, color=color.new(color.purple, 100), style=shape.labeldown, size=size.tiny)
plotshape(ulti_rally, title="Ulti Rally", location=location.abovebar, color=color.new(color.aqua, 100), style=shape.diamond, size=size.tiny)
plotshape(stephan_setup, title="Stephan Setup", location=location.abovebar, color=color.new(color.teal, 100), style=shape.labelup, size=size.tiny)
plotshape(is_bgrl, title="BGRL", location=location.abovebar, color=color.new(color.black, 100), style=shape.triangleup, size=size.tiny)
plotshape(is_rotes_plus, title="Rotes Kreuz", location=location.belowbar, color=color.new(color.red, 100), style=shape.labeldown, size=size.tiny)