Download MetaTrader 5
To add comments, please log in or register
How to buy a product in MetaTrader AppStore? Read the article!
sd2000sd
212
sd2000sd 2014.11.01 10:58 

I want to calculate MA of RSI .

SO far I could come this far with this code:

double rsi[];
  
   for(int i=0 ; i<=100 ; i++)
    {
      rsi[i]=iRSI(Symbol(),0,14,PRICE_OPEN,i);
    }
    
   
   ArraySetAsSeries(rsi,true);
   double ma=iMAOnArray(rsi,0,5,0,MODE_EMA,1);
   Print("MA value ",ma);

but when I compile the above EA I see this message in Experts tab of MT4:

2014.11.01 14:28:07.723    array out of range in 'maOnRSI.mq4' (50,10)



how can I solve this? what am I doing wrong?

Please help.

Thanks

Keith Watford
Moderator
7963
Keith Watford 2014.11.01 11:17  

You are declaring a dynamic array

double rsi[];

 

 but you don't size it, you have to use ArrayResize

sd2000sd
212
sd2000sd 2014.11.01 11:39  
GumRai:

You are declaring a dynamic array

 

 but you don't size it, you have to use ArrayResize

OK , I went one step forward, but there is still a problem:

I am using the following code, but the problem is I want to calculate MA -> period=5, MA method=Exponential, shift=0,      on RSI with (period=14, Apply to=Open).

MA of RSI for bar 1 in the indicators that I have installed on the chart is = 66.4862 but the following code says it is :

2014.11.01 15:09:07.336    maOnRSI GBPJPY,M15: MA of RSI for bar= 1 = 0.1348944125100005


what am I doing wrong now?

void OnTimer()
  {
//---
   double RSIBuffer[];
  double MAofRSIBuffer[];
  ArrayResize(RSIBuffer,Bars+1);
  ArrayResize(MAofRSIBuffer,Bars+1);
   for(int i=0 ; i<=Bars ; i++)
    {
      RSIBuffer[i]=NormalizeDouble( iRSI(NULL,0,14,PRICE_OPEN,i) ,4);

    }
    
   



   for(int i=0; i <= 4; i++)
      {
        MAofRSIBuffer[i]=iMAOnArray(RSIBuffer,0,5,0,MODE_EMA,i);
        Print ("IMAOnArray for ",i," = ",NormalizeDouble (iMAOnArray(RSIBuffer,0,5,0,MODE_EMA,i) ,4));
      }
   Print ("rsi = ",RSIBuffer[1]);   
   Print ("MA of RSI for bar= ", 1," = ",MAofRSIBuffer[1]);


   
  }
sd2000sd
212
sd2000sd 2014.11.01 11:59  
sam2014:

OK , I went one step forward, but there is still a problem:

I am using the following code, but the problem is I want to calculate MA -> period=5, MA method=Exponential, shift=0,      on RSI with (period=14, Apply to=Open).

MA of RSI for bar 1 in the indicators that I have installed on the chart is = 66.4862 but the following code says it is :

2014.11.01 15:09:07.336    maOnRSI GBPJPY,M15: MA of RSI for bar= 1 = 0.1348944125100005


what am I doing wrong now?

someone please help
Ernst Van Der Merwe
4404
Ernst Van Der Merwe 2014.11.02 06:06  
sam2014:

OK , I went one step forward, but there is still a problem:

I am using the following code, but the problem is I want to calculate MA -> period=5, MA method=Exponential, shift=0,      on RSI with (period=14, Apply to=Open).

MA of RSI for bar 1 in the indicators that I have installed on the chart is = 66.4862 but the following code says it is :

2014.11.01 15:09:07.336    maOnRSI GBPJPY,M15: MA of RSI for bar= 1 = 0.1348944125100005


what am I doing wrong now?

Try this

void OnTimer()
  {
//---
   int i,j;
   int signal=5;
   double RSIBuffer[];
   double MAofRSIBuffer[];
   ArrayResize(RSIBuffer,signal*2);
   ArrayResize(MAofRSIBuffer,signal+2);
   for(i=0 ; i<signal*2 ; i++)
    {
      RSIBuffer[i] = iRSI(NULL,0,14,PRICE_OPEN,i);

    }
    
   ArraySetAsSeries(RSIBuffer,true);


   for(i=0; i <signal+2; i++)
      {
        MAofRSIBuffer[i]=iMAOnArray(RSIBuffer,0,siganl,0,MODE_EMA,i);
        Print ("IMAOnArray for ",i," = ",iMAOnArray(RSIBuffer,0,signal,0,MODE_EMA,i));
      }
   Print ("rsi = ",RSIBuffer[1]);   
   Print ("MA of RSI for bar= ", 1," = ",MAofRSIBuffer[1]);


   
  }
whroeder1
13627
whroeder1 2014.11.02 12:54  
pipPod: Try this
With
ArraySetAsSeries(rsi,true);
Before filling in the values.
Ernst Van Der Merwe
4404
Ernst Van Der Merwe 2014.11.03 09:15  
WHRoeder:
pipPod: Try this
With
Before filling in the values.
Fixed.
/
To add comments, please log in or register