# Help me with this line of code

79

I wrote a simple indicator to compare RSI of previous bar with current rsi. But i need to change it to compare moving averages of RSI. please note that i know its doable to calculate moving average of rsi indicator by dragging moving average over rsi and applying it to previous indicators data and I also know there is ready to use indicators for this purpose on codebase but i need to code it.
Please note to line 62 of code. How can i compare rsi[i+1] with moving average of RSI (IMA(RSI) )?
I want to call rsi using iCustom and then in line 9, instead of PRICE_CLOSE, use that calculated rsi.
Please consider that this code seems nonsense for trading, but i want to know how to write  above code.
```int MA_handle;double MA[];int RSI_handle;double RSI[];double Low[];
int OnInit()  {      MA_handle = iMA(NULL, PERIOD_CURRENT, 14, 0, MODE_SMA, PRICE_CLOSE);   if(MA_handle < 0)     {      Print("The creation of iMA has failed: MA_handle=", INVALID_HANDLE);      Print("Runtime error = ", GetLastError());      return(INIT_FAILED);     }      RSI_handle = iRSI(NULL, PERIOD_CURRENT, 14, PRICE_CLOSE);   if(RSI_handle < 0)     {      Print("The creation of iRSI has failed: RSI_handle=", INVALID_HANDLE);      Print("Runtime error = ", GetLastError());      return(INIT_FAILED);     }      return(INIT_SUCCEEDED);  }
//+------------------------------------------------------------------+//| Custom indicator iteration function                              |//+------------------------------------------------------------------+int OnCalculate(const int rates_total,                const int prev_calculated,                const datetime& time[],                const double& open[],                const double& high[],                const double& low[],                const double& close[])  {   int limit = rates_total - prev_calculated;   //--- counting from 0 to rates_total   ArraySetAsSeries(Buffer1, true);   //--- initial zero   if(prev_calculated < 1)     {      ArrayInitialize(Buffer1, 0);     }   else      limit++;      if(CopyOpen(Symbol(), PERIOD_CURRENT, 0, rates_total, Open) <= 0) return(rates_total);   ArraySetAsSeries(Open, true);   if(CopyBuffer(MA_handle, 0, 0, rates_total, MA) <= 0) return(rates_total);   ArraySetAsSeries(MA, true);   if(CopyBuffer(RSI_handle, 0, 0, rates_total, RSI) <= 0) return(rates_total);   ArraySetAsSeries(RSI, true);   if(CopyLow(Symbol(), PERIOD_CURRENT, 0, rates_total, Low) <= 0) return(rates_total);   ArraySetAsSeries(Low, true);   //--- main loop   for(int i = limit-1; i >= 0; i--)     {           if(RSI[1+i] > RSI[i])        {         Buffer1[i] = Low[i];        }      else        {         Buffer1[i] = 0;        }     }   return(rates_total);  }```

19852

Huido:

Please note to line 62 of code. How can i compare open[i+1] with moving average of RSI (IMA(RSI) )?

I want to call rsi using iCustom and then in line 9, instead of PRICE_CLOSE, use that calculated rsi.
1. Open is 1.12345 and RSI is in the range zero to 100 What is the point in comparing them?
2. RSI is not a custom indicator, you can't use iCustom.
3. To get the MA of a buffer you must calculate it, like the MT4's iMAOnArray.
Migrating from MQL4 to MQL5 - MQL5 Articles -> № 17. Technical Indicators -> MAOnArrayMQL4
79

whroeder1:
1. Open is 1.12345 and RSI is in the range zero to 100 What is the point in comparing them?
2. RSI is not a custom indicator, you can't use iCustom.
3. To get the MA of a buffer you must calculate it, like the MT4's iMAOnArray.
Migrating from MQL4 to MQL5 - MQL5 Articles -> № 17. Technical Indicators -> MAOnArrayMQL4

You are right for #1. I was written it wrong. I changed it now to compare previous rsi with current one.

So you would say  its not possible to have something like this and use it instead of price_close in line 9?

`double myrsi=iRSI(NULL,0,14,PRICE_CLOSE,0)`
1947
dazi001

I would say, it is not possible.

Both indicators need an array to calculate the proper value.

The only way I see, is to create your own indicator, which is using one of the standard indicators to calculate the value
and put it to an internal array, while the other indicator needs to be rewritten to use this internal array instead of
Open, High, Low or Close.