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

 
Alexey Viktorov:

Maybe it will do? It is not always correct for forex.

it shows the wrong value, for example for SBRF-9.17 trading session end time on Friday = = 23:45:00 according to the minute chart, and this function shows 00:00:00, according to information from the stock exchange ending time of the evening trading session at 23:50

If I wanted to check where we are and use constants, but maybe someone has already implemented this functionality, I would not have to write my own bicycle
 
Alexey Viktorov:

there is no dependency and there cannot be any. Consequently, there can be no special code.

Developers do not use RNG in such cases. The algorithms are precise and reproducible.

 
Konstantin:

How to determine the closing time of the previous day's market in the futures market in different variants of the current time interval:

1. we are in the interval Saturday - Sunday, we need the time of closure of Friday evening trading session
2. we are in the interval of Monday-Friday closed market; we need the closing time of evening session Monday-Thursday
3. we are in the trading range Monday and we need to close time of evening trading session on Friday
4. in Tuesday-Friday time frame we need the closing time for Monday-Thursday evening sessions

Maybe someone wrote a similar functionality, I do not want to re-invent the wheel ))

I don't think there is much more flexibility than constants:

/*!
   \brief   Расчет конечной даты запроса
*/
datetime CVolumeCluster::CalcStopDate(void) {
   MqlDateTime _date;
   datetime _time_t = TimeTradeServer(_date);

   if(_date.hour == 23 && _date.min >= 44) {          // определяем время окончания торговой сессии
      _date.hour = 23;
      _date.min  = 44;
      _date.sec  = 59;
      _time_t    = StructToTime(_date);
   } else {
      TimeToStruct(_time_t - 86400, _date);
      _date.hour = 23;
      _date.min  = 44;
      _date.sec  = 59;
      if(_date.day_of_week == 0 || _date.day_of_week == 6)
         _date.day_of_week = 5;
      _time_t = StructToTime(_date);
   }
//---
   return _time_t;
}
 

advise who works with CCanvas class, how to make updating of graphic mark less resource-intensive, for example we have several hundred thousand lines in the graphic mark, when you change the size you have to re-draw each line in the graphic mark, because without re-drawing by simply changing the size, the lines on the chart are not displayed, although the object of the graphic mark changes its size

 
Konstantin:

I guess you can't think of anything more flexible than constants:

Isn't that easier?

/********************Script program start function*******************/
void OnStart()
{
 datetime timeArray[1], barArray[1];
 CopyTime(_Symbol, PERIOD_D1, 0, 1, timeArray);
 CopyTime(_Symbol, PERIOD_M1, timeArray[0]-1, 1, barArray);
 Print(barArray[0];
}/*******************************************************************/
 
Alexey Viktorov:

Isn't this easier?

 CopyTime(_Symbol, PERIOD_D1, 0, 1, timeArray);              // время текущего дня 00:00:00
 CopyTime(_Symbol, PERIOD_M1, timeArray[0]-1, 1, barArray);  // время открытия - 1 секунду

The result is basically correct)) thanks

 
Now (1626) does not work

Forum on trading, automated trading systems and trading strategies testing

Peculiarities of mql5 language, tips and tricks

fxsaber, 2017.05.05 23:48

// Возвращает текущее количество объектов классов
int GetAmountObjects( void )
{
  const class CLASS_TMP {} Tmp;
  
  return((int)::StringFormat("%d", &Tmp) - 1);
}
Example application
int OnInit()
{
  if (GetAmountObjects() > 0)
    Print("До " + __FUNCSIG__ + " были вызваны конструкторы!");

  return(INIT_SUCCEEDED);
}
 
// Советник возвращает полностью сформированные торговые запросы (включая ручные)
#define  TOSTRING(A)  #A + " = " + (string)(A) + "\n"
#define  TOSTRING2(A) #A + " = " + EnumToString(A) + " (" + (string)(A) + ")\n"

string ToString( const MqlTradeRequest &Request )
{
  return(TOSTRING2(Request.action) + TOSTRING(Request.magic) + TOSTRING(Request.order) +
         TOSTRING(Request.symbol) + TOSTRING(Request.volume) + TOSTRING(Request.price) + 
         TOSTRING(Request.stoplimit) + TOSTRING(Request.sl) +  TOSTRING(Request.tp) + 
         TOSTRING(Request.deviation) + TOSTRING2(Request.type) + TOSTRING2(Request.type_filling) +
         TOSTRING2(Request.type_time) + TOSTRING(Request.expiration) + TOSTRING(Request.comment) +
         TOSTRING(Request.position) + TOSTRING(Request.position_by));
}

void OnTradeTransaction(   const MqlTradeTransaction&, const MqlTradeRequest& Request, const MqlTradeResult& )
{
  if (Request.action)
    Print(ToString(Request));
}

If there is a problem with the same Filling, run this EA and create the order you want manually (F9 in the terminal). The generated trade request will be printed by the Expert Advisor.

Unfortunately, it is problematic to do this on real accounts. The developers have rejected this suggestion.

 
fxsaber:

If there is a problem with the same Filling, run this EA and create the order you want manually (F9 in the terminal). The generated trade request will be printed by the Expert Advisor.

All that's missing is an example of how it works

 
Rashid Umarov:

All we need is an example of work

Manually expose


We get the generated trade request in the log

Request.action = TRADE_ACTION_PENDING (5)
Request.magic = 0
Request.order = 157092716
Request.symbol = EURUSD
Request.volume = 0.01
Request.price = 1.13941
Request.stoplimit = 0.0
Request.sl = 1.13926
Request.tp = 1.13955
Request.deviation = 0
Request.type = ORDER_TYPE_BUY_LIMIT (2)
Request.type_filling = ORDER_FILLING_RETURN (2)
Request.type_time = ORDER_TIME_SPECIFIED (2)
Request.expiration = 2017.07.11 12:08:00
Request.comment = 
Request.position = 0
Request.position_by = 0
I have not seen any difference in the way I was looking at it. That is why I came up with an offer.
Reason: