MT5 and speed in action - page 30

 
Renat Fatkhullin:

one synchronised symbol database object. Read / Write locos are intermixed, as there is a constant tick write.

Is there one symbol database object for all symbols at once? If so, then it turns out that the request for a tick for EURUSD potentially slows down the request for a tick for GBPUSD.


Can you prepare a MqlTick for it by the time OnTick is called, so it won't be requested from the database on the general basis?

 
fxsaber:

Can you prepare a MqlTick for OnTick, so it won't be called from the database on the general basis?

That would be good, then maybe MQL5 will have predefined variables like in 4 - Ask and Bid

 

Most likely the slowdown is caused by high CPU consumption on the MT5 side when many EAs are running. Don't know how it is with MT4. Otherwise it's hard to explain why lags appear in a parallel running empty terminal.

Definitely, minimizing the use of trading environment API will solve the problem. After the tambourine dance I will report the results.

 
fxsaber:

You've got it wrong. Each EA is purely trading (in the Tester by real ticks not slowing down) and does not depend on others. All trading logic is executed only in OnTick, no spamming of trading orders, no recursion, no globalization and no resources.

OnTrade*, OnBook are not used. Second timer and OnChartEvent for the case when certain keys are pressed.


I am sure that proper implementation (by you or me) of snapshots will greatly reduce the number of calls of regular environment functions. Correspondingly, lags will be drastically reduced.

I never thought it would come to snapshot tricks. I am studying the issue, because the standard MT5 EA implementation is lame, unfortunately.

I can't believe your case at all.

We showed our calculations
 
Renat Fatkhullin:
I don't believe in your case at all.

Through TeamViewer or similar, ready to demonstrate.

 
::TerminalInfoInteger(TERMINAL_BUILD) = 2605
(bool)::TerminalInfoInteger(TERMINAL_X64) = true
(bool)::TerminalInfoInteger(TERMINAL_VPS) = false
::HistoryDealsTotal() = 13973
::HistoryOrdersTotal() = 18606
::TerminalInfoInteger(TERMINAL_MAXBARS) = 5000
::TerminalInfoInteger(TERMINAL_MEMORY_USED) = 1464
::MQLInfoInteger(MQL_MEMORY_USED) = 5
::ObjectsTotal(0) = 462
ChartsTotal = 16
::SymbolsTotal(true) = 19 (16 + 3)

Please advise how to reduce memory consumption by the Terminal? I'm using fresh ticks from CopyTicks for 16 characters. It seems, that each CopyTicks keeps in memory 128K ticks. I don't need them at all, but I keep them in memory. What does it take almost 1.5 GB? Can developers see what part of memory is used for what? Some rudimentary Task Manager.

 
fxsaber:

Most likely the slowdown is caused by high CPU consumption on the MT5 side when many EAs are running. I don't know how it is with MT4. Otherwise it's hard to explain why lags appear in a parallel running empty terminal.

Definitely, minimizing the use of trading environment API will solve the problem. I will write about the results after dancing with tambourines.

This is exactly what I was talking about a few pages ago. Moreover, EAs can be quite simple and based on non-liquid symbols, i.e., the matter is not the number of mathematical operations occurring inside the code of each of the EAs. The problem lies in the terminal itself and we will not be able to fix it through improving our code. Unfortunately :(

P.S I have rewritten the logic used in half of my EAs from OnBook back to OnTick and replaced the Core i5 by Xeon E5-2678. It would seem that speed should increase, but alas, a miracle did not happen :(

 
HistorySelect lags in OnTrade functions.
// Демонстрация лага HistorySelect в OnTrade*-функциях.
#include <fxsaber\Benchmark.mqh> // https://c.mql5.com/3/321/Benchmark.mqh

input int inAlertTime = 1; // Нижний порог в миллисекундах

#define _B2(A) _B(A, inAlertTime)

const bool Init = EventSetTimer(1);

void OnTimer()
{
  static MqlTradeRequest Request = {0};
  static MqlTradeResult Result = {0};

  if (PositionSelectByTicket(Result.order)) // Если позиция открыта - закрываем.
  {
    Request.type = ORDER_TYPE_SELL;
    Request.price = SymbolInfoDouble(_Symbol, SYMBOL_BID);
    Request.position = Result.order;
  }
  else // Иначе - открываем.
  {
    Request.action = TRADE_ACTION_DEAL;
    Request.type = ORDER_TYPE_BUY;
    Request.symbol = _Symbol;
    Request.volume = 0.1;
    Request.price = SymbolInfoDouble(_Symbol, SYMBOL_ASK);
    Request.position = 0;
  }

  const bool AntiWarning = OrderSendAsync(Request, Result); // Асинхронный приказ не случайно
}

void OnTrade()
{
  _B2(HistorySelect(0, INT_MAX));  
}


At almost every step.

2020.09.23 11:59:46.351 Alert: Time[Test6.mq5 437: HistorySelect(0,INT_MAX)] = 3 ms.
2020.09.23 11:59:46.354 Alert: Time[Test6.mq5 437: HistorySelect(0,INT_MAX)] = 2 ms.
2020.09.23 11:59:48.294 Alert: Time[Test6.mq5 437: HistorySelect(0,INT_MAX)] = 4 ms.
2020.09.23 11:59:48.296 Alert: Time[Test6.mq5 437: HistorySelect(0,INT_MAX)] = 2 ms.
2020.09.23 11:59:49.283 Alert: Time[Test6.mq5 437: HistorySelect(0,INT_MAX)] = 4 ms.
2020.09.23 11:59:49.285 Alert: Time[Test6.mq5 437: HistorySelect(0,INT_MAX)] = 2 ms.
2020.09.23 11:59:50.296 Alert: Time[Test6.mq5 437: HistorySelect(0,INT_MAX)] = 4 ms.
2020.09.23 11:59:50.302 Alert: Time[Test6.mq5 437: HistorySelect(0,INT_MAX)] = 5 ms.
2020.09.23 11:59:51.275 Alert: Time[Test6.mq5 437: HistorySelect(0,INT_MAX)] = 4 ms.
2020.09.23 11:59:51.277 Alert: Time[Test6.mq5 437: HistorySelect(0,INT_MAX)] = 2 ms.
2020.09.23 11:59:52.267 Alert: Time[Test6.mq5 437: HistorySelect(0,INT_MAX)] = 4 ms.
2020.09.23 11:59:52.269 Alert: Time[Test6.mq5 437: HistorySelect(0,INT_MAX)] = 2 ms.
2020.09.23 11:59:54.277 Alert: Time[Test6.mq5 437: HistorySelect(0,INT_MAX)] = 3 ms.
2020.09.23 11:59:54.282 Alert: Time[Test6.mq5 437: HistorySelect(0,INT_MAX)] = 5 ms.


Hopefully cache builds don't take so long, and this lag is due to database access during database update.

 

Any idea why mt5 does not feature the 'Commissions' tab? They only pop up after a trade is closed.

Any idea why mt5 does not feature 'Commissions' tab? They only pop up after a trade is closed.

 

If you run this EA on an account with no current positions or orders.

// Создает маркет-ордер в случае, если нет текущих позиций и ордеров.
bool PositionOpen()
{
  bool Res = (!PositionsTotal() && !OrdersTotal());
  
  if (Res)
  {
    MqlTradeRequest Request = {0};
    MqlTradeResult Result;
    
    Request.action = TRADE_ACTION_DEAL;
    Request.symbol = _Symbol;
    Request.volume = 0.1;
    Request.price = SymbolInfoDouble(_Symbol, SYMBOL_ASK);
    
    Res = OrderSendAsync(Request, Result);    
  }
  
  return(Res);
}

void OnInit()
{
  PositionOpen();
}

void OnTrade()
{
  PositionOpen();
}

and then manually close the position opened by the EA, then there will be three open positions on the hedge (on the netting triple volume position).


Is this the correct behaviour? I probably do not understand the Terminal correctly. Then please explain.