Pure Heikin-ashi Code

Hi,

Need code for Heikin-ashi. 

For buy, candlestick color turned into green in up trend, and for sell candlestick turns into red.

I'm referring daily chart here..... Thanks.

HAC=(OPEN+LOW+HIGH+CLOSE)/4

HAO=(REF(OPEN,1)+REF(CLOSE,1))/2

Buy: HAC>HAO AND TREND(HAC)=UP

Sell: HAC<HAO AND TREND(HAC)=DOWN

1 Like

I put your code in PI but some error is coming. Also please tell me what about 1st 2 code lines means, where i can put those?
(Buy: HAC>HAO AND TREND(HAC)=UP - Sell: HAC<HAO AND TREND(HAC)=DOWN)

you have to write: SET HAC = (OPEN+LOW+HIGH+CLOSE)/4
Similar for other line also. I had assumed that you have written Tradescript codes before, and gave you just the formula.
Heiken Ashi candles are calculated using median values of actual candlesticks. The first line calculates the closing price of Heiken Ashi candle by taking the median value of the present candle’s open,low,high and close. The 2nd line calculates the Heiken Ashi opening price by taking the median value of previous candle’s open and close. If you are completely new to algo trading in Pi, you can look at the Zerodha Varsity or their Youtube channel(where they have a detailed video about using EA in Pi). You have to put buy and sell codes in appropriate sections while creating your custom Expert Advisor. Please refer to Pi tutorials.

1 Like