study("ZTrend", shorttitle="Z_HA", overlay=false)
O = ema(open,3)
H = ema(high,3)
L = ema(low,3)
C = ema(close,3)
haclose = (O + H + L + C) / 4
haopen = na(haopen[1]) ? (O + C) / 2 : (haopen[1] + haclose[1]) / 2
hahigh = max(H, max(haopen, haclose))
halow = min(L, min(haopen, haclose))
plotcandle(haopen, hahigh, halow, haclose, title='Mod_HA', color=(haopen < haclose) ? green : red, wickcolor=gray)