【发布时间】:2021-03-02 17:32:59
【问题描述】:
我正在尝试将 TradingView 的股票 ATR 停止脚本(内置于 Pine Script v1 中)集成到我自己的 v4 代码中,这导致错误“输入语法错误'行尾没有行继续'的 iff以下陈述。
有人可以帮我将这些行翻译成 v4 兼容的代码吗? ????????????????????????
注意:正如帖子标题所暗示的,此代码有效,但仅在 Pine Script v1 中,我正在尝试将其调整为 v4,我认为它需要 if else 语句而不是 iff 语句。
//@version=1
study(title="ATR Stop", overlay = true)
nATRPeriod = input(5)
nATRMultip = input(2.5)
xATR = atr(nATRPeriod)
nLoss = nATRMultip * xATR
xATRTrailingStop = iff(close > nz(xATRTrailingStop[1], 0) and close[1] > nz(xATRTrailingStop[1], 0), max(nz(xATRTrailingStop[1]), close - nLoss),
iff(close < nz(xATRTrailingStop[1], 0) and close[1] < nz(xATRTrailingStop[1], 0), min(nz(xATRTrailingStop[1]), close + nLoss),
iff(close > nz(xATRTrailingStop[1], 0), close - nLoss, close + nLoss)))
pos = iff(close[1] < nz(xATRTrailingStop[1], 0) and close > nz(xATRTrailingStop[1], 0), 1,
iff(close[1] > nz(xATRTrailingStop[1], 0) and close < nz(xATRTrailingStop[1], 0), -1, nz(pos[1], 0)))
color = pos == -1 ? red: pos == 1 ? green : blue
plot(xATRTrailingStop, color=color, title="ATR Trailing Stop")
【问题讨论】:
-
Pine 代码以 4 个空格为增量缩进。如果代码在同一个缩进“级别”,它被认为是一个单独的命令。如果缩进一个空格,它被认为是上一行的一部分。你应该在最后一行缩进你的
iff,再加一个空格,就像你在第二行缩进iff一样。 -
谢谢我试了一下,但我仍然在上面代码的第一行收到“输入语法错误'没有行继续'的行尾”:(
-
请更新您的问题以包含完整的脚本,而不仅仅是此代码 sn-p。这将有助于调查问题。
-
已更新以包含完整的脚本????????
标签: pine-script