两种证券之间的定制亲戚
有一项研究可以在两个符号之间建立亲戚:
`
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Pine脚本中的
输入
在运行时无法更改,应在编译阶段知道。此外,request.security()
函数仅接受symbol =
参数的简单形式的字符串,因此您的可变 b 变量示例与安全功能不兼容。您可以在运行时与Pine脚本更改,而不是输入,您可以使用Ternary
?:
运算符和 b 的硬核使其与安全电话。下面的脚本使用Pine脚本版本5编译器指令:The
inputs
in Pine Script could not change during the runtime and should be known at the compilation stage. Moreover, therequest.security()
function accepts only a simple form of strings for thesymbol=
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:最后,我能够解决它。只需将此行添加到 @e2e4代码中
Finally I was able to solve it . Just add this lines to the @e2e4 code