Download MetaTrader 5

array out of range

To add comments, please log in or register
Write articles, help other developers and make money
Laurentiu Sorin Tene
692
Laurentiu Sorin Tene 2013.03.31 18:08 

I am newbie, please help! 2 questions: a- why I receive "Array out of range" error message window when I run/debug this code? b-how to code to get the last error code on this script? Thank you in advance for your help !!!!

void OnStart()
  {
double buffer[];   
SetIndexBuffer(0, buffer);
buffer[2]=11;
  }
Alain Verleyen
Moderator
30707
Alain Verleyen 2013.03.31 18:20  
tenlau:

I am newbie, please help! 2 question: a- why I receive Array out of range on this code? b-how to code to get the last error code on this script? Thank you in advance for your help !!!!

void OnStart()
  {
    double buffer[];   
    //SetIndexBuffer(0, buffer);
    if (ArrayResize(buffer, 5) != -1) {     // 5 as example
        buffer[2]=11;
    }
    else {
        Print("Error : ", GetLastError());
    }
  }
SetIndexBuffer is for use in indicator not with a script.
Laurentiu Sorin Tene
692
Laurentiu Sorin Tene 2013.03.31 18:33  
angevoyageur:
SetIndexBuffer is for use in indicator not with a script.

Thank you!

But I receive the same error in an indicator . I extracted the code I posted from its code to be not so complicated, that is why I used SetIndecBuffer (because in indicator was it)

And ArrayResize() is not for static arrays?

Alain Verleyen
Moderator
30707
Alain Verleyen 2013.03.31 18:44  
tenlau:

Thank you!

But I receive the same error in an indicator . I extracted the code I posted from its code to be not so complicated, that is why I used SetIndecBuffer (because in indicator was it)

And ArrayResize() is not for static arrays?

A static array is...static :-D you can't resize it. See documentation.

Please note that you can't change the size for dynamic arrays set as indicator buffers by the function SetIndexBuffer(). For indicator buffers, all operations of size changes are performed by the executing sub-system of the terminal.

If you use SetIndexBuffer in an indicator, then you can't resize it.

It's better to show you indicator code if you need help.

Alain Verleyen
Moderator
30707
Alain Verleyen 2013.03.31 19:08  
I have to delete your post, this is decompiled code. Don't decompile someone else code.
Maxim Khrolenko
7075
Maxim Khrolenko 2013.03.31 21:54  
angevoyageur:
I have to delete your post, this is decompiled code. Don't decompile someone else code.
I am in shock that MQL5 compiled file may be decompiled already.
Alain Verleyen
Moderator
30707
Alain Verleyen 2013.03.31 22:14  
paladin800:
I am in shock that MQL5 compiled file may be decompiled already.
This is not MQL5, this is MQL4. He took MQL4 decompiled code and try to convert it to MQL5.
Maxim Khrolenko
7075
Maxim Khrolenko 2013.03.31 22:20  
angevoyageur:
This is not MQL5, this is MQL4. He took MQL4 decompiled code and try to convert it to MQL5.
Ok :)
To add comments, please log in or register