MT5 and speed in action - page 18

 
Renat Fatkhullin:

You only have two states 5000 and an unlimited?

You are the mastermind of your own happiness.

Yes, you need either full control or superficial control. I don't see the point in the in-between.
 
Renat Fatkhullin:

In theory, yes.

Don't forget about synchronisation processes. A huge number of processes in the platform are asynchronous.

For example, a gateway integration with an exchange or liquidity provider may send transaction reports with delays of seconds or even minutes. Often the api does not provide access to history for reconciliation at all, but provides slow and non-rhythmic report generators.

At market opening, or due to an unexpected gateway reconnect, reports may be delayed. They are replicated to the history on the server and immediately asynchronously sent to the terminals. Because of the sorting by date, they are inserted in the right places, and in the meantime you can open new trades.

Most of the integration APIs are so illiterate and dysfunctional that they almost make it impossible to make guaranteed gateways. Although there's an opinion that this is a product of deliberate sabotage by their developers.

Should we give the right of choice? Who needs physical snaps and who needs enough to work with indexes with appropriate risks.

 
Comments not related to this topic have been moved to "Questions from MQL5 MT5 MetaTrader 5 beginners".
 
fxsaber:

Should we give the right to choose? Who needs physical snaps and who needs enough to work with indices with the appropriate risks.

What's the problem with keeping a local cache on the EA and sampling relative to the last update time? I do and have never had any lags with it. My network functions slow down the whole interface because of its synchronous implementation, it would be nice to have WebRequestAsync out of the box, although I'm already looking at DLL or even binding python and C++ wrappers, as there is a trading API in python :)

But working with large amounts of data without local caching is very strange.

PS. In general hash masks and caching are very much in demand in multicurrency and that is why I asked above in this thread for normal (read fast) hash masks out of the box.
Документация по MQL5: Сетевые функции / WebRequest
Документация по MQL5: Сетевые функции / WebRequest
  • www.mql5.com
Для использования функции WebRequest() следует добавить адреса серверов в список разрешенных URL во вкладке "Советники" окна "Настройки". Порт сервера выбирается автоматически на основе указанного протокола - 80 для "http://" и 443 для "https://". Функция WebRequest() является синхронной, это означает, что она приостанавливает выполнение...
 
Andrey Pogoreltsev:

What's the problem with keeping a local cache on the EA and sampling relative to the last update time?

The script does just that.

As for the local cache, that's how history is implemented in MT4Orders.

 
fxsaber:

As for the local cache, that's how MT4Orders implemented the story.

I did not expect that the script, which is two years old, would

Forum on trading, automated trading systems and testing trading strategies

OrderCloseTime Expert Advisor MQL5

fxsaber, 2018.07.06 00:49

#include <MT4Orders.mqh> // https://www.mql5.com/en/code/16006

void LastTimeMQL4( datetime &OpenTime, datetime &CloseTime )
{
  for (int i = OrdersHistoryTotal() - 1; i >= 0; i--)
    if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY) && (OrderType() <= OP_SELL))
    {
      OpenTime = OrderOpenTime();
      CloseTime = OrderCloseTime();
      
      break;
    }
}

void LastTimeMQL5( datetime &OpenTime, datetime &CloseTime )
{
  if (HistorySelect(0, INT_MAX))
  {
    for (int i = HistoryDealsTotal() - 1; i >= 0; i--)
    {
      const ulong Ticket = HistoryDealGetTicket(i);
  
      if (HistoryDealGetInteger(Ticket, DEAL_ENTRY) == DEAL_ENTRY_OUT)
      {
        CloseTime = (datetime)HistoryDealGetInteger(Ticket, DEAL_TIME);

        if (HistorySelectByPosition(HistoryDealGetInteger(Ticket, DEAL_POSITION_ID)))
          OpenTime = (datetime)HistoryDealGetInteger(HistoryDealGetTicket(0), DEAL_TIME);
          
        break;
      }
    }
  }
}

typedef void (*GetLastTime)( datetime&, datetime& );

void Bench( GetLastTime LastTime, const int Amount = 10000 )
{
  datetime OpenTime, CloseTime;
  datetime Tmp = 0;

  for (int i = 0; i < Amount; i++)
  {
    LastTime(OpenTime, CloseTime);
    
    Tmp += CloseTime - OpenTime;        
  }
  
  Print(Tmp);
}

#define  BENCH(A)                                                              \
{                                                                             \
  const ulong StartTime = GetMicrosecondCount();                              \
  A;                                                                          \
  Print("Time[" + #A + "] = " + (string)(GetMicrosecondCount() - StartTime)); \
}

#define  PRINT(A) Print(#A + " = " + (string)(A))

void OnStart()
{  
  if (HistorySelect(0, INT_MAX))
    PRINT(HistoryDealsTotal());

  BENCH(Bench(LastTimeMQL4))
  BENCH(Bench(LastTimeMQL5))  
}


will show such brakes!

// Первый запуск
2020.08.28 22:01:12.941 HistoryDealsTotal() = 9435
2020.08.28 22:01:13.198 2046.04.30 00:13:20
2020.08.28 22:01:13.198 Time[Bench(LastTimeMQL4)] = 257277
2020.08.28 22:01:43.982 2046.04.30 00:13:20
2020.08.28 22:01:43.982 Time[Bench(LastTimeMQL5)] = 30783493

// Второй запуск
2020.08.28 22:03:31.474 HistoryDealsTotal() = 9435
2020.08.28 22:03:31.724 2046.04.30 00:13:20
2020.08.28 22:03:31.724 Time[Bench(LastTimeMQL4)] = 250491
2020.08.28 22:04:02.011 2046.04.30 00:13:20
2020.08.28 22:04:02.011 Time[Bench(LastTimeMQL5)] = 30286258

Pure MQL5 is 100 times slower than partial (only HistorySelectByPosition) caching.

 
The test is unacceptable at all.

For MQL5-style, you have specifically tested 10 000 samples of HistorySelect on the whole depth. And you also added extra cycles.

Without a clear initial statement of the conditions, explaining their obvious bias and giving shocking numbers - this is the purest cheating and manipulation.

For such foul play with a wolfsbane ticket.
 
Renat Fatkhullin:
The test is not acceptable at all.

For MQL5 style you've tested 10 000 samples of HistorySelect on full depth. And you also added extra cycles.

Without a clear initial statement of the conditions, explaining their obvious bias and giving shocking numbers - this is the purest cheating and manipulation.

For such foul play with a wolfsbane ticket.

Well so your perception is wrong. It is shown that it is correct to cache yourself so that there is no thoromotion.

If I understand correctly, after this implementation.

Forum on trading, automated trading systems and strategy testing

MT5 and Speed in Action

Renat Fatkhullin, 2020.08.27 22:58

We already optimized a lot of sampling operations and now we are thinking about optimal update of the cache, when in reality 99% of samples will be completely useless and will be missed on fact.

That is, unless you specifically randomise the sampling limits, the cache will show hits close to 100%.

Most likely next week there will already be an effective solution.


this example will run much faster.


HH The script calculates the open/close time of the last position in the trading history.

 
fxsaber:

Shows you how to properly cache yourself, so that you don't get thrown off.

If you "cache" like this, it will be super-fast.

void LastTimeMQL5( datetime &OpenTime, datetime &CloseTime )
{
  static ulong PrevTicketIn = 0;  // Хранит тикет входа позиции с последнего вызова.
  static ulong PrevTicketOut = 0; // Хранит тикет выхода позиции с последнего вызова.
  
  if (HistorySelect(0, INT_MAX))
  {
    for (int i = HistoryDealsTotal() - 1; i >= 0; i--)
    {
      const ulong Ticket = HistoryDealGetTicket(i);
      
      if (Ticket == PrevTicketOut)            
      {
        OpenTime = (datetime)HistoryDealGetInteger(PrevTicketIn, DEAL_TIME);
        CloseTime = (datetime)HistoryDealGetInteger(PrevTicketOut, DEAL_TIME);        
        
        break;
      }
      else if (HistoryDealGetInteger(Ticket, DEAL_ENTRY) == DEAL_ENTRY_OUT)
      {
        PrevTicketOut = Ticket;
        
        CloseTime = (datetime)HistoryDealGetInteger(Ticket, DEAL_TIME);

        if (HistorySelectByPosition(HistoryDealGetInteger(Ticket, DEAL_POSITION_ID)))
        {
          PrevTicketIn = HistoryDealGetTicket(0);
          OpenTime = (datetime)HistoryDealGetInteger(PrevTicketIn, DEAL_TIME);
        }
          
        break;
      }
    }
  }
}

Who writes like this?

 
fxsaber:

If you 'cache it' like this, it's super-fast.

Who writes like this?

C programmers.