Download MetaTrader 5

Averaging an indicator in an EA

To add comments, please log in or register
rr
19
rr  

Hi, I'm trying to do an EMA of an indicator (ADX) in an EA, but I must be doing something wrong cause it doesn't work.

I attach some lines of the code:

<Please use SRC Button>

Fisrt of all, what I have to do to see this ema on the screen in a backtest for example? And second, if I try to backtest this EA, the value of maADX it's not the same as if I drag a moving average (period 50) to the ADX indicator with Previous Indicator's Data option.

Simon Gniadkowski
Moderator
18024
Simon Gniadkowski  
tradefish:

Hi, I'm trying to do an EMA of an indicator (ADX) in an EA, but I must be doing something wrong cause it doesn't work.

I attach some lines of the code:

<REMOVED>

Please use the SRC button to post code . . .
whroeder1
15591
whroeder1  
tradefish: I'm trying to do an EMA of an indicator (ADX) in an EA, but I must be doing something wrong cause it doesn't work.
  1. Use SRC. Please edit your post.
  2. Set the ADXarray as series so it knows array[0] is the newest like the chart.
rr
19
rr  
WHRoeder:
  1. Use SRC. Please edit your post.
  2. Set the ADXarray as series so it knows array[0] is the newest like the chart.
for ( int j=0;j<1000;j++)
    {
      ADXarray[j]=iADX(NULL,0,period,0,0,j);
    }
    ArraySetAsSeries(ADXarray,true);
    
    maADX=iMAOnArray(ADXarray,0,50,0,MODE_EMA,1);

Ok, here is the code. I've used ArraySetAsSeries and now it works (thanks WHRoeder). The only missing thing is that I don't know how to show this ema when I backtest. After stopping the backtest I see the ADX, but not the ema. In fact, it's not very important, I can drag the ema to the ADX to see if everything is ok....
whroeder1
15591
whroeder1  
      ADXarray[j]=iADX(NULL,0,period,0,0,j);
    }
    ArraySetAsSeries(ADXarray,true);
BEFORE you use it
To add comments, please log in or register