MQL5 Array out of Range Issue

 

Hello , i have created a simple program on MQL5 but i keep getting array out of range.

Could you tell me how i can fix it please?

int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---
double array[];

   //ArraySetAsSeries(array,true);


      for ( int i = 500 ; i >= 0; i-- )
      {
               array[ i ] = i;
      }
      
        
  
  Comment("array 0:",array[0]);

//--- return value of prev_calculated for next call
   return(rates_total);
  }
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.
 
double array[];
⋮
               array[ i ] = i;
Your array has no size. Why does trying to assign to it (giving you your error) surprise you?
 
William Roeder #:
Your array has no size. Why does trying to assign to it (giving you your error) surprise you?
It is not possible to create a dynamic array on MQL5?
 
BobChip #:
It is not possible to create a dynamic array on MQL5?
Like C++, either you resize the array with ArrayResize to the amount you need, or use a container like CArrayDouble that automatically allocates the memory as you need.
Reason: