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

 
Evgeniy Chernish #:

https://www.mql5.com/ru/articles/15223

Yes, MinBLEIC used.

Thanks!

 
Vladimir Simakov local lifetime are called in the reverse order of their declaration. Therefore, in the code:

DoSomething will be called first, and only then the ~TSomeClass() destructor. Theoretically, we may not even have the TSomeClass source code on hand and not know what happens in the destructor.

However, if we do this:

, it is guaranteed that the TSomeClass destructor will be called first and only then, when the TScoupe destructor is executed, will DoSomething be called.

I don't even know how to respond to this answer.

I wasn't asking about the "advantages of wrapping in classes".

I was asking a completely different question.

 
Aleksandr Slavskii #:
Can you tell me, is this without OOP equal to the one below with OOP? And if not, what is the difference?
It is equivalent in function.
 
Sergey Gridnev #:
Functionally equivalent.

Thank you.

 
Reproducing a situation where the equity drawdown is less than the balance drawdown.
#include <MT4Orders.mqh> // https://www.mql5.com/ru/code/16006

#define  Bid SymbolInfoDouble(_Symbol, SYMBOL_BID)
#define  Ask SymbolInfoDouble(_Symbol, SYMBOL_ASK)

void OnTick()
{
  static const bool Init = OrderSend(_Symbol, OP_BUY, 1, Ask, 0, 0, 0) &&
                           OrderSend(_Symbol, OP_SELL, 1, Bid, 0, 0, 0);
}


 
fxsaber #:
void OnTick() { static const bool Init = OrderSend(_Symbol, OP_BUY, 1, Ask, 0, 0, 0, 0) && OrderSend(_Symbol, OP_SELL, 1, Bid, 0, 0, 0, 0); }

Dear fxsaber, may I ask why in the construct

void OnTick()
{
  static const bool Init = OrderSend(_Symbol, OP_BUY, 1, Ask, 0, 0, 0) &&
                           OrderSend(_Symbol, OP_SELL, 1, Bid, 0, 0, 0);
}

need static const?

 
Alexey Volchanskiy #:

Dear fxsaber, may I ask why in the design of the

need static const?

static - the variable is initialised only on the first OnTick call.

const - the variable will not be changed after initialisation. I write this way for self-control.

 
fxsaber #:

static - the variable is initialised only on the first OnTick call.

const - the variable will not be changed after initialisation. I write this way for self-control.

Thanks, I thought so. I just use static and const when inheriting classes, that's why I asked.

 

In the tester event a new bar in multisymbol trading.

// https://www.mql5.com/ru/forum/170952/page68#comment_6406566
#property indicator_chart_window
#property indicator_plots 0
enum inp
  {
   Tick,
   Bar
  };
input long Chart  = 0; // идентификатор графика-получателя события
input int Index   = 0;
input inp variant = Tick;
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total, const int prev_calculated, const int, const double &[])
  {
   if(prev_calculated)
      switch(variant)
        {
         case  Tick:
            EventChartCustom(Chart, 0, Index, 0, NULL);
            break;
         default:
            if(prev_calculated != rates_total)
               EventChartCustom(Chart, 0, Index, 0, NULL);
            break;
        }
   return(rates_total);
  }
//+------------------------------------------------------------------+

Convenient. Fast.

S.W. Maybe it was already written somewhere, but I haven't seen it.
 
Aleksandr Slavskii new bar in multisymbol trading.

Convenient. Fast.

S.W. Maybe it was already written somewhere, but I haven't seen it.

the method is not working, sometimes the system shows the information of the Past on the iCustom indicators on the first tick of a new bar, i.e. there will be one value in the array on 0 and 1 closed bar - "no signal".

and also requotes will have to be processed.

in case of simple indicator spy just on M1 we process all actions and there will not be afraid of requotes and glitches of the first tick, the robot will process all M1 signals and other situations.

Also in this case you can easily control the size of the maximum spread, instead of adding, checks opened-not opened.

I.e. on the first tick you can have 3 situations for not opening a trade on the New bar.