How to work correctly in MT5 with OrderSend - page 6

 
Alexey Viktorov:

The first EA realises that after its OrderSend the history is not yet synchronised. He is just waiting for the event of synchronization.

But how does the second Expert Advisor understand that the history is synchronized or not yet?

 
fxsaber:

The first EA realises that after its OrderSend the history is not yet synchronised. He is just waiting for the event of synchronization.

But how does the second Expert Advisor understand that the history is synchronized or not yet?

Forget about the history. Try to study the behavior of the function OnTradeTransaction().

The first Expert Advisor has put a position and this event is handled in OnTradeTransaction where the wrong order is activated... This event is handled in OnTradeTransaction as well.

The second Expert Advisor also sifts out orders, positions, and trades that are not its own.

I have 2 EAs working in real accounts. In one of them the position magician assigns a ticket to the position to which it should be attached. And you understand yourself they are not two different magicians...

I think your name is Victor? Start setting two positions with different mages in the debug and trace their structures in OnTradeTransaction.

 
Alexey Viktorov:

Forget about the history. Try to study the behavior of the OnTradeTransaction() function.

The first Expert Advisor placed a position, OnTradeTransaction handles this event, "not theirs" are sifted out there, the order is activated... OnTradeTransaction handles this event as well.

The second Expert Advisor also sifts out orders, positions and trades that are not its own.

I have 2 EAs working in real accounts. In one of them the position magician assigns a ticket to the position to which it should be attached. And you understand yourself they are not two different magicians...

I think your name is Victor? Start setting two positions with different mages in the debug and trace their structures in OnTradeTransaction.

If you look carefully at my logs, you can see

that the ticket is received faster than OnTradeTransaction is triggered, so

the order ticket will be sufficient.

Although, of course (in this case) it's better to use Magician.

And (better yet) use OrderSendAsync - there are no errors, neither on FOREX, nor on FORTS.

 
prostotrader:

If you look closely at my logs, you can see,

that the ticket is received faster than the OnTradeTransaction, so

the order ticket will be sufficient.

Although, of course (in this case) it would be better to use Magician.

And (for now) it is better to use OrderSendAsync - there are no errors, neither on FOREX, nor on FORTS.

Maybe, this may be so. But what if the pending order is activated? Should we analyze the history? Another problem with the environment synchronization speed?

All in all, it is an amateur's game. The main thing is to make it work, not to slow down too much and to avoid...

 
Alexey Viktorov:

Forget the history. Try to study the behaviour of OnTradeTransaction()

How does the second one work during a non-synchronized history?

This problem does not only affect MT5, but also quadruple.

 
fxsaber:

How does the second one work during an unsynchronised history?

This problem not only affects MT5 but also quadruple as well.

I'm becoming even more certain that your name is Victor. I won't tell anyone your past nickname.

You have mastered the programming at an above average level in a short time, in my opinion, even above average. But it's very hard to move you from your erroneous position. And now that your level of programming knowledge is higher than mine, I'm not even going to try.

Forget the history, see the structures of the OnTradeTransaction function.

Try to explain in words, how do you determine in mql5 that a pending order is activated?

 
Alexey Viktorov:

I'm becoming even more certain that your name is Victor. I won't tell anyone your old nickname.

You've mastered programming in a short time...

Actually, it's another reincarnation of hrenfx. Decided to come in a new way.
 
prostotrader:

If you look closely at my logs, you can see,

that the ticket is received faster than the OnTradeTransaction, so

the order ticket will be sufficient.

Although, of course (in this case) it would be better to use Magician.

And (for now) it is better to use OrderSendAsync - there are no errors, neither on FOREX, nor on FORTS.

And what is the OrderSendAsync() advantage? It does not wait for response in Results. It means it has to be caught later. It's not clear what is the advantage.
 
prostotrader:

OrderSend() is an absolutely synchronous function - if a ticket is received, everything is executed.

Below is an example

Added, and here are the logs

https://www.mql5.com/ru/forum/38456/page85#comment_2888263

Thank you!
 

Forum on trading, automated trading systems and trading strategy testing

How do I know my commission without opening a position on a symbol?

fxsaber, 2016.11.08 20:30

#include <MT4Orders.mqh>

void OnStart()
{
  const int Ticket = OrderSend(_Symbol, OP_BUY, 1, SymbolInfoDouble(_Symbol, SYMBOL_ASK), 0, 0, 0);
  
  OrderClose(Ticket, 0.3, SymbolInfoDouble(_Symbol, SYMBOL_BID), 0, clrNONE);

  Sleep(1000); // ждем обновления истории
  
  if (OrderSelect(Ticket, SELECT_BY_TICKET))
    Alert(OrderCommission());
}

I guess this example is illustrative.

If you don't do Sleep, you often get a situation where the history hasn't had time to update after OrderClose and OrderCommission returns a value as if OrderClose hadn't been done.

Note that this is a script and there can be no Event-overs. The only way out is a dumb Sleep.

If you rewrite this script with SB, nothing will change.

Reason: