松脚本 returns "Syntax error at input 'strategy.long'."
Pine script returns "Syntax error at input 'strategy.long'."
我一直在尝试基于 Stoch RSI 制定一个新的简单策略,并通过这个简单的代码取得了成功
strategy("Long Strategy", overlay=true)
length = input.int(10, minval=1)
OverBought = input(85)
OverSold = input(5)
smoothK = 3
smoothD = 3
k = ta.sma(ta.stoch(close, high, low, length), smoothK)
d = ta.sma(k, smoothD)
b = ta.crossover(k,OverSold)
s = ta.crossunder(d,OverBought)
strategy.entry("Buy", strategy.long, when=(b and k > OverSold), comment="Buy")
strategy.close("Buy", when=(s and d < OverBought), comment="Sell")
但我想对其进行编辑,以便 strategy.close 只有在高于入场价时才会履行。所以,我编辑了代码,我一直试图找出第 17 行的问题,但我似乎做不到。
错误显示“第 17 行:输入 'strategy.long' 处出现语法错误。”
编辑后的代码如下:
strategy("Stoch. RSI", format=format.price, overlay=true)
length = input.int(10, minval=1)
OverBought = input(85)
OverSold = input(5)
smoothK = 3
smoothD = 3
k = ta.sma(ta.stoch(close, high, low, length), smoothK)
d = ta.sma(k, smoothD)
b = ta.crossover(k,OverSold)
s = ta.crossunder(d,OverBought)
var price = 0.0
if (b and k > OverSold) and strategy.position_size == 0
price := close`
strategy.entry(id="buy", strategy.long , comment="Buy")
if (s and d < OverBought) and (price > close)
strategy.close(id="buy", comment="Sell")
var price = 0.0
if (b and k > OverSold) and strategy.position_size == 0
price := close
strategy.entry("buy", strategy.long, comment="Buy")
我删除了“id=”,它起作用了。
我一直在尝试基于 Stoch RSI 制定一个新的简单策略,并通过这个简单的代码取得了成功
strategy("Long Strategy", overlay=true)
length = input.int(10, minval=1)
OverBought = input(85)
OverSold = input(5)
smoothK = 3
smoothD = 3
k = ta.sma(ta.stoch(close, high, low, length), smoothK)
d = ta.sma(k, smoothD)
b = ta.crossover(k,OverSold)
s = ta.crossunder(d,OverBought)
strategy.entry("Buy", strategy.long, when=(b and k > OverSold), comment="Buy")
strategy.close("Buy", when=(s and d < OverBought), comment="Sell")
但我想对其进行编辑,以便 strategy.close 只有在高于入场价时才会履行。所以,我编辑了代码,我一直试图找出第 17 行的问题,但我似乎做不到。
错误显示“第 17 行:输入 'strategy.long' 处出现语法错误。”
编辑后的代码如下:
strategy("Stoch. RSI", format=format.price, overlay=true)
length = input.int(10, minval=1)
OverBought = input(85)
OverSold = input(5)
smoothK = 3
smoothD = 3
k = ta.sma(ta.stoch(close, high, low, length), smoothK)
d = ta.sma(k, smoothD)
b = ta.crossover(k,OverSold)
s = ta.crossunder(d,OverBought)
var price = 0.0
if (b and k > OverSold) and strategy.position_size == 0
price := close`
strategy.entry(id="buy", strategy.long , comment="Buy")
if (s and d < OverBought) and (price > close)
strategy.close(id="buy", comment="Sell")
var price = 0.0
if (b and k > OverSold) and strategy.position_size == 0
price := close
strategy.entry("buy", strategy.long, comment="Buy")
我删除了“id=”,它起作用了。