Yes, you should collect the data first and use iMAOnArray()
int i, indicator_counted; //--- subtracts one MA from another MA for (i = Bars - indicator_counted; i >= 0; i--) { MA_2 = iMA(NULL,0,X,0,MODE_SMA,PRICE_CLOSE,(i+A)); MA_1 = iMA(NULL,0,X,0,MODE_SMA,PRICE_CLOSE,(i+B)); Data [i] = MA_2 - MA_1; } //--- MA of the result of "subtracts one MA from another MA" for (i = Bars - indicator_counted; i >= 0; i--) { MA [i] = iMAOnArray (Data,0, R,0,MODE_SMA, i); } indicator_counted = IndicatorCounted() - 1;
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
Hi,
I am trying to create an indicator which subtracts one MA from another MA, then plots an MA of the result and plots a single period rate of change of the result.
The two inital MAs are of equal length (let the length be X) and are separated by a window period (let this be W, please note that X isn't necessarily equal to W).
The length of the resultant MA is equal to R.
I am new to coding but trying to learn. I can't seem to get the array indexing right, so that the two lines (the resultant MA and the ROC) are in phase .
i.e.
If the window period between the two inital MAs = W
If the length of the two MAs = X
And the length of the resultant MA = R
then what are the variables A,B,C,D,E?
Is this the best way to code this indicator? Should I instead let
Line_1[]=MA_2-MA_1
And then use iMAOnArray to get the resultant MA?
Thanks.