【发布时间】:2021-11-25 04:27:22
【问题描述】:
我一直在尝试基于 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")
【问题讨论】:
标签: pine-script cryptocurrency