pinescript meldet kompilierungsfehler in dieser st...

Créé le : 15 juin 2025

Répondu en utilisant O3 par Chat01

Question

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?

Réflexion

Handling Pine Script variable declarations

It seems I had to make some changes to avoid issues with variable declarations in Pine Script. In version v5, I could declare variables like float stopPrice inside blocks, but now I need to be more cautious with type inference. I didn’t need the float type declaration inside the if block, so I removed it. I made sure to declare the variables before the trade exit condition to prevent errors with scope and overshadowing — which would mess

Thought for 25 seconds

Réponse

Hier ist die bereinigte und auf Pine-Script v6 umgestellte Version.
Die zwei Ursachen für die Fehlermeldungen waren

  1. veraltete Skript-Version//@version=6
  2. geänderter Funktionsnameticker.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!

Partager cette Q&R