How long size we can give to an array?

 

I wrote a indicator in which I define a single dimentional array.

I want to give it a very long size such as  60,000 for example.

But I cann't.

MT4 accepts 2,200, but does not 2,250 nor above.

Its timeframe is H1.

So 2,250 is not so far as enough as we can be provided.

Then I think MQL may have a maximum size for an array.

Do you have an information about it? 

 
buffett1930:

I wrote a indicator in which I define a single dimentional array.

I want to give it a very long size such as  60,000 for example.

But I cann't.

MT4 accepts 2,200, but does not 2,250 nor above.

What error do you get ?
 
No mind readers here, post your code.
 
RaptorUK:
What error do you get ?


When I change the parameter from 2200 to 2250, the cursor becomes a ring rolling forever.
 
WHRoeder:
No mind readers here, post your code.

It is not so special code.
extern int HPeriod = 2200;

int start()
{
   int i;
   double price[];

   ArrayResize(price, HPeriod);

   if (Bars - IndicatorCounted() > 1)
   {
      for(i = 0; i <= HPeriod - 1; i++)
      {
         price[i] = Close[i + 1];
      }
 
The problem is not there. Post the rest of the code.
 
WHRoeder:
The problem is not there. Post the rest of the code.
Would you please try that first in indicator, WHRoeder ?, and please see the logs in expert or journal tab.
 
//---- input parameters
extern int HPeriod = 12345678;
:
int start(){
   double price[];   
   int nPrice=ArrayResize(price, HPeriod);
   Log("Resize="+nPrice);
   int counted_bars    = IndicatorCounted();   if (counted_bars < 0)   return;
   :
/** Log
* send information to OutputDebugString() to be viewed and logged by
* SysInternal's DebugView (free download from microsoft) This is ideal for
* debugging as an alternative to Print(). The function will take up to 10
* stringa (or numeric) arguments to be concatenated into one debug message.
//*/
#import "kernel32.dll"
   void OutputDebugStringA(string msg);
#import
void Log(string s1,    string s2="", string s3="", string s4="", string s5="",
         string s6="", string s7="", string s8="", string s9="", string s10=""){
    if (IsDllsAllowed()){
        string out  = WindowExpertName() + ": "
                    + s1 + s2 + s3 + s4 + s5 + s6 + s7 + s8 + s9 + s10;
        OutputDebugStringA(out);
    }
}

output: [2720] MASAR: Resize=12345678

Your problem is elsewhere

 
WHRoeder:
The problem is not there. Post the rest of the code.


I increased HPeriod 10 by 10 or 1 by 1 upon necessary.

Do you think what happened?

Nothing!!

2250 was accepted without any troublems though I did not change anything else in the code.

I cannot understand what was wrong at all even now.

I do not think it was caused by the spec of my PC because 2250 had not been accepted for long time even by other PCs.

Anyway I was increasing HPeriod.

Then I got another number which was refused by the code, 2417.

As I examined on which part the number was refused, the program may confuse on the following function.

But I cannot understand what is wrong nor why not wrong by 2416.

void Average3(double array[], int no_result, double &result[])
{
        int i, j, c;
        ArrayResize(result, no_result);

        i = 0;
        for(j = 0; j <= no_result - 1; j++)
        {
                c = 1;
                result[j] = array[i];
                while(array[i + 1] != 1000000)
                {
                        result[j] += array[i + 1];
                        i++;
                        c++;
                }
                i += 2;
                result[j] /= c;
        }
}

At first as I suspected I might have a mistake on ArrayResize, I canceled the for statement.

Nothing wrong.

And the second I suspected the line of "i+=2" because it made one bigger size to the array at the end of the j=no_result-1 loop.

So I changed the part as following.

                i += 1;
                result[j] /= c;
                if(i <= no_array - 1)  // no_array was added as another argument
                {
                      i += 1;
                }
                   

But 2417 is not accepted yet.

Incidentally the array has some 1000000s because the array was made from 2 dimentional array.

This code was wrote on C first.

But when I translated to MQL, I knew MQL was not good at the multi-dimentional array.

So I have changed all the 2 dimentional arrays to 1 dimentional arrays using 1000000s as the marker. 

 
void Average3(double array[], int no_result, double &result[])

There are no mind readers here. You keep showing little bits of code. On the above we have know idea what array is, what its size is, etc.

2D to 1D is irrelevant. And unnecessary. You can resize 2D arrays (the first dimension.) Don't use ArraySize, that returns the number of elements, you want the number of rows = ArrayRange(buffer,0)

 

I knew what was wrong and why the period of 2250 had been accepted suddenly.

I did not make any mistake at all.

The program cannot use the data before I opened the account!

So even if I find the max number of the period, I will be able to increase it only one more after a hour.

Do you know such a thing?

I did not!!

Anyway thank you all for kind advising! 

Reason: