NavigationUser loginWho's new
Who's onlineThere are currently 0 users and 35 guests online.
|
iMaOnArray (Moving average of indicator)Hi folks, I've got a lot messages in the forex-tsd forum asking me how to use iMaOnArray function to get the Moving Average of a specific indicator. Today I'm going to answer all of you in this article. What's the moving average of indicator?When you attach an indicator to the chart it uses the price to for it calculation and save (draw) them . You can calculate the moving average of this array. I'll give you a manual example before going to create our mql4 version. Let's say that we will attach the CCI (Commodity Channel Index) indicator to our chart (Figure 1).
Now we want to get the moving average of the CCI. We can do that by dragging the Moving Average indicator to the window holds the CCI indicator and choose the Apply to: Previous Indicator's Data (Figure 2).
And that's what you get (Figure 3)
How to do that programicly?If you are interested in getting the moving average of any indicator like the above manual setup, you can 'trigger' your MetaEditor and write this code: //+------------------------------------------------------------------+
As you can notice in the above code that we use the function iCCI and iMAOnArray to calculate the Moving average of the CCI indicator. The iCCI function simply calculate the CCI of a giving bar and return its value. We store those values returned by iCCI function in our buffer ExtMapBuffer1. Now we have a full of data buffer (ExtMapBuffer1), how to get the Moving Average of this buffer? iMAOnArray:With the aid of the iMAOnArray function we can calculate the moving average of the values stored in an array(buffer). This is the syntax of the iMAOnArray function: double iMAOnArray(double array [],int total,int period,int ma_shift,int ma_method,int shift)The iMAOnArray - as you see in its syntax - returns double value; this is the value of the moving average - counted on the array - of the given bar. Don't worry you will understand well when you know the parameters of the iMAOnArray function. Parameters:double array []:This is the array of the values you want to calculate the moving average of it. int total:You use the total parameter to indicate the count of items of the data from the array you want to use to calculate the moving average. int period:The moving average period of the moving average you want to use. int ma_method:The moving average method you want to use in your calculation.
|