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

 
fxsaber:
The proposed solution hasn't hit anything else yet. That's why I couldn't suggest it better.
Thank you for sharing.
 
fxsaber:
If you put the solution in front of the SB now, it becomes synchronized.
Can I give you a small example? When you connect classes - yours and SB's:
#include <Ваш_класс.mqh>
#include <Trade\Trade.mqh>
Compilation scolding starts
 
Artyom Trishkin:
Can I give you a little example? When I connect classes - yours and SB:
#include <Ваш_класс.mqh>
#include <Trade\Trade.mqh>
Compilation scolding starts

Getting into the theme)

Taken from here

 
Vitaly Muzichenko:

Getting into the theme)

Taken from here

Already done.

I just swapped the lines...
 
Artyom Trishkin:
Can I give you a little example? When I connect classes - yours and SB:
#include <Ваш_класс.mqh>
#include <Trade\Trade.mqh>
Compiling curse starts
My bad, I was overconfident, I didn't check it.
Vitaly Muzichenko:

I'll get into the subject.)

Yes, I forgot about that nuance. True, this restriction does not exist there anymore...

If you rearrange the inludes, then, of course, will not swear. But the effect will be null - SB will not be synchronized.

Unfortunately, I do not see a nice solution. So far

// Вместо #include <Trade\Trade.mqh> использовать этот код
// Это сделает СБ синхронизированным и не потребует каких-либо изменений в экспертах.

#ifdef OrderSend
  #undef OrderSend

  #define CTrade CTradeBase
    #include <Trade\Trade.mqh>
  #undef CTrade
  
  class CTrade : public CTradeBase
  {
    virtual bool OrderSend(const MqlTradeRequest &request,MqlTradeResult &result)
      {
       bool res;
       string action="";
       string fmt   ="";
    //--- action
       if(m_async_mode)
          res=::OrderSendAsync(request,result);
       else
          res=ORDERSEND::OrderSendSync(request,result); // единственное отличие от стандарта
    //--- check
       if(res)
         {
          if(m_log_level>LOG_LEVEL_ERRORS)
             PrintFormat(__FUNCTION__+": %s [%s]",FormatRequest(action,request),FormatRequestResult(fmt,request,result));
         }
       else
         {
          if(m_log_level>LOG_LEVEL_NO)
             PrintFormat(__FUNCTION__+": %s [%s]",FormatRequest(action,request),FormatRequestResult(fmt,request,result));
         }
    //--- return the result
       return(res);
      }
  };
  
  // Эта строчка позволяет сделать все OrderSend корректными.
  #define OrderSend ORDERSEND::OrderSendSync  
#else
  
#include <Trade\Trade.mqh>
#endif
 
fxsaber:
My bad, overconfidently stated, didn't check.

Yes, I forgot about that nuance. True, this restriction does not exist there anymore...

If you rearrange the inludes, then, of course, will not swear. But the effect will be null - SB will not be synchronized.

Unfortunately, I do not see a nice solution. For now you can see the following way

// Вместо #include <Trade\Trade.mqh> использовать этот код
// Это сделает СБ синхронизированным и не потребует каких-либо изменений в экспертах.

...
What if I need to inherit from Trade\Trade.mqh ? How?

Well, that is, to connect your class, and Trade\Trade.mqh will pull up.
 
Artyom Trishkin:
What if it is required to inherit from Trade\Trade.mqh ? How?

Well, that is, to connect your class, and Trade\Trade.mqh will be pulled up.
The inheritance will work as before. But you'd better specify your question.
 
fxsaber:
Inheritance will work as before. But you'd better clarify your question.
This code must be inherited from CTrade.

That is, make CTrade a base class in the first line of your code:

class ORDERSEND  : public CTrade
Respectively, it's no longer Trade\Trade.mqh that should be connected to your program, but rather an inculuder, for example #include <aTradeSync.mqh> that contains your class and #include <Trade\Trade.mqh> written there in the very beginning.

How should it be in this case? Instead of #include <Trade\Trade.mqh> insert the suggested code?
 
Artyom Trishkin:
Inherit this code from CTrade.

I.e., make CTrade a base class in the first line of your code:

class ORDERSEND  : public CTrade

Accordingly, you should not connect Trade\Trade.mqh to your program any more, but rather an inluder, for example #include <aTradeSync.mqh> which contains your class and #include <Trade\Trade.mqh> written there in the very beginning.

I wouldn't do it that way, because it would require changing previously written experts. And pure OrderSend will not be synchronized, only SB-OrderSend. Not everyone uses SB-only. Some people even use pure MQL5.

Therefore, the below solution seems to be optimal for the time being. All EAs will work without changes.

#include <OrderSendSync.mqh> // Если хочется, чтобы OrderSend был синхронизированным.
#include <TradeSync.mqh>     // Если подключен OrderSendSync.mqh - СБ станет синхронизированной, иначе - стандартной.
Files:
 
fxsaber:

I wouldn't do it this way, because it would require changing previously written experts. And pure OrderSend will not be synchronized, but only SB-OrderSend. Not everyone uses SB-only. Some people even use pure MQL5.

Therefore, the below solution seems to be optimal for the time being. All EAs will work without changes.

#include <OrderSendSync.mqh> // Если хочется, чтобы OrderSend был синхронизированным.
#include <TradeSync.mqh>     // Если подключен OrderSendSync.mqh - СБ станет синхронизированной, иначе - стандартной.
I see. Thank you.