Finding ArrayMinimum of an RSI to be lower to a certain specified number level

 

Hello Forum,

I am writing a function in MQL4 where I want the lowest array of an RSI to be lower than a number I define. There is no error when I compile it but it won't execute. These are the errors I get from the Journal. 

  • 2020.04.28 06:55:22.813 2019.11.05 00:00:03  Testing pass stopped due to a critical errorin the EA;
  • 2020.04.28 06:55:22.813 2019.11.05 00:00:03  Stack overflowin 'C:\Users\………;

I have already deleted and redownloaded the prices from the price history, and also experimented with different numbers (level, e.g., 30).

Please let me know what's wrong with my code. Thanks.

// initialization
double RSIMinimumArray[100];
double lowestRSI;

//body of the function
bool RSIBottom()
  {
   for(int i=0; i<40+1; i++)
     {
      RSIMinimumArray[i] = iRSI(_Symbol, _Period, 14, PRICE_CLOSE, i);      
      lowestRSI = ArrayMinimum(RSIMinimumArray, 40, 1);
      
      if(lowestRSI < 30)
        {
         RSIBottom();
        }
     }
   return(RSIBottom());
  }


Documentation on MQL5: MQL5 programs / Runtime Errors
Documentation on MQL5: MQL5 programs / Runtime Errors
  • www.mql5.com
The executing subsystem of the client terminal has an opportunity to save the error code in case it occurs during a MQL5 program run. There is a predefined variable _LastError for each executable MQL5 program. Before starting the OnInit function, the _LastError variable is reset...
 

In future please post in the correct section.

I will move this thread to the "MQL4 and MetaTrader4" section.

 
  1.    for(int i=0; i<40+1; i++)
         {
          RSIMinimumArray[i] = iRSI(_Symbol, _Period, 14, PRICE_CLOSE, i);      
          lowestRSI = ArrayMinimum(RSIMinimumArray, 40, 1);
          
          if(lowestRSI < 30)
    How do you think you can get a minimum before completely filling the array?
  2. You are filling elements [0 … 40] Why are you searching [1 … 41]?

  3. bool RSIBottom(){
       ⋮
          if(lowestRSI < 30){ RSIBottom(); }
       ⋮
       return(RSIBottom());
    Stack overflow means you are infinitely calling yourself.
 

I tweaked a bit and it looks like this works for me, although not elegant. Thanks for the ideas.

// initialization
double RSIMinimumArray[100];
double lowestRSI;

//body of the function

bool RSIBottom()
  {
   for(int i=0; i<40; i++)
     {
      RSIMinimumArray[i] = iRSI(_Symbol, _Period, 14, PRICE_CLOSE, i);     
     }

   lowestRSI = iRSI(_Symbol, _Period, 14, PRICE_CLOSE, ArrayMinimum(RSIMinimumArray, 40, 0));

   if(lowestRSI < 30)
      return(true);
   return(false);
  }
Reason: