Ich habe alles versucht, aber es gibt mir immer noch diesen Fehler: " line 27: Syntax error at input 'i'. " Es scheint auch keine Einrückungsprobleme zu geben.
Hilfe bitte. Vielen Dank im Voraus.
'''
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © VaheHV
//@version=5
strategy("Momentum Signal", overlay=true)
ema12 = ta.ema(close, 12)
ema26 = ta.ema(close, 26)
ema9 = ta.ema(close, 9)
macdLine = ema12 - ema26
macdSignal = ta.ema(macdLine, 9)
crossover = ta.crossover(macdLine, macdSignal)
crossunder = ta.crossunder(macdLine, macdSignal)
if crossover and macdLine < 0 and macdSignal < 0 and close > ta.ema(close, 200)
strategy.entry("Long", strategy.long)
if crossunder and macdLine > 0 and macdSignal > 0 and close < ta.ema(close, 200)
strategy.entry("Short", strategy.short)
float[] longStopLoss = na
float[] longTakeProfit = na
float[] shortStopLoss = na
float[] shortTakeProfit = na
if strategy.opentrades!= 0
for i = 0 to strategy.opentrades - 1
if strategy.position_size > 0
array.push(longStopLoss, ta.lowest(low, 15))
array.push(longTakeProfit, (1.5*(strategy.opentrades.entry_price(i) - longStopLoss[i]) + strategy.opentrades.entry_price(i)))
strategy.exit("LongClose", profit = longTakeProfit[i] * 100, loss = longStopLoss[i] * 100)
else if strategy.position_size < 0
array.push(shortStopLoss, ta.highest(high, 15))
array.push(shortTakeProfit, (strategy.opentrades.entry_price(i) - 1.5*(shortStopLoss[i] - strategy.opentrades.entry_price(i)))
strategy.exit("ShortClose", profit = shortTakeProfit[i] * 100, loss = shortStopLoss[i] * 100)
'''
Lösung des Problems
[]
in pinescript
heißt Verlaufsreferenzoperator. Es wird verwendet, um auf historische Daten einer Variablen zuzugreifen.
Sie verwenden nicht, []
um auf Array-Elemente zuzugreifen. Stattdessen sollten Sie dafür die array.get()
Funktion verwenden.
Außerdem fehlt in der unteren Zeile eine schließende Klammer. Überprüfen Sie also diese Zeile in meinem Beispiel.
array.push(shortTakeProfit, (strategy.opentrades.entry_price(i) - 1.5*(shortStopLoss[i] - strategy.opentrades.entry_price(i)))
Das sollte funktionieren:
if strategy.opentrades!= 0
for i = 0 to strategy.opentrades - 1
if strategy.position_size > 0
array.push(longStopLoss, ta.lowest(low, 15))
array.push(longTakeProfit, (1.5*(strategy.opentrades.entry_price(i) - array.get(longStopLoss, i)) + strategy.opentrades.entry_price(i)))
strategy.exit("LongClose", profit = array.get(longTakeProfit, i) * 100, loss = array.get(longStopLoss, i) * 100)
else if strategy.position_size < 0
array.push(shortStopLoss, ta.highest(high, 15))
array.push(shortTakeProfit, (strategy.opentrades.entry_price(i) - 1.5*(array.get(shortStopLoss, i) - strategy.opentrades.entry_price(i))))
strategy.exit("ShortClose", profit = array.get(shortTakeProfit, i) * 100, loss = array.get(shortStopLoss, i) * 100)
Keine Kommentare:
Kommentar veröffentlichen