【问题标题】:Pine script returns "Syntax error at input 'strategy.long'."Pine 脚本返回“输入 'strategy.long' 处的语法错误。”
【发布时间】: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


    【解决方案1】:
    var price = 0.0
    if (b and k > OverSold) and strategy.position_size == 0
        price := close
        strategy.entry("buy", strategy.long, comment="Buy")
    

    我删除了“id=”并且它起作用了。

    【讨论】:

    • 非常感谢!!代码不能完成这项工作,但至少它现在可以工作了
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-27
    • 1970-01-01
    • 2022-10-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多