A MA of a separate window Indicator

To add comments, please log in or register
rwb181
98
rwb181  

Good Morning All,

In the MT4 terminal, it is possible to add a MA to an indicator by dragging the MA indicator onto the chart and selecting apply to “Previous Indicator’s Data” but, since I couldn’t figure out how to duplicate that same action in my EA, I decided I needed to build my own indicator that would. And, since I recall seeing some posts here in the past about others trying to do the same, I thought I’d share what I created and hopefully it will be found useful to someone.

In this indicator the first array is the difference between to MA’s and the second is the first array’s value shifted a given number of bars(MT_Shift). It is the third array, that I made as a MA of the first array (in this case, also using the value of MT_Shift as the period for the MA), that I am referring to above and that is the one you would want to mimic in your own custom indicator. Below is the pertinent part and attached is the whole indicator.

while(i>=0)
     {
     ExtMapBuffer1[i]=iMA(0,0,ST_Period,ST_Shift,ST_Method,ST_Price,i)-iMA(0,0,LT_Period,LT_Shift,LT_Method,LT_Price,i);
     ExtMapBuffer2[i]=ExtMapBuffer1[i+MT_Shift];
     double ST_Total=0;
     int c;
     for(c=1;c<=MT_Shift;c++)
       {
       ST_Total=ST_Total+ExtMapBuffer1[i+(MT_Shift-c)];
       }
     ExtMapBuffer3[i]=ST_Total/MT_Shift;
     i--;
     }
Files:
To add comments, please log in or register