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

 
mktr8591:

A real-life example of use - in the Virtual library, the VIRTUAL class contains static const VIRTUAL_DELETE VirtualDelete;

It can be replaced by static const VIRTUAL static_Virtual;

(and of course move the destructor to VIRTUAL) .

Do not. new-objects do not call their destructor when the program is terminated.

 
fxsaber:

You cannot. New objects do not call their own destructor when the programme is terminated.

I'm sorry, I don't understand where in VIRTUAL_DELETE is new?
 
mktr8591:
Sorry, not sure where in VIRTUAL_DELETE new?

In VIRTUAL::Create.


ZZZ The thread is not about Virtual...

 

Mining your Alert window.

#ifdef __MQL5__
  #include <WinAPI\WinAPI.mqh>
#else // #ifdef __MQL5__
  #define long int
    #define  pack(A)  
      #include <WinAPI\WinAPI.mqh>
    #undef  pack
  #undef long
  
  #undef  HANDLE
  #define  HANDLE int
#endif // #ifdef __MQL5__ #else

uint GetProcessID( const HANDLE Handle )
{
  uint ID = 0;
  
  user32::GetWindowThreadProcessId(Handle, ID);
  
  return(ID);
}

// Возвращает хендл Alert-окна.
HANDLE GetAlertHandle( void )
{  
  static HANDLE Handle = 0;
  
  if (!Handle)
  {
    static const string AlertCaptions[] = {"Alert", "Алерт"};
    static const uint ProcessID = GetProcessID((HANDLE)::ChartGetInteger(0, CHART_WINDOW_HANDLE));  
    
    for (int i = 0; i < sizeof(AlertCaptions) / 12; i++)  
    {
      Handle = user32::FindWindowW("#32770", AlertCaptions[i]);
      
      if (Handle && (GetProcessID(Handle) == ProcessID))
        break;
      else
        Handle = 0;
    }
  }
    
  return(Handle);
}
 

CPU load during custom events.

void OnInit()
{
  EventChartCustom(0, 0, 0, 0, NULL);
}

void OnChartEvent( const int id, const long&, const double&, const string& )
{
  if (id == CHARTEVENT_CUSTOM)
  {
    Sleep(0); // Без этой строки будет 100%-я нагрузка ядра CPU.
    
    EventChartCustom(0, 0, 0, 0, NULL);
  }
}
 
 

Sometimes DEAL_TIME is less than DEAL_ORDER_TIME_SETUP. Must be a bug in the brokers software.

// Показывает ордера, которые имеют время выставления ПОЗЖЕ сделок, которые породил.
#property script_show_inputs

input datetime inFrom = D'2021.06.01';

void OnStart()
{
  if (HistorySelect(inFrom, INT_MAX))
    for (int i = HistoryDealsTotal() - 1; i >= 0; i--)
    {
      const ulong Deal = HistoryDealGetTicket(i);
      const ulong Order = HistoryDealGetInteger(Deal, DEAL_ORDER);
      
      if ((HistoryOrderGetInteger(Order, ORDER_TICKET) == Order) &&
          (HistoryOrderGetInteger(Order, ORDER_TIME_SETUP_MSC) > HistoryDealGetInteger(Deal, DEAL_TIME_MSC)))
        Print((string)Order + " - " + (string)Deal);
    }
}


This is how it looks in the GUI.


 
fxsaber:

Sometimes DEAL_TIME is less than DEAL_ORDER_TIME_SETUP. Must be a bug in the brokers software.


This is how it looks like in the GUI.


Probably, it is a bug.

But it is possible to do it normally, isn't it? If the user/software changes the limit order after the partial execution, the ORDER_TIME_SETUP will be updated.

 
mktr8591:

But this is also possible, right? If the limit order is changed by the user/software after partial execution, ORDER_TIME_SETUP is updated.

This field is a constant. It is written together with the ticket.

 
fxsaber:

This field is a constant. It is written together with the ticket.

Apparently, I misunderstood the trading situation.

The way I pictured it: the pending limit was executed through several trades. During this time, it was hanging in live orders and the ORDER_TIME_SETUP field was not a constant. After the last trade it entered the history. At that moment, ORDER_TIME_SETUP became a constant.

Or was it not?