RSI array out of range error

 
Hi guys. newbie here ..I need some help. 
I would like to use rsi value of 5th candle as part of my entry so I need to keep checking for it's value . I compiled my code and have no errors or warnings. However when using strategy tester, I keep getting array out of range (89,38) . How can I fix this and make the code work as  intended . 
 Please give advice if I have done it wrong. Here's the code below 

double rsiArray[];
  
   int rsiHandle = iRSI(_Symbol,PERIOD_CURRENT,7,PRICE_CLOSE);
   
   ArraySetAsSeries(rsiArray,true);
  
   CopyBuffer(rsiHandle,0,5,6,rsiArray);
  
   double rsi = NormalizeDouble(rsiArray[5],2);

Additionally, I have used rsi value in this code below below

if((rsi > 80) && (slowMaArray[5] > 12000) && (FastMaArray[0] < slowMaArray[0] && FastMaArray[1] > slowMaArray[1]))
{
  trade.Sell(0.2,_Symbol,0,0,0);
}
If this is the source of the problem or  my if statement is wrong please advise also . (I have a feeling it's wrong lol)
Thanks . 
The checks a trading robot must pass before publication in the Market
The checks a trading robot must pass before publication in the Market
  • www.mql5.com
Before any product is published in the Market, it must undergo compulsory preliminary checks in order to ensure a uniform quality standard. This article considers the most frequent errors made by developers in their technical indicators and trading robots. An also shows how to self-test a product before sending it to the Market.
 
Seleucus:
Hi guys. newbie here ..I need some help. 
I would like to use rsi value of 5th candle as part of my entry so I need to keep checking for it's value . I compiled my code and have no errors or warnings. However when using strategy tester, I keep getting array out of range (89,38) . How can I fix this and make the code work as  intended . 
 Please give advice if I have done it wrong. Here's the code below 


Additionally, I have used rsi value in this code below below

If this is the source of the problem or  my if statement is wrong please advise also . (I have a feeling it's wrong lol)
Thanks . 

1. Please paste your code correctly: click the  Codebutton, then paste your code into the popup window. I have edited your message.

2. You have a gross mistake: you create an indicator handle on each tick. According to the MQL5 style, the indicator handle should be created ONLY ONCE and should be done in OnInit.

See an example of creating a simple Expert Advisor: Very Simple Intersection iMA Open Position

How to start with MQL5
How to start with MQL5
  • 2022.04.07
  • www.mql5.com
This thread discusses MQL5 code examples. There will be examples of how to get data from indicators, how to program advisors...
 
I corrected my problem. I created the handle in the oninit function. 
I had gotten bad examples from some YouTube videos where the handle is created in ontick function. 
Thanks again for your examples.
Reason: