//@version=5
strategy(“Heiliger Gral (Heikin Ashi)”, overlay=true)
// Auswahl des Timeframes für externe Berechnungen
tf = input.timeframe(“1D”, title=”Timeframe für Berechnung”) // Standardmäßig 1 Tag
// Auswahl: Trading Direction (Long, Short oder Long and Short)
tradeDirection = input.string(“Long and Short”, title=”Trading Direction”, options=[“Long”, “Short”, “Long and Short”])
// Kopierschutz: Definiere das feste Enddatum für den Backtest
int backtest_end_date = timestamp(2035, 2, 14, 0, 0)
current_time = time
// *** Heikin Ashi für den aktuellen Timeframe ***
ha_close_curr = (open + high + low + close) / 4
var float ha_open_curr = (open + close) / 2
ha_open_curr := (ha_open_curr + ha_close_curr[1]) / 2
ha_high_curr = math.max(high, math.max(ha_open_curr, ha_close_curr))
ha_low_curr = math.min(low, math.min(ha_open_curr, ha_close_curr))
// *** Heikin Ashi-Kerzen aus dem anderen Timeframe berechnen ***
ha_close_ext = request.security(syminfo.tickerid, tf, (open + high + low + close) / 4)
ha_open_ext_pre = request.security(syminfo.tickerid, tf, (open[1] + close[1]) / 2)
ha_open_ext = request.security(syminfo.tickerid, tf, na(ha_open_ext_pre[1]) ? ha_open_ext_pre : (ha_open_ext_pre[1] + ha_close_ext[1]) / 2)
ha_high_ext = request.security(syminfo.tickerid, tf, math.max(high, math.max(ha_open_ext, ha_close_ext)))
ha_low_ext = request.security(syminfo.tickerid, tf, math.min(low, math.min(ha_open_ext, ha_close_ext)))
// **Berechnung von z1 und z2 basierend auf externen Heikin Ashi-Kerzen**
a = request.security(syminfo.tickerid, tf, ta.highest(ha_high_ext, 3))
b = request.security(syminfo.tickerid, tf, ta.lowest(ha_low_ext, 3))
var float z1 = na
var float z2 = na
float z1_plot = na
float z2_plot = na
float z3 = na
if (current_time <= backtest_end_date)
ifha_close_ext[1]>ha_open_ext[1]andha_close_ext<ha_open_ext
z1:=a
ifha_close_ext[1]<ha_open_ext[1]andha_close_ext>ha_open_ext
z2:=b
// Berechne z3, wenn z1 und z2 gültig sind
ifnotna(z1)andnotna(z2)
z3:=(z1+z2)/2
// Entry-Logik
iftradeDirection==”Long”ortradeDirection==”Long and Short”
ifha_close_curr>z3
strategy.entry(“Long”,strategy.long)
iftradeDirection==”Short”ortradeDirection==”Long and Short”
ifha_close_curr<z3
strategy.entry(“Short”,strategy.short)
// Exit-Logik basierend auf z3
ifnotna(z3)
ifclose>z3
strategy.close(“Short”)
ifclose<z3
strategy.close(“Long”)
z1_plot:=z1
z2_plot:=z2
else
strategy.close(“Long”)
strategy.close(“Short”)
label.new(bar_index,high,”No Live Trading”,color=color.red,textcolor=color.white,style=label.style_label_down)
// Plotting
plot(z1_plot, title=”z1 – Höchster Wert”, color=color.blue, linewidth=2, style=plot.style_stepline)
plot(z2_plot, title=”z2 – Tiefster Wert”, color=color.red, linewidth=2, style=plot.style_stepline)
plot(z3, title=”z3 – Mitte von z1 und z2″, color=color.gray, linewidth=2, style=plot.style_line)