Write directly MODE_SMMA
double _GetDerivedMA(int index, int priceType) { double ma[]; int j=0; ArrayResize(ma, dMA_Period); ArrayInitialize(ma, EMPTY_VALUE); //I've tried setting array as series, but without any luck //ArraySetAsSeries(ma, true); for(int i=index; i<index+dMA_Period; i++, j++) { ma[j] = _GetMA(i, priceType); } return (iMAOnArray(ma,0,dMA_Period,0,MODE_SMMA,0) ); } double _GetMA(int index, int priceType) { return (iMA(Symbol(),0,MA_Period,MA_Shift,MODE_SMMA,priceType,index)); }and I am more than sure it will work correctly.
Thanx Rosh, I'll try out that one. Could you explain though, why is it happening?
I think you loss value of dMA_Mode somewhere. That's why you decide about incorrect behavior of iMAOnArray().
Rosh:
I think you loss value of dMA_Mode somewhere. That's why you decide about incorrect behavior of iMAOnArray().
Rosh, i've just tried printing out the variable dMA_Mode and MODE_SMMA value from inside the _GetDerivedMA() function. They dont differ. Which means iMAOnArray takes the proper MODE_SMMA value, but for some reason does not calculate what's needed. Same actually goes for LWMA and EMA. Have i overlooked something?
I think you loss value of dMA_Mode somewhere. That's why you decide about incorrect behavior of iMAOnArray().
Write simple code and study it. For example:
double arrayForMA[]; int size=1000; int type=MODE_SMMA; int period=24; ArrayResize(size); ArraySetAsSeries(); for (int=0;i<size;i++) { arrayForMA[i]=Close[i]; } for (int=0;i<size;i++) { double MA_from_Array=iMAOnArray(arrayForMA,0,period,0,type,i); double MA=iMA(Symbol(),0,period,0,type,PRICE_CLOSE,i); if (MathAbs(MA-MA_from_Array)>Point) Print("i=",i," MA=",MA," MA_from_Array=",MA_from_Array); }
Thanks Rosh! I see my fault now. I just need to use a bigger MA buffer.
You're welcome.
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Im a newbie here, so cheers everyone!
I've been trying to figure out what's wrong with code that uses iMAOnArray() function for a couple of days now. When I set mode to MODE_SMMA, it calculates SMA instead. :) The piece of code that give me trouble is given below:
Any clue why SMMA is not working? Im using MT4 Build 211 (Oct 2007), if it will be any help.
Andrey.