Please help - iRSIOnArray

To add comments, please log in or register
Andrew Thompson
247
Andrew Thompson  

I am trying to plot the RSI of an indicator, "xxx.mq4", as follows:

#property indicator_buffers 1
#property indicator_color1 Red
#property indicator_width1 2

//---- buffers
double ExtMapBufferCustomIndicator[];
double ExtMapBufferRSICustomIndicator[];
int i;
string s="xxx";

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,ExtMapBufferRSICustomIndicator);
   SetIndexLabel(0,"RSICustomIndicator");
   
   IndicatorShortName("RSI of xxx: RSICustomIndicator");
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int counted_bars=IndicatorCounted();
   if(counted_bars < 0)  return(-1);
   if(counted_bars>0) counted_bars--;
   int limit=Bars-counted_bars;
   if(counted_bars==0) limit-=15;
//   printf(limit);
//---- main loop
   for(i=0; i<limit; i++)
     {
      ExtMapBufferCustomIndicator[i]= iCustom(NULL,0,s,20,40,0,0);
     }
   for(i=0; i<limit; i++)
     {
      ExtMapBufferRSICustomIndicator[i]=iRSIOnArray(ExtMapBufferCustomIndicator,0,14,0);
     }
//---- done
   return(0);
  }
//+------------------------------------------------------------------+

but I get the following error on running: "RSIxxx [instrument],H1: array out of range in 'RSIxxx.mq4' (55,26)

The reference is to this line:

      ExtMapBufferCustomIndicator[i]= iCustom(NULL,0,s,20,40,0,0);

The custom indicator takes two integers as arguments, hence the 20,40 after the name of the Custom Indicator.


Any clues?

Naguisa Unada
346
Naguisa Unada  

Add in "int init()".

IndicatorBuffers(2);
SetIndexBuffer(1,ExtMapBufferCustomIndicator);

Fix the following 2 lines.

ExtMapBufferCustomIndicator[i]=iCustom(NULL,0,s,20,40,0,i);//iCustom(NULL,0,s,20,40,0,0);
ExtMapBufferRSICustomIndicator[i]=iRSIOnArray(ExtMapBufferCustomIndicator,0,14,i);//iRSIOnArray(ExtMapBufferCustomIndicator,0,14,0);
To add comments, please log in or register