How can we resize a static array in mql5 language?

 

This script works in mql4 language and returns the correct output,

but in mql5 language it returns "array out of range" error.;

How to resize a static array in mql5 language?

int array[4] = {41, 52, 78, 51};
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
void OnStart()
    {
     AddToEnd_x(85, array);
     Print("===>>>> ", array[4]);
    }
//+------------------------------------------------------------------+
bool AddToEnd(int value, int & a_Source[])
    {
     bool res = false;
//---
     int src_size = ArraySize(a_Source);
     int new_size = src_size + 1;
     ArrayResize(a_Source, new_size);
     a_Source[new_size - 1] =  value;
//---
     return(res);
    }
 
  1. alighasemi1993: How to resize a static array in mql5 language?

    Perhaps you should read the manual.

       How To Ask Questions The Smart Way. (2004)
          How To Interpret Answers.
             RTFM and STFW: How To Tell You've Seriously Screwed Up.


  2. alighasemi1993: This script works in mql4 language and returns the correct output,

    It doesn't “return the correct output,” as the MT4 documentation says the same thing. The fact it works is a bug.

 
William Roeder #:
  1. Perhaps you should read the manual.

       How To Ask Questions The Smart Way. (2004)
          How To Interpret Answers.
             RTFM and STFW: How To Tell You've Seriously Screwed Up.


  2. It doesn't “return the correct output,” as the MT4 documentation says the same thing. The fact it works is a bug.

So what we should do in case like this?

How we could resize arrays like this?

 
Please don't post randomly in any section. Your topic has been moved to the section: Expert Advisors and Automated Trading
 
alighasemi1993 #: How we could resize arrays like this?

You don't; you can't resize a fixed size array. Create a dynamic array, resize it, populate it.