0

我不明白是什么导致了这里的问题。我检查了我在函数中放入的参数,我检查了所有参数和函数是否相互兼容,但我仍然不知道如何解决这个问题。谁能帮我解决这个问题?

我在下面提到了我的代码,以便您检查它以找到问题。

非常感谢施希尔

// This source code is subject to the terms of the Mozilla Public License 2.0 at`https://mozilla.org/MPL/2.0/
// © shishirshrivastava911

//@version=5
strategy("RSI Divergence - Trend Reversal", overlay=true, margin_long=20, margin_short=20)

// Strategy Settings
lookback = input(title="Lookback:", defval=7)
rsiOB = input(title="RSI Overbought Level", defval=80)
rsiOS = input(title="RSI Oversold Level", defval=20)
rsiLen = input(title="RSI Length", defval=7)
rsiSrc = input(title="RSI Source", defval=close)

// Get RSI Value
rsi = ta.rsi(rsiSrc, rsiLen)
rsisell = rsi > rsiOB
rsibuy = rsi < rsiOS

// Determine Buy/Sell Signals
buysignal1 = (rsibuy or rsibuy[1]) and
     close[1] < open[1] and close > open[1] and low > low[1] and low[1] < low [2] and
     low[1] == ta.lowest(low,lookback) and open <= close[1]
buysignal2 = (rsibuy or rsibuy[1]) and
     close[1] < open[1] and close > open[1] and low < low[1] and
     low == ta.lowest(low,lookback) and open <= close[1]
sellsignal2 = (rsisell or rsisell[1]) and
     close[1] > open[1] and close < open[1] and high > high[1] and
     high == ta.highest(high,lookback) and open >= close[1]
sellsignal1 = (rsisell or rsisell[1]) and
     close[1] > open[1] and close < open[1] and high < high[1] and high[1] > high[2] and
     high[1] == ta.highest(high,lookback) and open >= close[1]

// Buy/Sell Triggers
bool buysignal = buysignal1 or buysignal2
bool sellsignal = sellsignal1 or sellsignal2

// Paint Signals
bgcolor(buysignal1 ? color.lime : sellsignal1 ? color.red : color.new(na,0), title="123 Fractal")
bgcolor(buysignal1 ? color.lime : sellsignal1 ? color.red : color.new(na,0), title="Swing Fractal") 
plot(rsi, title="RSI", color=rsisell ? color.red : rsibuy ? color.lime : na)
plot(rsiOB, title="RSI Overbought", color=color.new(color.red,0))
plot(rsiOS, title="RSI Oversold", color=color.new(color.green, transp=0))

// Strategy to Exit a Trade
atr = ta.atr(7)
rrr = input(2, "Risk Reward Ratio (RRR)")
float exitTickCount = (atr[1]*rrr)/0.05
float stopLossTickCount = (atr[1]/0.05)

// Trade Number of the Day
trade_num = strategy.opentrades-1
trade_num_str = str.tostring(trade_num)

// Entry Price of the Trade
float entry_price = strategy.opentrades.entry_price(trade_num)

// Long Trade Close and Stop Signals
bool longClose = (close > (entry_price + exitTickCount))
longStop = entry_price - stopLossTickCount

//Long Trade Entry and Close
strategy.entry("Enter Long", strategy.long, 100, when = buysignal, stop = longStop)
strategy.close("Entry Long", strategy.long, qty = 100, when = longClose)

// Short Trade Close and Stop Signals
bool shortClose = (close < (entry_price - exitTickCount))
shortStop = entry_price + stopLossTickCount

// Short Trade Entry and Close
strategy.entry("Enter Short", strategy.short, 100, when = sellsignal, stop = shortStop)
strategy.close("Entry Short", strategy.short, qty = 100, when = shortClose)
4

1 回答 1

0

您不能将strategy.longstrategy.short参数传递给strategy.close()函数。可能是复制/粘贴错误。删除它们,你就很好了。

strategy.close("Entry Long", when = longClose, qty = 100)
strategy.close("Entry Short", qty = 100, when = shortClose)
于 2022-01-22T20:59:58.207 回答