iMAOnArray()
Thanks for your response, qjol. So, is this correct? I'd like to take the 30-EMA of the 33-ADX.
double ADX = iADX(NULL, 0, 33, PRICE_CLOSE, MODE_MAIN, 0); double EMA_of_ADX = iMAOnArray(iADX, 0, 30, 0, MODE_EMA, 0);
Please let me know.
double ADX[i] = iADX(NULL, 0, 33, PRICE_CLOSE, MODE_MAIN, 0); double EMA_of_ADX = iMAOnArray(ADX, 0, 30, 0, MODE_EMA, 0);
double iMAOnArray( | double array[], int total, int period, int ma_shift, int ma_method, int shift) |
qjol, I get an error when I try to use that code.
If I use this:
double ADX = iADX(NULL, 0, 33, PRICE_CLOSE, MODE_MAIN, 0); double EMA_of_ADX = iMAOnArray(ADX, 0, 30, 0, MODE_EMA, 0);
...then the EA returns the error "first parameter for iMAOnArray indicator must be an array". And if I use the edited version of your code:
double ADX[i] = iADX(NULL, 0, 33, PRICE_CLOSE, MODE_MAIN, 0); double EMA_of_ADX = iMAOnArray(ADX, 0, 30, 0, MODE_EMA, 0);
...then I can't compile it, because the ADX isn't defined as an array, and I get "variable not defined" errors as well as an error trying to define "ADX[i]".
Do you know what's wrong here? Thanks again for your help.
then define it as an array
double ADX[]; double EMA_of_ADX[]; for (....) ADX[i] = iADX(NULL, 0, 33, PRICE_CLOSE, MODE_MAIN, 0); EMA_of_ADX[i] = iMAOnArray(ADX, 0, 30, 0, MODE_EMA, 0);
I believe with iMAOnArray() you have to fill an array in the first indicator loop then create a second loop for filling the iMAOnArray() buffer
I believe with iMAOnArray() you have to fill an array in the first indicator loop then create a second loop for filling the iMAOnArray() buffer
u right my bad
double ADX[]; double EMA_of_ADX[]; for (int i....) ADX[i] = iADX(NULL, 0, 33, PRICE_CLOSE, MODE_MAIN, 0); for (i....) EMA_of_ADX[i] = iMAOnArray(ADX, 0, 30, 0, MODE_EMA, 0);
Thanks guys, so I'd end up with this, then?
double ADX[]; double EMA_of_ADX[]; for (int i....) ADX[i] = iADX(NULL, 0, 33, PRICE_CLOSE, MODE_MAIN, 1); for (i....) EMA_of_ADX[i] = iMAOnArray(ADX, 0, 30, 0, MODE_EMA, 0);
Which hopefully will return both the current and previous values of the 30-EMA taken of the 33-ADX in the array when I call for it as a variable in my algorithm. I did read somewhere else on the forums that you can't use iMAOnArray for EAs (only for use in indicators); that's not true, is it?
It should be like this:
double ADX[]; double EMA_of_ADX[]; for (int i....) ADX[i] = iADX(NULL, 0, 33, PRICE_CLOSE, MODE_MAIN, i); for (i....) EMA_of_ADX[i] = iMAOnArray(ADX, 0, 30, 0, MODE_EMA, i);
Also have a look at the code for the mql4 MACD. It uses iMAOnArray() too, so you can see how it should be done.
You probably cant use iMAOnArray() in an EA because you need to set indicator buffers for the two arrays, but if you create an indicator you can call it in an EA by using iCustom()
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
So I just realized that you can take moving averages of indicators in metatrader. I've been getting some decent (manual backtesting) results by taking the EMA of the ADX and combining it with the PSAR, and I'd like to automate this system. However, I need to somehow define this EMA-ADX combo indicator as a variable for my EA. Can anyone help me? I'm very inexperienced with coding.
My best guess is that it's something like this...
double ADX = iADX(NULL, 0, 33, PRICE_CLOSE, MODE_MAIN, 0);
double EMA_of_ADX = iMA(NULL, 0, 30, 0, MODE_PreviousIndicator??, PRICE_CLOSE, 0);
...but I'm pretty sure there's no mode that allows you to establish that the moving average should be calculated based on another indicator. How would I go about this? I attached an image of what I mean, for clarity's sake.
Thanks for any help.