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

 
Igor Makanu:

is different

there are so-called Control and Management tasks

EA - management, service - control

control should not be superfluous - if you consume all resources of the system, you get an unstable system instead of control

So what is the saving? The service will do the same enumeration of orders, the same comparisons.

If the idea is for one service to 'service' multiple advisors by sending them the 'something has changed' signal, then the solution is questionable.
Firstly, it is silly to wait for the critical data needed to make a decision from outside. And secondly, the savings, if any, will only be in the case of a multitude of Expert Advisors in one terminal.

This is more of a theoretical trick, in practice we have no problems with order lookup in the EA.

 
Some kind of glitch in MT5 has caught this situation.
ACCOUNT_TRADE_EXPERT = true
ACCOUNT_TRADE_ALLOWED = false
TERMINAL_TRADE_ALLOWED = true
Keep in mind that such a ban may be the result of the Terminal (bug), not the broker.
 
fxsaber:
Some kind of MT5 glitch caught this situation. Keep in mind that this ban may be the result of the Terminal (bug), not the broker.

It's not the same situation as Robo, the first 2 minutes the trade is closed and the quotes go?

Only I don't remember if trading is banned every day or only on Mondays for these 2 minutes.

 
Alexey Viktorov:

It's not the same situation as Robo, the first 2 minutes the trade is closed and the quotes are coming in?

Only I don't remember if every day or only on Mondays these 2 minutes are not allowed to trade.

No, this is in the middle of the day. MT5 failure, the broker is not involved.

 
Alexey Viktorov:

Only I don't remember if trading is banned every day or only on Mondays for those 2 minutes.

Only when the market opens
 
MessageBox does not show all the information in the log. When reading the log, there are sometimes questions. The solution is as follows.
// Терминал при MessageBox не выводит в лог имя MQL-программы, текст заголовка окна, флаги и результат нажатия.
int MessageBox2( const string Text, const string Caption = NULL, const int Flags = 0 )
{
  const int Res = MessageBox(Text, Caption, Flags);
  
#define  TOSTRING(A) " " + #A + " = " + (string)(A)
  Print("MessageBox:" + TOSTRING(Caption) + TOSTRING(Flags) + TOSTRING(Res));
#undef  TOSTRING
  
  return(Res);
}

#define MessageBox MessageBox2
 

Forum on trading, automated trading systems and trading strategies testing

Peculiarities of mql5, tips and tricks

fxsaber, 2020.04.30 08:49

Some glitch in MT5 has caught this situation.
ACCOUNT_TRADE_EXPERT = true
ACCOUNT_TRADE_ALLOWED = false
TERMINAL_TRADE_ALLOWED = true
Keep in mind that such a ban may be the result of the Terminal (bug), not the broker.

I got it again. I assume that this may occur in rare situations when re-logging.

Solution - if false, try again after a short pause.

bool IsTradeAllowed( const int Attempts = 0 )
{        
  // https://www.mql5.com/ru/forum/170952/page174#comment_16363677
  bool Res = false;
  int Count = 0;
  
  // https://www.mql5.com/ru/forum/170952/page174#comment_16363677
  while (!(Res = ::MQLInfoInteger(MQL_TRADE_ALLOWED) &&
                 ::AccountInfoInteger(ACCOUNT_TRADE_EXPERT) &&
                 ::AccountInfoInteger(ACCOUNT_TRADE_ALLOWED) &&
                 ::TerminalInfoInteger(TERMINAL_TRADE_ALLOWED)) &&
         (Count++ < Attempts) && !::IsStopped())
    ::Sleep(100);
    
  return(Res);
}
 
When you want to catch a change in a variable on assignment.
if (Value != (Value = NewValue()))
  Print("Value is changed.");
 
fxsaber:
When you need to catch a change in a variable on assignment.

You have UB here, you can't use it.

 
Vict:

You have UB here, you can't use it.

It works, but you can suggest a proper macro.

Reason: