Calculating the average value of a specific difference in mql4
- Set your arrays to as-series before filling.
- Fill your arrays and then compute your average, or count down so you try to compute average of filled elements.
William Roeder:
Ok thank you very much, I’ll try and let you know
- Set your arrays to as-series before filling.
- Fill your arrays and then compute your average, or count down so you try to compute average of filled elements.
William Roeder:
- Set your arrays to as-series before filling.
- Fill your arrays and then compute your average, or count down so you try to compute average of filled elements.
So i tried, and now i can retrieve the information from the single row in the array. What i don't understand is why if i print it it won't give me the same value on every print. Probably because i set the shift on "i" in the LWMA parameters?
double CalculateAVGLongRange() { double BBMid = 0; double LWMA = 0; double ALWMA[]; double ABBMID[]; double Shift[]; double AVGLongRange = 0; double ShiftC = 0; for(int i=Bars-1;i>=0;i--) { BBMid = iBands(Symbol(),Period(),20,2,0,PRICE_CLOSE,MODE_MAIN,i); LWMA = iMA(Symbol(),Period(),20,0,MODE_LWMA,PRICE_CLOSE,i); //if(Close[i] > BBMid && LWMA > BBMid) { if(Close[i] > LWMA) { ArrayResize(ALWMA,Bars); ArrayResize(Shift,Bars); ArraySetAsSeries(ALWMA,true); ArrayFill(ALWMA,0,Bars,LWMA); ShiftC= Close[i] - ALWMA[i]; ArraySetAsSeries(Shift,true); ArrayFill(Shift,0,i,ShiftC); AVGLongRange =iMAOnArray(Shift,Bars,14,0,MODE_SMA,0); Print(ALWMA[0]); } } } if(AVGLongRange > 0 ) return(AVGLongRange); else return(0); } void Plot(){ for(int i=0;i<CalculateBars;i++) { double BBMid = iBands(Symbol(),Period(),20,2,0,PRICE_CLOSE,MODE_MAIN,i); double LWMA = iMA(Symbol(),Period(),20,0,MODE_LWMA,PRICE_CLOSE,i); LongRangeBandDownBuffer[i] = LWMA; LongRangeBandUpBuffer[i] = LWMA+CalculateAVGLongRange(); } }

Hello everyone, so i've been trying to create my custom indicator, but i'm having trouble creating the "iMaOnArray" of this calculation.
What i basically wanna do is retrieve the average value of the difference between close price and LWMA(Linear Weighted Moving Average) when close price is higher than LWMA and vice versa ( so AVG(Close[i] - LWMA)).
I tried doing this by using iMaOnArray, but i don't get a specific value. Anyone can help?
Thanks in advance to whoever will help me :)