What is the equivalent of iMAOnArray on MQL5

 

Hello Folks,


Recently I had to shift from mql4 (which I can code) to mql5

I want to create a moving average on a custom array that I have after some calculations

in mql4 I used to calculate it as follows

customMA[i] = iMAOnArray(customArray, Bars, maPeriod,0,maMethod, i);

I have done my search and so far I found out the following :

in mql5 there is only iMA which take price or handle of a previously calculated indicator and I don't have any of these


any help please to achieve this, Thank you in advance and your help is highly appreciated

 
aya3adel:

Hello Folks,


Recently I had to shift from mql4 (which I can code) to mql5

I want to create a moving average on a custom array that I have after some calculations

in mql4 I used to calculate it as follows

I have done my search and so far I found out the following :

in mql5 there is only iMA which take price or handle of a previously calculated indicator and I don't have any of these


any help please to achieve this, Thank you in advance and your help is highly appreciated


Use the movingaverages.mqh library and call the average on array type you want to use.
 
Navdeep Singh:

Use the movingaverages.mqh library and call the average on array type you want to use.

Thank you so much for your reply, do you know any way to achieve the same concept in bollinger bands? in other words a replacement for iBandsOnArray?

 
Thank you so much that actually worked just fine, do you know any way to achieve the same concept in bollinger bands? in other words a replacement for iBandsOnArray? I can't find it in the migration from mql4 to mql5 documentation
 
aya3adel:

Thank you so much for your reply, do you know any way to achieve the same concept in bollinger bands? in other words a replacement for iBandsOnArray?

I don't think there is any. You will have to write your own custom function for that.
 
Navdeep Singh:
I don't think there is any. You will have to write your own custom function for that.
That's really frustrating, Thank you for your help though.
 
aya3adel: Thank you so much that actually worked just fine, do you know any way to achieve the same concept in bollinger bands? in other words a replacement for iBandsOnArray? I can't find it in the migration from mql4 to mql5 documentation

Bollinger Bands is just a Simple Moving Average and Simple Standard Deviation. I used the following information to to build my own solutions when I need to implement incremental versions for my own indicators, but can be just as easily applied to arrays.

The PDF document describes the math for moving averages and variance (and standard deviation) for Simple, Weighted and Exponential moving averages.

 
Fernando Carreiro:

Bollinger Bands is just a Simple Moving Average and Simple Standard Deviation. I used the following information to to build my own solutions when I need to implement incremental versions for my own indicators, but can be just as easily applied to arrays.

The PDF document describes the math for moving averages and variance (and standard deviation) for Simple, Weighted and Exponential moving averages.

Thank you Fernando for your reply, I'm aware of the mathematical concept behind it but while coding anything other than simple moving average it makes the code larger which results in taking a lot of time to execute it and this makes the indicator slower on the smaller timeframes that's why I preferred the ready-made functions in mql4 they were a lot faster.. I feel like it's a downgrade not an upgrade removing all these function from mql5 I don't even understand why
 
aya3adel:
Thank you Fernando for your reply, I'm aware of the mathematical concept behind it but while coding anything other than simple moving average it makes the code larger which results in taking a lot of time to execute it and this makes the indicator slower on the smaller timeframes that's why I preferred the ready-made functions in mql4 they were a lot faster.. I feel like it's a downgrade not an upgrade removing all these function from mql5 I don't even understand why

Not true! That is why I gave you the incremental version (called "Online") of moving averages and not the standard ones, which is much faster and uses less memory than the versions provided thus far by MetaQuotes. I use them in all my code and performance is way better than using the internal functions.

In fact I have Indicators and EAs that run hundreds of moving averages and standard deviations simultaneously on every M1 bar and calculates the virtual trading metrics on them so as to select the best one and to optimise in real-time while trading, and it is super fast and has no delays in trading.

Obviously, you have to implement and code them properly and trigger the calculations at the proper times and not at every single tick.

 
aya3adel #:
Thank you so much that actually worked just fine, do you know any way to achieve the same concept in bollinger bands? in other words a replacement for iBandsOnArray? I can't find it in the migration from mql4 to mql5 documentation

Hello, me too I'm trying to create SMA on price but I can't understand what I have to insert as "position" variable... (the first parameters).

Example: if I want a SMA 200 periods writing SimpleMA(?, 200, close) where close is native array of OnCalculate function

Whether I put zero (as positoin) it doesn't work, even because into the code there is 

result += price[pos - i];

 so 0-1 isn't possible...

Thanks in advance.