Bucky
Bucky

Reputation: 1206

Converting a Heikin 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 :(

Upvotes: 1

Views: 563

Answers (1)

TNBrian
TNBrian

Reputation: 1

You are taking the MA of the regular price value, not of the Heikinashi values. you can't just call an iMA function to generate an MA like that. It would look at normal price values, not heikinashi values.

Either look for a heikinashi smoothed indicator. or modify the indicator. Put EMA code in the EA that can take an array of values and make your own EMA without the iMA function.

You will need to write or copy code that takes the heikinashi values as input, then smooths them with an ema code.

Upvotes: 0

Related Questions