如何在使用 Heikin Ashi 蜡烛时获得 Pine 脚本中普通蜡烛的收盘价?

How to get close price for normal candles in Pine script while using Heikin Ashi candles?

我想在 Pine 脚本 3 中绘制当前 Heikin Ashi (HA) 收盘价和实际收盘价(在普通蜡烛上)之间的差异。

如果我在图表上使用普通蜡烛似乎可以工作,但如果我使用 Heikin Ashi,我得到的是 HA 收盘价而不是普通蜡烛。

HAclose = security(heikinashi(tickerid), period, close)
NormalClose = security(tickerid, period, close)

plot(HAclose, offset=1, show_last=1)
plot(NormalClose, offset=1, show_last=1)

上面的代码应该在最后一根蜡烛前画两条线,显示 HA 收盘价和正常收盘价。如果图表设置为普通蜡烛,它会这样做,但在 HA 蜡烛上,它们具有相同的值 -- HA 关闭。如果我只使用 close.

也是一样

有没有办法明确解决普通蜡烛的价格问题?

阅读评论后,我可以使用 syminfo.prefix and ticker

破解
//@version=3
study("Actual price for HA candles") //, overlay=false)
selected_interval = input(title="Interval", defval="D", type=resolution)
// selected_interval = tostring(interval)

actual_close = plot(security(syminfo.prefix + ":" + ticker, selected_interval, close), color=green)
HA_close = plot(security(tickerid, selected_interval, close), color=red)

fill(actual_close, HA_close, color=color(purple,0))

我也尝试将间隔设置为自动,但我没有成功,因为 interval 变量只有 returns 间隔乘数,所以它在某些时间范围内表现得很奇怪。

我在 BITMEX:ETHUSD 日线图上对此进行了测试 - 如果您查看 2019 年 6 月 12 日并选择了 HA 蜡烛,您可以看到实际收盘价为 263.05(绿色数字),而 HA 收盘价为 254.00(红色数字)。

realPrice = request.security(ticker.new(syminfo.prefix, syminfo.ticker), timeframe.period, close)

v5

编辑说明:

在 Heikin Ashi 图表上,close 价格是 Heikin Ashi 的计算结果,而不是普通蜡烛的收盘价。 security 函数 returns 任何股票代码和任何时间范围的收盘价。

示例:在 AAPL 图表上获取时间范围 5 的收盘价

realPrice = request.security("AAPL", "5", close)

不用输入“AAPL”,而是通过以下方式获取当前代码:

currentTicker = ticker.new(syminfo.prefix, syminfo.ticker)

而不是输入“5”获取当前时间范围:

currentTimeframe = timeframe.period

决赛:

realPrice = request.security(currentTicker, currentTimeframe, close)