Questions from Beginners MQL5 MT5 MetaTrader 5 - page 687

 

How do I know why this construct doesn't work?

void OnStart()
  {
//---
   double buf[];
   ArrayInitialize(buf,0);
   for(int i=0; i<10; i++)
     {
      buf[i]= i;
     }
  }
It reports an error array out of range in '**.mq5' (13,10)
If I replace the string double buf[]; with double buf[10]; then there is no exit outside the array.
 
ivanivan_11:

Can you tell me why this construction doesn't work?

void OnStart()
  {
//---
   double buf[];
   ArrayInitialize(buf,0);
   for(int i=0; i<10; i++)
     {
      buf[i]= i;
     }
  }
reports an error array out of range in '**.mq5' (13,10)
if I replace the string double buf[]; with double buf[10]; then there is no exit for the array.

Either double buf[10];

Or double buf[];, but then necessarily ArrayResize(buf,10);

 
Artyom Trishkin:

Either double buf[10];

Or double buf[];, but then I have to do ArrayResize(buf,10);

Thank you.

can i explain something else?

I.e., if I initialize an array and then fill it in the loop, its size will grow with each iteration, and I'll have to redefine its size? I thought this is done automatically, no matter how many elements I add to it.

If I fill it immediately with a certain number of elements, I don't have to do this procedure.

void OnStart()
  {
//---
   double buf[];
   ArrayInitialize(buf,0);
   int closed1=CopyClose("EURUSD",NULL,0,3,buf);
  
  }
 
ivanivan_11:

Thank you.

Can I make it clearer?

I.e., if I initialize an array and then fill it in the loop, its size will grow with each iteration, and I'll have to redefine its size? I thought that's done automatically, no matter how many elements I add to it.

and if I fill it immediately with a certain number of elements, I don't have to do such a procedure.

void OnStart()
  {
//---
   double buf[];
   ArrayInitialize(buf,0);
   int closed1=CopyClose("EURUSD",NULL,0,3,buf);
  
  }

The CopyXXXX() function automatically overrides the size of the array passed into it.

If you fill in the array yourself, if it's dynamic, then it's up to the programmer to make sure it's the right size.

You can, when you declare an array, make it

  • a dynamic array, in which case it's up to you to re-define its size.
  • non-dynamic: buff[5] - in that case you need to initialize it with the right values
  • not dynamic: buff[]={10,20,30,40,50}; - in this case it is initialized with values at declaration
 
Artyom Trishkin:

The CopyXXXX() function automatically overrides the size of the array passed to it.

If you're filling the array yourself, if it's dynamic, it's up to the programmer to make sure it's the right size.

You can, when you declare an array, make it

  • a dynamic array, in which case it's up to you to re-define its size.
  • non-dynamic: buff[5] - in this case you need to initialize it with the right values
  • non-dynamic: buff[]={10,20,30,40,50}; - in this case it is initialized with values you declare
thanks for the clarification
 
Who knows what the numbers in the run graph mean in genetic optimisation? There are two numbers, for example 0.637 or 7.27. And how to choose the right run. For example, I am interested in the run number 5381. How to choose it?
 
who knows what the sign between the brackets is?GHPR=(BalanceClose/BalanceOpen)^(1/N)
 
Roma Ivanov:
who knows what the sign between the brackets is?GHPR=(BalanceClose/BalanceOpen)^(1/N)
Bitwise exclusive OR operation
 

Really? Really?

I always thought that(^) was an exponentiation.

 
Roma Ivanov:
who knows what the sign between the brackets is?GHPR=(BalanceClose/BalanceOpen)^(1/N)
Degree conversion.
Reason: