Trying to convert a Heiken Ashi related PineScript to MQL5

 

The pinescript code is like the following

ha = heikinashi(tickerid)
ha_close = security(ha, res, close[1])
ma = ema(ha_close[1], 30)


I'm trying to use the above code in MetaTrader5.

So I tried the following,

[ Using https://www.mql5.com/en/code/33 for getting Heikin Ashi values ]

int handleHA = iCustom(_Symbol,PERIOD_CURRENT,"Heiken Ashi");

Then I got the CLOSE buffer value, Which is at the 4th position,

double haArray[];
CopyBuffer(handleHA,3,1,5,haArray);

And then I got the EMA of those CLOSE values,

int handleEMA = iMA(_Symbol,PERIOD_CURRENT,30,0,MODE_EMA,haArray[1]);
CopyBuffer(handleEMA,0,1,5,emaArray);

But in Metatrader 5 I'm getting different results compared to the TradingView. I think I did the first and third step right. But I have doubts on how I wrote  ha_close = security(ha, res, close[1])  in MQL5. Need help :(

Heiken-Ashi
Heiken-Ashi
  • www.mql5.com
The Heiken-Ashi indicator is looks like the candlestick chart, but it has some difference.The advantage of the Heiken-Ashi charts is a simple trend determination, the upward trend candles are blue,the downward trend candles are red.