请为我修复此代码,我正在尝试在 Tradeviewer pine 编辑器上运行它

问题描述 投票:0回答:0

所以我尝试在 tradeview.com 上的 pine 编辑器上运行这段代码:

//@version=5
strategy(title="High Efficiency Strategy", overlay=true, pyramiding=1, default_qty_value=1, default_qty_type=strategy.percent_of_equity, calc_on_order_fills=true)

// Inputs
long_priority = input(title="Long Priority", type=input.bool, defval=true)
bb_length = input.int(title="Bollinger Bands Length", defval=20, minval=1)
bb_mult = input.float(title="Bollinger Bands Standard Deviations", defval=2, minval=0.1, maxval=5)
sma20 = input.float(title="20 Period SMA", defval=close, minval=1)
sma50 = input.float(title="50 Period SMA", defval=close, minval=1)
rsi_length = input.int(title="RSI Length", defval=14, minval=1, maxval=100)
rsi_oversold = input.int(title="RSI Oversold", defval=30, minval=0, maxval=100)
rsi_overbought = input.int(title="RSI Overbought", defval=70, minval=0, maxval=100)
profit_target = input.float(title="Take Profit %", defval=25, minval=0.1, step=0.1)
stop_loss = input.float(title="Stop Loss %", defval=5, minval=0.1, step=0.1)

// Calculations
sma20_val = ta.sma(close, 20)
sma50_val = ta.sma(close, 50)
bb_upper = ta.bbands(close, bb_length, bb_mult).upperband
bb_lower = ta.bbands(close, bb_length, bb_mult).lowerband
rsi_val = ta.rsi(close, rsi_length)

// Conditions
long_condition = (rsi_val <= rsi_oversold) and (close > sma20_val) and (close > sma50_val) and (close < bb_lower)
short_condition = (rsi_val >= rsi_overbought) and (close < sma20_val) and (close < sma50_val) and (close > bb_upper)

// Trades
if long_priority
    strategy.entry("Buy", strategy.long, when=long_condition)
    strategy.entry("Sell", strategy.short, when=short_condition)
else
    strategy.entry("Sell", strategy.short, when=short_condition)
    strategy.entry("Buy", strategy.long, when=long_condition)

// Exits
strategy.exit("TP/SL", "Buy", limit=close * (1 + profit_target / 100), stop=close * (1 - stop_loss / 100))
strategy.exit("TP/SL", "Sell", limit=close * (1 - profit_target / 100), stop=close * (1 + stop_loss / 100))

// Plotting
plot(sma20_val, title="20 Period SMA", color=color.green)
plot(sma50_val, title="50 Period SMA", color=color.orange)
plot(bb_upper, title="Bollinger Bands Upper", color=color.purple)
plot(bb_lower, title="Bollinger Bands Lower", color=color.yellow)

但每次我解决一件事时,都会出现另一个问题,让我回到开头:如果你能做到这一点,我会亲你

我尝试过使用 ChatGPT 来解决我遇到的问题,但一旦它修复了一件事,它就会恢复原状,无法解决旧问题。

在这里输入。

pine-script-v5 tradingview-api openai-api
© www.soinside.com 2019 - 2024. All rights reserved.