Pinescript V2到V4转换,不能与自引用变量转换

发布于 2025-01-22 16:15:26 字数 1824 浏览 3 评论 0 原文

我正在尝试将我的pine脚本版本2指示器转换为版本4,因此我发布了它,但是它使用了一个自我引用变量,它们在版本3中删除了它。要求解它页面我将在底部链接,但我无法弄清楚如何正确包装它。如果有人可以帮助我包装这个公式,将不胜感激。先感谢您。

这是代码。自我引用变量在第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")```

I'm trying to convert my Pine script version 2 indicator to version 4 so I publish it, but it uses a self-referencing variable which they got rid of in version 3. To solve it it needs to be wrapped as stated in the reference page I will link at the bottom, but I cant figure out how to properly wrap it. If anyone could help me wrap this formula it would be greatly appreciated. Thank you in advance. https://www.tradingview.com/pine-script-docs/en/v5/migration_guides/To_Pine_version_3.html#

Here is the code. The self-referencing variable is on line 33 (BSsum) and uses line 9 as part of its formula.

// © 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")```

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一个人的旅程 2025-01-29 16:15:26

它不必包装,如果要在 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")

It doesn't have to be wrapped, wrapping variables inside functions is necessary if you want to pass these mutable variables inside the security(). Your variable is based on data from security, but it isn't passed to it.

To make the script work in v4, you need to first declare the variable, and then assign it a new value via the := operator:

// © 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")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文