I'm new in programming MQL4, I'm trying to calculate the mving average of an indicator in an EA.
Could someone give me a code example of :
- The moving average of x period of the volume of a symbol ?
- The moving average of x period of the slow stochastic(5,10,3) of a symbol ?
Thanks in advance for your help.
No one to help me ?.
I would imagine it would have something to do with re-writing a custom MA indicator that looks at average values of the indicator you want. Should really just be a case of replacing the price values in the current MA indicator with iStochastic values then you can just use iCustom() to call the custom indicator. I think.
here's the simple moving average code from the MA indicator that comes with MT4, should just be a case of replacing the Close[pos] with iStochastic(...,[pos]) values i think
//---- initial accumulation
//---- main calculation loop
//---- zero initial bars
Thanks for your help, mrwobbles, but it didn't help me yet.
Imagine simply I would like to calculate the moving average of x periods on volumes, have you got the code for this ?
As said ahmetozer10 you have to use iMAOnArray()
int period = 7;
int history = 100;
for (int i=0; i<history; i++) array[i]=(double)iVolume(NULL,0,i);
double result = iMAOnArray(array,0,period,0,MODE_SMA, shift); // shift = studied bar
You have just answered 10 years old question. I know, theoretically there is possibility they guy still is looking for an answer but the chances are slim ;)