Moving average of an indicator
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
void sma()
{
double sum=0;
int i,pos=Bars-ExtCountedBars-1;
//---- initial accumulation
if(pos<MA_Period) pos=MA_Period;
for(i=1;i<MA_Period;i++,pos--)
sum+=Close[pos];
//---- main calculation loop
while(pos>=0)
{
sum+=Close[pos];
ExtMapBuffer[pos]=sum/MA_Period;
sum-=Close[pos+MA_Period-1];
pos--;
}
//---- zero initial bars
if(ExtCountedBars<1)
for(i=1;i<MA_Period;i++) ExtMapBuffer[Bars-i]=0;
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
void sma()
{
double sum=0;
int i,pos=Bars-ExtCountedBars-1;
//---- initial accumulation
if(pos<MA_Period) pos=MA_Period;
for(i=1;i<MA_Period;i++,pos--)
sum+=Close[pos];
//---- main calculation loop
while(pos>=0)
{
sum+=Close[pos];
ExtMapBuffer[pos]=sum/MA_Period;
sum-=Close[pos+MA_Period-1];
pos--;
}
//---- zero initial bars
if(ExtCountedBars<1)
for(i=1;i<MA_Period;i++) ExtMapBuffer[Bars-i]=0;
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()
e.g.
int period = 7; int history = 100; double array[]; ArrayResize(array,history); 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
Use iMAOnArray() function. For the data array, use an array you previously populated with the indicator's data.
PS:
Note that
ArraySetAsSeries(array, true);
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 ;)
As said ahmetozer10 you have to use iMAOnArray()
e.g.
How do I do this on MQL5 the iMAOnArray() is not available.
Im trying to find the 20MA of the On Balance Volume. Am I missing something.
I am new to this type of thing.
Thanks in advance
//+------------------------------------------------------------------+ //| On Balance Volume | //+------------------------------------------------------------------+ // create an Array for several prices double OnBalanceVolumeArray[]; double OnBalance_MA_Array[]; // sort the price array from the current candle downwards ArraySetAsSeries(OnBalanceVolumeArray,true); // sort the price array1 from the current candle downwards ArraySetAsSeries(OnBalance_MA_Array,true); // define the properties of the OBV int OBVDefinition = iOBV (_Symbol,_Period,VOLUME_TICK); int OBV_MA20 = iMA( ? ) // Defined OBV, one line,current candle,20 candles, store result CopyBuffer(OBVDefinition,0,0,20,OnBalanceVolumeArray); // Defined OBV, one line,current candle,20 candles, store result CopyBuffer(OBV_MA20,0,0,20,OnBalance_MA_Array);
Hi,
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.