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

 
// Возвращает скорректированный ORDER_REASON.
ENUM_ORDER_REASON GetOrderReason( const ulong Ticket )
{
  ENUM_ORDER_REASON Reason = ORDER_REASON_CLIENT;
    
  if (HistorySelectOrder(Ticket)) // https://www.mql5.com/ru/forum/170952/page186#comment_18099882
  {
    Reason = HistoryOrderGetInteger(Ticket, ORDER_REASON);
    
    if ((HistoryOrderGetInteger(Ticket, ORDER_TYPE) <= ORDER_TYPE_SELL) &&
        (Reason != ORDER_REASON_SL) && (Reason != ORDER_REASON_TP))
    {
      string PartComment = HistoryOrderGetString(Ticket, ORDER_COMMENT);

      if (StringLen(PartComment) > 3)
      {      
        PartComment = ::StringSubstr(PartComment, 0, 3);
        
        if (PartComment == "[tp")
          Reason = ORDER_REASON_TP;
        else if (PartComment == "[sl")
          Reason = ORDER_REASON_SL;      
      }
    }
  }
  
  return(Reason);
}
 
fxsaber :

A way was once proposed to determine the GMT offset of the server time. It doesn't always work exactly.

Below, it seems, is the exact version.


//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int TimeServerGMTOffset()
  {
   return (int)(TimeGMT()-TimeTradeServer());
  }
//+------------------------------------------------------------------+
 

The trading history can be full of market orders with REJECTED status. As a rule, these are the targets.

Some servers have a special feature for such market orders that have received a REJECT: the status is different - CANCELED.

 
Is this a bug or a bug with string conversion in time?
Print((datetime)"12:34"); //    Результат: 2021.01.15 12:34:00. Ожидалось: 1970.01.01 12:34:00.

// Выкручивание.
Print(((datetime)"12:34") % (24 * 3600)); //    Результат: 1970.01.01 12:34:00.
 
Is this piece turned into a constant at compile time?
StrDate = StringSubstr(StrDate, StringLen(StrDate) - StringLen("00:00:00 - 00:00:00"));
 
fxsaber:
Is this a bug or a chip with string to time conversion?

That's the way it's always been. But I would have done it a little differently...

Print(((datetime)"12:34") % PeriodSeconds(PERIOD_D1); //    Результат: 1970.01.01 12:34:00.

And if you just print out this time, all you have to do is

  Print(TimeToString(TimeCurrent(), TIME_SECONDS));
//Результат 
//2021.01.15 18:46:12.938       00 (EURRUB_TOD,H1)      18:31:18
 
Alexey Viktorov:

This has always been the case.

An interesting consequence then.

Print((datetime)""); // Текущая дата.

Concise and surprising. Because the compiler does not convert what appears to be a constant to a constant.

 
fxsaber:

An interesting consequence then.

Concise and surprising. Because the compiler doesn't convert what appears to be a constant to a constant.

Is the empty string the current date?

ps; Surprisingly... Indeed the current date, but the time is 1:00
 
fxsaber:

An interesting consequence then.

Concise and surprising. Because the compiler doesn't convert what appears to be a constant.

Does it substitute TimeCurrent or TimeLocal?)

I remember in some languages creating a date type automatically initializes it with the system time.

Документация по MQL5: Дата и время / TimeCurrent
Документация по MQL5: Дата и время / TimeCurrent
  • www.mql5.com
TimeCurrent - Дата и время - Справочник MQL5 - Справочник по языку алгоритмического/автоматического трейдинга для MetaTrader 5
 
Alexey Viktorov:

Current date indeed, but the time is 1:00 a.m.

No suggestion as to where the hour is coming from (the same for me). Probably depends on the time zone.


This is no longer interesting.

Print((datetime)"00:00"); // Текущая дата.