Pine Script. Heinkin Ashi Candles source

Viewed 34

I've been testing a strategy based on Heikin Ashi(HA) Candles, I tried three different sources of HA candles, one using code to do the math, and other two using the security function. All three had different results. I would like to know what is the most reliable one, and if anyone knows why the difference between them.

Follow the code:

  1. From security
Heikin Ashi from Security
UseHAcandles    = input(true, title="Use Heikin Ashi Candles in Algo Calculations")
hkClose = UseHAcandles ? request.security(ticker.heikinashi(syminfo.tickerid),
timeframe.period, close) : close
hkOpen  = UseHAcandles ? request.security(ticker.heikinashi(syminfo.tickerid),
timeframe.period, open) : open
hkHigh  = UseHAcandles ? request.security(ticker.heikinashi(syminfo.tickerid),
timeframe.period, high) : high
hkLow   = UseHAcandles ? request.security(ticker.heikinashi(syminfo.tickerid),
timeframe.period, low) : low
  1. From security

[hkOpen, hkHigh, hkLow, hkClose] = request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, [open, high, low, close])

  1. From math
hkClose         = (open + high + low + close) / 4
hkOpen          = (open[1] + close[1]) / 2     
hkHigh          = math.max(high, math.max(hkOpen, hkClose))
hkLow           = math.min(low,  math.min(hkOpen, hkClose))
1 Answers
Related