0
votes

I want to plot difference between current Heikin Ashi (HA) close price and real close price (on normal candles) in Pine script 3.

Seems like it can work if I use normal candles on chart but if I use Heikin Ashi, I get HA close price instead of normal one.

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)

The code above is expected to draw two lines in front of last candle, showing HA close and normal close. It does if chart is set to normal candles, but on HA candles those have same value -- HA close. Same if I use just close.

Is there a way to explicitly address price on normal candles?

1
I don't think it is possible to refer normal candle prices when you are using a different kind of candlestick type. I have gone through the reference manual and couldn't find a built-in variable for that.Baris Yakut
I was able to get real price by hardcoding tickerid into security: security("BITMEX:ETHUSD", period, close). Maybe HA changes tickerid somehow? I could parse it back maybe but not sure if Pine is capable of it. Maybe construct tickerid out of ticker and something else?Helyrk

1 Answers

1
votes

After reading the comments I was able to hack it using 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))

I tried to make the interval automatic as well, but I was not successful since the interval variable only returns interval multiplier, so it behaved strangely on some timeframes.

I tested this on BITMEX:ETHUSD daily chart - if you have a look at 12th June 2019 with HA candles selected you can see that the actual close is 263.05 (green number) while the HA close is 254.00 (red number).

example