两种证券之间的定制亲戚

发布于 2025-01-22 16:53:56 字数 881 浏览 2 评论 0原文

有一项研究可以在两个符号之间建立亲戚:

`

study("RELATIVE STRENGTH", shorttitle="RS") 
a = tickerid 
b = input("SPY", type=symbol) 
as = security(a, period, close) 
bs = security(b, period, close) 
plot(as/bs, title="RS", color=blue)

`

这可以用间谍做亲戚。但是我想使Divisor可以在松树中自定义。例如,根据活动安全性的扇区,我想在适当的部门ETF中选择(我尝试使用If ... else)。我是Pine编程的新手,我无法做到。我已经寻找了一个同样的公式,但我没有找到它。这就是我所做的,它说:“不匹配的输入'B'期望'在没有线路的情况

`

//@version=2

study("RELATIVE STRENGTH", shorttitle="RS") 
a = ticker    // or tickerid ???
//b = input("SPX500USD", type=symbol) 

if a == "AAPL"  
     b := input("XLK", type=symbol) 
     
    else if a == "AMZN"
        b := input("XLY", type=symbol) 
    
    else
        b := input("SPY", type=symbol) 

as = security(a, period, close) 
bs = security(b, period, close) 
plot(as/bs, title="RS", color=blue)

'

there is a Study to build a RELATIVE between two symbols that is like this:

`

study("RELATIVE STRENGTH", shorttitle="RS") 
a = tickerid 
b = input("SPY", type=symbol) 
as = security(a, period, close) 
bs = security(b, period, close) 
plot(as/bs, title="RS", color=blue)

`

This works fine to do relatives with SPY. But I would like to make the divisor customizable in Pine. for example, depending on the sector of the active security, I would like to choose in PINE the appropriate sector ETF(I have tried using if...else). I am new to programming in PINE, and I cannot make it . I have looked for a simmilar formula but I do not find it. This is what I have done and it says: "Mismatched input 'b' expecting 'end of line without line continuation'

`

//@version=2

study("RELATIVE STRENGTH", shorttitle="RS") 
a = ticker    // or tickerid ???
//b = input("SPX500USD", type=symbol) 

if a == "AAPL"  
     b := input("XLK", type=symbol) 
     
    else if a == "AMZN"
        b := input("XLY", type=symbol) 
    
    else
        b := input("SPY", type=symbol) 

as = security(a, period, close) 
bs = security(b, period, close) 
plot(as/bs, title="RS", color=blue)

`

thank you for your help

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

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

发布评论

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

评论(2

尘曦 2025-01-29 16:53:56

Pine脚本中的输入在运行时无法更改,应在编译阶段知道。此外,request.security()函数仅接受symbol =参数的简单形式的字符串,因此您的可变 b 变量示例与安全功能不兼容。

您可以在运行时与Pine脚本更改,而不是输入,您可以使用Ternary ?:运算符和 b 的硬核使其与安全电话。下面的脚本使用Pine脚本版本5编译器指令:

//@version=5

indicator("RELATIVE STRENGTH", shorttitle="RS") 
ticker = syminfo.ticker
var string b = ticker == "AAPL" ? "XLK" : ticker == "AMZN" ? "XLY" : "SPY"

secA = request.security(ticker, timeframe.period, close) 
secB = request.security(b, timeframe.period, close) 
plot(secA/secB, title="RS", color=color.blue)

The inputs in Pine Script could not change during the runtime and should be known at the compilation stage. Moreover, the request.security() function accepts only a simple form of strings for the symbol= argument, hence the mutable b variable in your example is not compatible with the security functions.

Instead of input, that could not be changed from the Pine script during the runtime, you can use the ternary ?: operator and hardcore the values for b to make it compatible with the security calls. The script below uses the Pine Script version 5 compiler directive:

//@version=5

indicator("RELATIVE STRENGTH", shorttitle="RS") 
ticker = syminfo.ticker
var string b = ticker == "AAPL" ? "XLK" : ticker == "AMZN" ? "XLY" : "SPY"

secA = request.security(ticker, timeframe.period, close) 
secB = request.security(b, timeframe.period, close) 
plot(secA/secB, title="RS", color=color.blue)
时间你老了 2025-01-29 16:53:56

最后,我能够解决它。只需将此行添加到 @e2e4代码中

myLabel = label.new(bar_index[0],secA/secB ,"/"+str.tostring(b), color = color.white, style = label.style_label_left, textcolor = color.blue, size=size.normal )

label.delete(myLabel[1])

Finally I was able to solve it . Just add this lines to the @e2e4 code

myLabel = label.new(bar_index[0],secA/secB ,"/"+str.tostring(b), color = color.white, style = label.style_label_left, textcolor = color.blue, size=size.normal )

label.delete(myLabel[1])
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文