pinescript meldet kompilierungsfehler in dieser st...
Créé le : 15 juin 2025
Créé le : 15 juin 2025
pinescript meldet kompilierungsfehler in dieser strategie: //@version=5
strategy(title = "UT-Bot Strategie (mit SL & Trailing)",overlay = true,initial_capital = 1000,default_qty_type = strategy.percent_of_equity,default_qty_value = 10)
// ======= Eingaben ============================================================
sens = input.int(1, "Key-Wert (Sensitivität)", minval = 1)
atrPeriod = input.int(10, "ATR-Periode", minval = 1)
useHA = input.bool(false,"Heikin-Ashi-Quelle nutzen?")
stopLossPct = input.float(1.5, "Fixer Stop-Loss [%]", minval = 0.1, step = 0.1)
trailPct = input.float(1.0, "Trailing-Stop [%]", minval = 0.1, step = 0.1)
// ======= Heikin-Ashi oder normale Quelle wählen =============================
haClose() =>
request.security(heikinashi(syminfo.tickerid), timeframe.period, close)
src = useHA ? haClose() : close
// ======= UT-Bot Kernindikator ===============================================
atr = ta.atr(atrPeriod)
nLoss = sens * atr
// Gleitender ATR-Stopp
var float atrStop = na
atrStop := src > nz(atrStop[1], 0) and src[1] > nz(atrStop[1], 0) ? math.max(nz(atrStop[1]), src - nLoss) :
src < nz(atrStop[1], 0) and src[1] < nz(atrStop[1], 0) ? math.min(nz(atrStop[1]), src + nLoss) :
src > nz(atrStop[1], 0) ? src - nLoss : src + nLoss
// Positionsrichtung merken
var int pos = 0
pos := src[1] < nz(atrStop[1], 0) and src > nz(atrStop[1], 0) ? 1 :
src[1] > nz(atrStop[1], 0) and src < nz(atrStop[1], 0) ? -1 :
nz(pos[1])
// EMA-Filter (wie im Original)
ema1 = ta.ema(src, 1)
above = ta.crossover(ema1, atrStop)
below = ta.crossover(atrStop, ema1)
// Signale
longSignal = src > atrStop and above
shortSignal = src < atrStop and below
// ======= Ein- & Ausstiege mit SL & Trailing ================================
// Long Entry
if longSignal
strategy.entry(id = "Long", direction = strategy.long)
// Short Entry
if shortSignal
strategy.entry(id = "Short", direction = strategy.short)
// Exit Long mit SL und Trailing
if strategy.position_size > 0
float stopPrice = strategy.position_avg_price * (1 - stopLossPct / 100)
float trailPts = trailPct / 100 * close
strategy.exit(id = "L-Exit", from_entry = "Long", stop = stopPrice, trail_points = trailPts)
// Exit Short mit SL und Trailing
if strategy.position_size < 0
float stopPrice = strategy.position_avg_price * (1 + stopLossPct / 100)
float trailPts = trailPct / 100 * close
strategy.exit(id = "S-Exit", from_entry = "Short", stop = stopPrice, trail_points = trailPts)
// ======= Visualisierung im Chart ============================================
plot(atrStop, "ATR-Trailing-Stop", color = color.gray)
plotshape(longSignal, "Long-Signal", shape.labelup, location.belowbar,
color = color.green, text = "Buy", textcolor = color.white, size = size.tiny)
plotshape(shortSignal, "Short-Signal", shape.labeldown, location.abovebar,
color = color.red, text = "Sell", textcolor = color.white, size = size.tiny)
barcolor(pos == 1 ? color.new(color.green, 80) : pos == -1 ? color.new(color.red, 80) : na)
und zwar folgendes: Could not find function or function reference 'heikinashi' und Die Pine Script®-Version 5 ist veraltet. Verwenden Sie bitte die aktuelle Version 6.(PINE_VERSION_OUTDATED). kannst du das korrigieren und eine komplette darstellen?
Hier ist die bereinigte und auf Pine-Script v6 umgestellte Version.
Die zwei Ursachen für die Fehlermeldungen waren
//@version=6
ticker.heikinashi()
statt heikinashi()
pinescript//@version=6 strategy( title = "UT-Bot Strategie (mit SL & Trailing)", overlay = true, initial_capital = 1000, default_qty_type = strategy.percent_of_equity, default_qty_value = 10) // ========= Eingaben ========================================================= sens = input.int(1, "Key-Wert (Sensitivität)", minval = 1) atrPeriod = input.int(10, "ATR-Periode", minval = 1) useHA = input.bool(false,"Heikin-Ashi-Quelle nutzen?") stopLossPct = input.float(1.5, "Fixer Stop-Loss [%]", minval = 0.1, step = 0.1) trailPct = input.float(1.0, "Trailing-Stop [%]", minval = 0.1, step = 0.1) // ========= Heikin-Ashi- oder normale Quelle wählen ========================== haClose() => request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, close) src = useHA ? haClose() : close // ========= UT-Bot Kernindikator ============================================ atr = ta.atr(atrPeriod) nLoss = sens * atr // Gleitender ATR-Stopp var float atrStop = na atrStop := src > nz(atrStop[1]) and src[1] > nz(atrStop[1]) ? math.max(nz(atrStop[1]), src - nLoss) : src < nz(atrStop[1]) and src[1] < nz(atrStop[1]) ? math.min(nz(atrStop[1]), src + nLoss) : src > nz(atrStop[1]) ? src - nLoss : src + nLoss // Positions-Richtung merken var int pos = 0 pos := src[1] < nz(atrStop[1]) and src > nz(atrStop[1]) ? 1 : src[1] > nz(atrStop[1]) and src < nz(atrStop[1]) ? -1 : nz(pos[1]) // EMA-Filter (wie im Original) ema1 = ta.ema(src, 1) above = ta.crossover(ema1, atrStop) below = ta.crossover(atrStop, ema1) // Signale longSignal = src > atrStop and above shortSignal = src < atrStop and below // ========= Trades + SL / Trailing ========================================== // Long-Entry if longSignal strategy.entry("Long", strategy.long) // Short-Entry if shortSignal strategy.entry("Short", strategy.short) // Exit Long if strategy.position_size > 0 stopPrice = strategy.position_avg_price * (1 - stopLossPct / 100) trailPts = trailPct / 100 * close strategy.exit("L-Exit", from_entry = "Long", stop = stopPrice, trail_points = trailPts) // Exit Short if strategy.position_size < 0 stopPrice = strategy.position_avg_price * (1 + stopLossPct / 100) trailPts = trailPct / 100 * close strategy.exit("S-Exit", from_entry = "Short", stop = stopPrice, trail_points = trailPts) // ========= Visualisierung =================================================== plot(atrStop, "ATR-Trailing-Stop", color=color.gray) plotshape(longSignal, title="Long-Signal", shape=shape.labelup, location=location.belowbar, color=color.green, text="Buy", textcolor=color.white, size=size.tiny) plotshape(shortSignal, title="Short-Signal", shape=shape.labeldown, location=location.abovebar, color=color.red, text="Sell", textcolor=color.white, size=size.tiny) barcolor(pos == 1 ? color.new(color.green, 80) : pos == -1 ? color.new(color.red, 80) : na)
Einfach kopieren, auf TradingView einfügen und kompilieren – die Fehler sollten verschwunden sein. Viel Erfolg beim Testen!