The great and terrible MT4 forever (or how to strategise a transition) - page 20

 
Andrey Khatimlianskii:

You can't talk with your tongue. You should teach me. Me, please.

There is a problem, and it's not just at this broker.
And the problem is not in waiting for the execution of a specific order (that is another matter), but in the fact that at the moment of order execution they temporarily disappear from all lists (open, closed, deals, positions).

We could use another crutch, of course. But we want to find a human solution. And so fxsaber works on it publicly, listening to barking of well-wishers passing by.

Personally, I hope you can understand the documentation

While the Expert Advisor handles trade transactions using the OnTradeTransaction() handler, the terminal continues handling newly arrived trade transactions. Therefore, the state of a trade account can change already while OnTradeTransaction() is running. For example, while an MQL5 program handles an event of adding a new order, it may be executed, deleted from the list of the open ones and moved to the history. Further on, the program will be notified of all these events.
and this applies not only to the OnTradeTransaction() event handler , but also to any part of the code after OrderSend() has been sent. Wait for the completion of the transaction. There are no other options and there won't be any. Just think why everything is so simple in mql4? Well, it's because these expectations are laid out far from your eyes. And in MQL5, you somehow think all checks and expectations are crutches. Why?
 
Alexey Viktorov:

Personally, I hope you have enough insight into such words of documentation

And this concerns not only OnTradeTransaction() event handler , but also any part of code after OrderSend() is sent. Wait for the completion of the transaction. There are no other options and there won't be any. Just think why everything is so simple in mql4? Well, it's because these expectations are laid down far from your eyes. And in MQL5, you somehow think all checks and expectations are crutches. Why?

Alexey, you are off the subject. Sorry, no time or inclination to explain it all again.

 

tried it this way:

void OnTrade()
{
   HistorySelect(TimeCurrent(),0);
   if(PositionsTotal() >= 10) return;
   MqlTradeResult result;
   BuyRequest.price = SymbolInfoDouble(_Symbol, SYMBOL_ASK);
   OrderSend(BuyRequest, result);
}

5 times I ran my code, until exactly 10 positions open

 
Igor Makanu:

tried it this way:

Run my code 5 times, until exactly 10 positions open

It looks like an error in setting the HistorySelect inputs.

 
fxsaber:

Looks like an error in setting the HistorySelect inputs.

idea to reach the server and synchronise

rewrote it as a script:

//+------------------------------------------------------------------+
void OnStart()
{
   MqlTradeRequest BuyRequest = {0};
   MqlTradeResult result = {0};
   BuyRequest.action = TRADE_ACTION_DEAL;
   BuyRequest.type = ORDER_TYPE_BUY;
   BuyRequest.symbol = _Symbol;
   BuyRequest.volume = 0.1;
   BuyRequest.type_filling = GetFilling();
   datetime t_start = TimeCurrent();
   while(PositionsTotal() < 10)
   {
      BuyRequest.price = SymbolInfoDouble(_Symbol, SYMBOL_ASK);
      if(!HistorySelect(TimeCurrent(), t_start) || ! OrderSend(BuyRequest, result)) continue;
      if(PositionsTotal() >= 10) return;
   }
}
//+------------------------------------------------------------------+
ENUM_ORDER_TYPE_FILLING GetFilling(const uint Type = ORDER_FILLING_FOK)
{
   const ENUM_SYMBOL_TRADE_EXECUTION ExeMode = (ENUM_SYMBOL_TRADE_EXECUTION)::SymbolInfoInteger(_Symbol, SYMBOL_TRADE_EXEMODE);
   const int FillingMode = (int)::SymbolInfoInteger(_Symbol, SYMBOL_FILLING_MODE);

   return((FillingMode == 0 || (Type >= ORDER_FILLING_RETURN) || ((FillingMode & (Type + 1)) != Type + 1)) ?
          (((ExeMode == SYMBOL_TRADE_EXECUTION_EXCHANGE) || (ExeMode == SYMBOL_TRADE_EXECUTION_INSTANT)) ?
           ORDER_FILLING_RETURN : ((FillingMode == SYMBOL_FILLING_IOC) ? ORDER_FILLING_IOC : ORDER_FILLING_FOK)) :
          (ENUM_ORDER_TYPE_FILLING)Type);
}
//+------------------------------------------------------------------+

ran it several times, also opens 10 positions, added the current start time of the script

 
Igor Makanu:

the idea of reaching the server and synchronising

rewrote it as a script:

ran it a few times, also opens 10 positions, added the current start time of the script

What will this change show?

#include <fxsaber\Benchmark\Benchmark.mqh> // https://www.mql5.com/ru/code/31279

      if(!_B(HistorySelect(TimeCurrent(), t_start), 1) || ! OrderSend(BuyRequest, result)) continue;
 
fxsaber:

What will this change show?


2021.05.09 21:35:06.210 tst (ETHUSD,H1) Benchmark.mqh: TimeAvg[GetMicrosecondsCount()] = 0 mcs.

2021.05.09 21:35:06.211 tst (ETHUSD,H1) Benchmark.mqh is On.

2021.05.09 21:35:06.211 tst (ETHUSD,H1) Alert: Bench_Stack = 0, 1 <= Time[tst.mq5 16 in OnStart: HistorySelect(TimeCurrent(),t_start)] = 20 mcs.

2021.05.09 21:35:06.308 tst (ETHUSD,H1) Alert: Bench_Stack = 0, 1 <= Time[tst.mq5 16 in OnStart: HistorySelect(TimeCurrent(),t_start)] = 6 mcs.

2021.05.09 21:35:06.404 tst (ETHUSD,H1) Alert: Bench_Stack = 0, 1 <= Time[tst.mq5 16 in OnStart: HistorySelect(TimeCurrent(),t_start)] = 10 mcs.

2021.05.09 21:35:06.501 tst (ETHUSD,H1) Alert: Bench_Stack = 0, 1 <= Time[tst.mq5 16 in OnStart: HistorySelect(TimeCurrent(),t_start)] = 13 mcs.

2021.05.09 21:35:06.597 tst (ETHUSD,H1) Alert: Bench_Stack = 0, 1 <= Time[tst.mq5 16 in OnStart: HistorySelect(TimeCurrent(),t_start)] = 10 mcs.

2021.05.09 21:35:06.694 tst (ETHUSD,H1) Alert: Bench_Stack = 0, 1 <= Time[tst.mq5 16 in OnStart: HistorySelect(TimeCurrent(),t_start)] = 3 mcs.

2021.05.09 21:35:06.792 tst (ETHUSD,H1) Alert: Bench_Stack = 0, 1 <= Time[tst.mq5 16 in OnStart: HistorySelect(TimeCurrent(),t_start)] = 4 mcs.

2021.05.09 21:35:06.888 tst (ETHUSD,H1) Alert: Bench_Stack = 0, 1 <= Time[tst.mq5 16 in OnStart: HistorySelect(TimeCurrent(),t_start)] = 3 mcs.

2021.05.09 21:35:06.989 tst (ETHUSD,H1) Alert: Bench_Stack = 0, 1 <= Time[tst.mq5 16 in OnStart: HistorySelect(TimeCurrent(),t_start)] = 4 mcs.

positions still 10pc, no doubling yet
 
Igor Makanu:

Positions are still 10 pcs, no doubling yet

The execution time of HistorySelect shows well that it does not request anything from the Trade server.


Several versions.

  1. You're in luck.
  2. This branch has caused a quiet change in the new build of the Terminal. Which is easy to confirm if there is a backlash in the old ones.
  3. Unusual behaviour of HistorySelect when From >= To.
  4. Trade server. Name?


Try the same way to get rid of the doubling here.

Forum on trading, automated trading systems and strategy testing

The Great and Powerful MT4 Forever (or how to strategize correctly to switch)

fxsaber, 2021.05.05 02:04

// Демонстрация открытия дубля позиции в MT5.

#include <Trade\Trade.mqh>

void OnStart()
{
  CTrade Trade;
  
  while (!IsStopped() && (PositionsTotal() <= 1)) // Закончим, когда появится более одной позиции.
    if (PositionsTotal() == 1)
      Trade.PositionClose(PositionGetTicket(0)); // Если есть позиция - закрываем.
    else if (!OrdersTotal())
      Trade.Buy(0.01); // Если нет позиции и ордера - открываем позицию.
}

Run this code on an empty demo account and see if two positions open in a few seconds.

 

I came by chance and read it - it's a shame !

No one should be trusted !
 
fxsaber:

You can clearly see from the execution time of HistorySelect that it does not request anything from the Trade server.


Several versions.

  1. You're in luck.
  2. This branch has caused a quiet change in the new build of the Terminal. Which is easy to confirm if there is a backlash in the old ones.
  3. Unusual behaviour of HistorySelect when From >= To.
  4. Trade server. Name?


Try the same way to get rid of the doubling here.

1. alas, can't survive in our business without it ))

2. I ask few days ago what build (not beta) is relevant, silence, I decided not to update, on a laptop and on a PC is hard to understand what builds are relevant - I have not worked with the terminals for a couple of months, not keep track. Now on the PC build 2903.

3. I'll pass, you are in charge of this banquet, developers are silent, my guess... thumb in the sky, I think the problem is in the network latency, and multiple sockets? terminal, no synchronization, one socket prices, another OrderSend, another where OnTrade()..... so packets are flying from where and where

4. i have robotforex + 100 mbps optical (ETTH), i had a bad mobile internet and fhopin on my laptop before


I tried it for 2 minutes, script flailed for 2 minutes, always one position, no reversals, I took the script off by hand

Reason: