# MovingAverage applied to RSI

64

Hi guys,

I'm new on MQL programming and just tried to make an EA with an moving average applied to an RSI.

Before I continue, I'd like you to check the code and tell me whether I did it right.

Not sure whether I have to build an array, hope not...

TIA

``` double RSI = iRSI(NULL,0,14,PRICE_CLOSE,1);
double RSIPreviousPeriod = iOBV(NULL,0,PRICE_CLOSE,2);
double MARSI = iMA(NULL,PERIOD_CURRENT,MovingAverage,0,MODE_SMA,RSI,1);
double MARSIPreviousPeriod = iMA(NULL,PERIOD_CURRENT,MovingAverage,0,MODE_SMA,RSI,2);```
135

ThorstenKock:

Hi guys,

I'm new on MQL programming and just tried to make an EA with an moving average applied to an RSI.

Before I continue, I'd like you to check the code and tell me whether I did it right.

Not sure whether I have to build an array, hope not...

TIA

Looks right. Tell me if it works. I'm also working on something similar
Moderator
189753

In fact, it is simple.

Pay attention to the help: iMA and parameter "type of price or handle"

```int  iMA(
string               symbol,            // symbol name
ENUM_TIMEFRAMES      period,            // period
int                  ma_period,         // averaging period
int                  ma_shift,          // horizontal shift
ENUM_MA_METHOD       ma_method,         // smoothing type
ENUM_APPLIED_PRICE   applied_price      // type of price or handle
);```

You need: create an iRSI indicator handle, create an iMA indicator handle in iMA (in place applied_price ) insert iRSI handle.

I did the same: calculated iMA by iRVI indicator - code example iMA calculated by iRVI

```//+------------------------------------------------------------------+
//|                                       iMA calculated by iRVI.mq5 |
//|                                           http://wmua.ru/slesar/ |
//+------------------------------------------------------------------+
...
int    handle_iRVI;                          // variable for storing the handle of the iRVI indicator
int    handle_iMA;                           // variable for storing the handle of the iMA indicator
...
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
{
...
//--- create handle of the indicator iRVI
handle_iRVI=iRVI(m_symbol.Name(),Period(),Inp_RVI_ma_period);
//--- if the handle is not created
if(handle_iRVI==INVALID_HANDLE)
{
//--- tell about the failure and output the error code
PrintFormat("Failed to create handle of the iRVI indicator for the symbol %s/%s, error code %d",
m_symbol.Name(),
EnumToString(Period()),
GetLastError());
//--- the indicator is stopped early
return(INIT_FAILED);
}
//--- create handle of the indicator iMA
handle_iMA=iMA(m_symbol.Name(),Period(),Inp_MA_ma_period,Inp_MA_ma_shift,
Inp_MA_ma_method,handle_iRVI);
//--- if the handle is not created
if(handle_iMA==INVALID_HANDLE)
{
//--- tell about the failure and output the error code
PrintFormat("Failed to create handle of the iMA indicator for the symbol %s/%s, error code %d",
m_symbol.Name(),
EnumToString(Period()),
GetLastError());
//--- the indicator is stopped early
return(INIT_FAILED);
}
//---
return(INIT_SUCCEEDED);
}```