Forgive me I've just started coding in mql4 last week....I have also tried searching the forums and reading the reference materials but am so
My question is:
How do you change the source of a moving average to be something other than 'PRICE_CLOSE'/'PRICE_HIGH' etc. For example just a moving
average of the Volume.
This is super easy in pine script on tradingview.
I believe this cannot be done with 'iMA'. Am I correct in thinking in my volume example above that you must use iMAOnArray?
I am getting so confused but what I have so far is:
#property copyright "Jim Davies"
#property link "https://www.mql5.com"
#property version "1.00"
volbuffer = Volume;
double mavol = iMAOnArray(volbuffer,0,14,0,MODE_SMA,0);
The problem here is (volbuffer outputs the volume correctly) but mavol outputs 0.
Thanks for any help
You need to fill the buffer I guess. One value is not enough to form a moving average.
Thanks for your reply.
I changed "double volbuffer" to "double volbuffer" and "mavol" now outputs 314.43533.... instead of 0. This value cant be right
as the volume is between 5000-10,000 over the last 14 candles...… :/.
I know i'm stupid but this is difficult to understand....
only because 14 returned a ridiculous number as well. (just testing other numbers)
if the volbuffer is outputting 5000+ and the previous 14 candles are 5000+ how on earth is a 14 period moving average returning 300?
If anyone could help further...
I have a moving average(maArray) of a volume moving average(FinalMa)
MaArray is outputting the first index but not any of the others. All the others are 0.
Heres the code:
for(int i=0; i<14;i++)
MaArray[j] = iMAOnArray(VolArray,0,14,0,MODE_SMA,j);
double FinalMa = iMAOnArray(MaArray,0,14,0,MODE_SMA,0);
Any help/Ideas why?
Thanks again guys
For anyone searching the forums with a similar problem....
The solution that works or at least outputs the correct numbers is increasing the VolArray to VolArray and also changing the
VolArray 'for' loop to match. This i'm guessing is to allow for the shift of MaArray/iMaOnArray. I also reverse indexed VolArray with
ArraySetAsSeries to keep the 0 index as the most recent candle.
FinalMa then outputs a 14 period moving average of a 14 period moving average of the volume.