两种证券之间的自定义关系
CUSTOM RELATIVE between two securities
有一项研究在两个符号之间建立一个 RELATIVE 是这样的:
`
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)
`
这很适合用 SPY 做亲戚。但我想在 Pine 中自定义除数。例如,根据主动证券的行业,我想在 PINE 中选择合适的行业 ETF(我试过使用 if...else)。我是 PINE 编程的新手,我做不到。我一直在寻找类似的公式,但没有找到。这就是我所做的,它说:“输入不匹配 'b' 期望 '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)
`
感谢您的帮助
Pine Script中的inputs
在运行时不能改变,应该在编译阶段就知道了。此外, request.security()
函数只接受 symbol=
参数的简单字符串形式,因此示例中的可变 b 变量与安全函数不兼容.
您可以使用三元 ?:
运算符并硬核 b 的值,而不是在运行时无法从 Pine 脚本更改的输入使其与安全调用兼容。下面的脚本使用 Pine Script 版本 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)
终于解决了。只需将此行添加到@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])
有一项研究在两个符号之间建立一个 RELATIVE 是这样的:
`
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)
`
这很适合用 SPY 做亲戚。但我想在 Pine 中自定义除数。例如,根据主动证券的行业,我想在 PINE 中选择合适的行业 ETF(我试过使用 if...else)。我是 PINE 编程的新手,我做不到。我一直在寻找类似的公式,但没有找到。这就是我所做的,它说:“输入不匹配 'b' 期望 '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)
`
感谢您的帮助
Pine Script中的inputs
在运行时不能改变,应该在编译阶段就知道了。此外, request.security()
函数只接受 symbol=
参数的简单字符串形式,因此示例中的可变 b 变量与安全函数不兼容.
您可以使用三元 ?:
运算符并硬核 b 的值,而不是在运行时无法从 Pine 脚本更改的输入使其与安全调用兼容。下面的脚本使用 Pine Script 版本 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)
终于解决了。只需将此行添加到@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])