返回"Script could not be translated from: null"错误



代码如下:

'//@version=2'
// Lookback period for calculating the Moving Average
length = input(20, minval=1)
// Breakout level
breakout = input(2)
// Moving Average
sma = sma(close, length)
// Calculate the distance between the current price and the Moving Average
distance = abs(close - sma)
// Check if the distance is greater than the breakout level
if (distance > breakout)
strategy.entry("Long", strategy.long)
strategy.exit("Close Long", "Long", stop=sma)

if (distance > breakout) and (close > sma)
if (distance < breakout) or (close < sma)
strategy.close("Long")
takeProfit = input(5)
strategy.exit("Take Profit", "Long", limit=sma + takeProfit)
stopLoss = input(3)
strategy.exit("Stop Loss", "Long", stop=sma - stopLoss)

当我尝试在tradingview上运行它时,我得到错误"Script无法从:null"我是全新的,所以我不知道如何解决这个问题。我应该改变什么?

我试着改变和添加不同的行,但没有工作到目前为止。再说一遍,我是新来的。

您的脚本必须有一个study()strategy()调用。在你的例子中是strategy()

strategy("test")添加到脚本中,它将工作。

注意:你有一个空的if语句,所以如果你不使用它,你应该把它也删除。