Heiking Ashi Candle code

Dear experts,

The EA for Heikin Ashi provided under Artificial Intelligence in PI plots only the CLOSE part of candle. It does not define Open, High and Low parts. Open part is tricky and I seek you help.

The Heikin Ashi candle opening is defined in Stockcharts.com as

HA-Open = (HA-Open(-1) + HA-Close(-1)) / 2 

How can we program this in Tradescript. The problem is Defining HA-Open refers to HA-Open for previous time period. That is:

SET HO = (REF(HO,1) + REF(HC,1))/2

As we are Setting HO for the first time now, how can we have a hitherto undefined HO on RHS also, which is Unreferenced?

Could you please suggest how to code this HA-Open?

Thanks

As per the above query

BuyScript:

SET HC = (OPEN+HIGH+LOW+CLOSE)/4
SET HO = (REF(OPEN,1) + REF(CLOSE,1))/2
SET HH = MAXOF(HIGH, MAXOF(HC, HO))
SET HW = MINOF(LOW, HO, HC)
HC>MAXOF(REF(HH,1),REF(HH,2),REF(HH,3), REF(HH,4)) 

SellScript:

SET HC = (OPEN+HIGH+LOW+CLOSE)/4
SET HO = (REF(OPEN,1) + REF(CLOSE,1))/2
SET HH = MAXOF(HIGH, MAXOF(HC, HO))
SET HW = MINOF(LOW, HO, HC)
HC<MAXOF(REF(HH,1),REF(HH,2),REF(HH,3), REF(HH,4)) 

Brother you will never get his answer especially when it I related to heiken ashi… I am asking him same question since 2 months… He is such a waste. I m sure he is a zerodha staff. Your question is simplest and he is asking you that he didn’t understand it. Instead of simply saying I am not able to code this he is trying to show we are asking him wrong

Dear Sir, you didn’t read my question I think.
I request help in programming HA-Open = (HA-Open(-1) + HA-Close(-1)) / 2
That is, Open of HA Candle is = Average of Previous HEIKEN ASHI candle’s open and close.
What you have suggested is Open of HA Candle = Average of Previous STANDARD candle’s open and close.
In PI charts also, the HA Candle’s open is plotted as “Average of Previous HEIKEN ASHI candle’s open and close” , and NOT “Average of Previous STANDARD candle’s open and close”.
Thanks