Features of the mql5 language, subtleties and tricks - page 175

 

Forum on trading, automated trading systems and trading strategies testing

Features of mql5 language, subtleties and tricks

fxsaber, 2017.11.30 09:48

Memo

Action/type of program Change of TF or symbol Account change
Indicator Run OnDeinit and OnInit, global class object changes (full reset). Nothing happens except that prev_calculated is reset.
EA Run OnDeinit and OnInit, global class object does not change. Running OnDeinit and OnInit, global class object changes (full reload).

Can you tell me how to avoid full restart of EA when re-logging (e.g. manually)?

I don't understand why everything is reset on re-logging. Is this a flaw?

 
fxsaber:

It works, but you can suggest the right macro.

If you don't care much about the quality of your crafts, then I care even less.

 
Vict:

If you don't care much about the quality of your crafts, then I care even less.

This is where you write about the features of MQL5.

 
fxsaber:

They write here about the features of MQL5.

Who says it's a feature and not a UB? Is there any information in the docs? In most cases UB is necessary to give freedom to the compiler to make all sorts of optimizations. What will be the result in different cases in real code - I don't know, it depends on the mood of the optimizer. I may run this code in crosses too and get some results, should I then be told "look what a peculiarity"?

I can run this code in crosses and get some results, and then I'll be told: "look, what's the peculiarity"?

 
Vict:

Who says it's a feature and not a UB? Is there any information in the docks?

This is where you write about things that aren't in the docks. Otherwise there is no point in the thread.

 
fxsaber:

This is where you write about things that aren't in the docks. Otherwise there is no point in the thread.

It would be meaningful if there were comments of developers, but otherwise...

So, yes, it is written in docks: execution order, - therefore, everything seems to be legal. But all the same, given that in the pluses is really fierce ub, I would like to make sure that the reference really mean exactly execution order and not associativity of operators.

 
fxsaber:

Can you tell me how to avoid a complete restart of the EA when re-logging (e.g. manually)?

I don't understand why everything is reset on re-logging. Is this a flaw?

I had the task to skip some calculations when re-logging, and to delete the Expert Advisor when changing the account. It was solved in one place.

This is what it looks like when we simply want to delete the Expert Advisor at account change.

string GetGlobalNameAccount( void )
{
  return(::MQLInfoString(MQL_PROGRAM_NAME) + (string)::ChartID() + "_Account");
}

void SaveAccount( void )
{  
  if (!::GlobalVariableSet(GetGlobalNameAccount(), CurrentAccount))
    ::Alert("GlobalVariableSet - ERROR!");
  
  return;
}

int LoadAccount( void )
{
  int Res = 0;
  
  const string Name = GetGlobalNameAccount();
    
  if (::GlobalVariableCheck(Name))
  {
    Res = (int)::GlobalVariableGet(Name);
    
    ::GlobalVariableDel(Name);      
  }
  
  return(Res);
}

const int CurrentAccount = (int)AccountInfoInteger(ACCOUNT_LOGIN);
int PrevAccount = 0;

int OnInit( void )
{
  PrevAccount = LoadAccount();
  
  bool Res = !PrevAccount || (PrevAccount == CurrentAccount);
  
  if (Res)
  {
    // .....
  }
  else
    Alert("Account is changed! " + (string)PrevAccount + " -> " + (string)CurrentAccount);
    
  return(Res ? INIT_SUCCEEDED : INIT_FAILED);
}

void OnDeinit( const int Reason )
{
  if (Reason == REASON_ACCOUNT)
    SaveAccount();
}


The simplest task in MQL5 makes me dance the subversion.

 
Vladimir Simakov:

It would make sense if there were comments from the developers, but otherwise...

So, yes, the docs say: execution order, - hence, everything seems to be legal. But all the same, given that in pluses it is really fierce ub, I would like to make sure that the help really means exactly execution order and not associativity of operators.

Please do not litter this branch. This thread is about features of MQL5, not C++

 
Artyom Trishkin:

Please do not litter this branch. This thread is about peculiarities of MQL5, not C++

It's weird, one writes on UB and the other blindly echoes him. Is it okay that in the MCL Help.

Note: Precedence of operations in MQL5 corresponds to the precedence С++, and differs from the priority given in MQL4.

And what is called "Order of execution" in the table is actually called "associativity" and has no effect on the order of evaluation, which in the general case is not defined.

Well, never mind, it's a thankless task, everyone here is such a fucking expert, so I'm not intruding.

 
Vict:
Attention: The priority of operations in MQL5 corresponds to the С++, and differs from the priority given in MQL4.

This most likely applies only to non-strict mode.

Hundreds of people have been writing cross-platform stuff here for years.
Reason: