A bug in the OrderSend() function ? - page 7

 
tara:
Because it doesn't provide for the variable to be initialised on program restart, it MUST.

Once again, for those in the tank:

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
   static int cc=20;
   Print("cc = ",cc);
   cc++;
   
   return(0);
  }
Example works. Initialisation works.
 
hoz:

Although this point(from the textbook) is not quite clear to me:

"Static variables are initialized once before calling the specialized init() function, i.e., the value of this variable is not lost when leaving the function, within which a static variable is declared.

What does this have to do with, " before calling the special init() function " and after " i.e. when you exit a user function (judging by the content) in which a static variable is declared? "

A function in which a static variable is declared can be at the end of a program... i.e. at the end of code or somewhere else. Theinit() function is executed once just before the program starts. It turns out to be inconsistent. How can a variable be initialized before theinit() function?

It doesn't matter where the function is in the program, static variables are outside of functions.
 
PapaYozh:
It doesn't matter where the function is in the program, the variables static are outside the functions.

What do you mean?
 
tara:

No, it won't. It's a bug :)
It's a bad habit to rely on default initialisation.
 
PapaYozh:

Once again, for those in the tank:

The example works. The initialisation works.

Clinic...

Yes, initialisation works. Exactly once. And on restart, it doesn't. I wish it did. Is that clearer?

 
For fuck's sake, don't use statics in EAs.
 
tara:

Clinic...

Yes, the initialisation works. Exactly once. And on restart, it doesn't. I wish it did. Is that clearer?

It shall work only once, when you restart the Expert Advisor.

What do you mean by restart, entering the Expert Advisor properties and exiting by pressing OK?

 
TheXpert:
For fuck's sake, don't use statics in EAs.
Not "don't use", but"use correctly" or"don't use incorrectly".
 

Yes, and also:

1. When the account is changed;

2. When changing an instrument;

3. When changing the TF.

Reason: