PineScript v2到v4转换,不能转换与自我引用变量



我正试图将我的Pine脚本版本2指示器转换为版本4,所以我发布它,但它使用了一个自引用变量,他们在版本3中摆脱了。为了解决这个问题,它需要按照参考页面中所述的包装,我将在底部链接,但我不知道如何正确包装它。如果有人能帮我包装这个公式,我将不胜感激。提前谢谢你。https://www.tradingview.com/pine-script-docs/en/v5/migration_guides/To_Pine_version_3.html

下面是代码。自引用变量在第33行(BSsum),并使用第9行作为其公式的一部分。

// © OasisTrading
//@version=4
study("Rotation Factor: Buy/Sell Pressure", shorttitle="Rotation Factor")
interval = security(syminfo.tickerid, input("1D", title="Reset Interval"), time)
newSession = iff(change(interval), 1, 0)
one = (high > high[1]) and (low > low[1])
two = (high < high[1]) and (low < low[1])
three = (high > high[1]) and (low < low[1])
four = (high < high[1]) and (low > low[1])
five = (high == high[1]) and (low > low[1])
six = (high > high[1]) and (low == low[1])
seven = (high < high[1]) and (low == low[1])
eight = (high == high[1]) and (low < low[1])
//formula
onex = +2 
twox = -2
threex = 0
fourx = 0
fivex = +1
sixx = +1
sevenx = -1 
eightx = -1
formula = (high > high[1]) and (low > low[1]) ? onex : (high < high[1]) and (low < low[1]) ? twox : (high > high[1]) and (low < low[1]) ? threex : (high < high[1]) and (low > low[1]) ? fourx : (high == high[1]) and (low > low[1]) ? fivex : (high > high[1]) and (low == low[1]) ? sixx : (high < high[1]) and (low == low[1]) ? sevenx : (high == high[1]) and (low < low[1]) ? eightx : 0
BuySell = sum(formula, 1)
BSsum : iff(newSession, BuySell, BSsum[1]+BuySell)
Kolor1 = (BSsum > 0)==true
Kolor2 = (BSsum < 0)==true
plot(BSsum, style=plot.style_columns, color=Kolor1?color.green:Kolor2?color.red:na, linewidth=3, transp=0, title="Buy/Sell Pressure")```

不需要包装,如果你想在security()中传递这些可变变量,就必须在函数中包装变量。您的变量基于security的数据,但它没有传递给它。

要使脚本在v4中工作,您需要首先声明变量,然后通过:=操作符为其分配一个新值:

// © OasisTrading
//@version=4
study("Rotation Factor: Buy/Sell Pressure", shorttitle="Rotation Factor")
interval = security(syminfo.tickerid, input("1D", title="Reset Interval"), time)
newSession = iff(change(interval), 1, 0)
one = (high > high[1]) and (low > low[1])
two = (high < high[1]) and (low < low[1])
three = (high > high[1]) and (low < low[1])
four = (high < high[1]) and (low > low[1])
five = (high == high[1]) and (low > low[1])
six = (high > high[1]) and (low == low[1])
seven = (high < high[1]) and (low == low[1])
eight = (high == high[1]) and (low < low[1])
//formula
onex = +2 
twox = -2
threex = 0
fourx = 0
fivex = +1
sixx = +1
sevenx = -1 
eightx = -1
formula = (high > high[1]) and (low > low[1]) ? onex : (high < high[1]) and (low < low[1]) ? twox : (high > high[1]) and (low < low[1]) ? threex : (high < high[1]) and (low > low[1]) ? fourx : (high == high[1]) and (low > low[1]) ? fivex : (high > high[1]) and (low == low[1]) ? sixx : (high < high[1]) and (low == low[1]) ? sevenx : (high == high[1]) and (low < low[1]) ? eightx : 0
BuySell = sum(formula, 1)
BSsum = 0.0
BSsum := newSession ? BuySell : BSsum[1] + BuySell
Kolor1 = (BSsum > 0)==true
Kolor2 = (BSsum < 0)==true
plot(BSsum, style=plot.style_columns, color=Kolor1?color.green:Kolor2?color.red:na, linewidth=3, transp=0, title="Buy/Sell Pressure")

最新更新