How to solve Array out of range error in Stoch rsi indicator

 
Hi I used the Stoch RSI indicator and received an error when I changed the period of the stochastics to be higher than the  period value of the RSI.

The exit error is " array out of range in 'Stoch RSI.mq5' (162,29)"
The error occurs on the line "if(Result==0 || (high[i]>Result && high[i]!=EMPTY_VALUE))"
double Highest(double &high[], int length, int shift)
{
   double Result=0;
   for(int i=shift; i<=shift+length; i++)
   {
      if(Result==0 || (high[i]>Result && high[i]!=EMPTY_VALUE))
      {
         Result=high[i];
      }
   }

   return Result;
}

Now I do realize that the indicator will work fine if I just change the values to normal but you see my strategy requires two certain periods to be effective, and thus I need the indicator to work when the period of the stochastics is higher than the period value of the RSI in my EA.

I would very much appreciate if you could help me with this problem

Files:
Stoch_RSI.mq5  8 kb
 

line 117

int limit = prev_calculated==0?rates_total-(MathMax(InpRSIPeriod,InpStockKPeriod)+1):rates_total-prev_calculated+1;

After this line, shift+length exceeds rates_total, resulting in an array out-of-range error.

 
Nagisa Unada #:

line 117

After this line, shift+length exceeds rates_total, resulting in an array out-of-range error.

Thank you very much and how would i go about solving this issue?

I would really appreciate the help

 
Moe alda #:

Thank you very much and how would i go about solving this issue?

You can find the cause by tracing the data using the debugger.

https://www.mql5.com/en/articles/654

Debugging MQL5 Programs
Debugging MQL5 Programs
  • www.mql5.com
This article is intended primarily for the programmers who have already learned the language but have not fully mastered the program development yet. It reveals some debugging techniques and presents a combined experience of the author and many other programmers.
 
Nagisa Unada #:

You can find the cause by tracing the data using the debugger.

https://www.mql5.com/en/articles/654

Thank you very much