Something I’m missing, however, just the code is already familiar probably.
In general, there is an Expert Advisor on MT5 that should open only one position on a signal. This is checked by the function:
void Fn_pos_find_market(ulong &tic1, ulong &tic2, int magic){
tic1=0; tic2=0;
datetime time1 = 0, time2 = 0;
for(int i=0; i ulong tic= PositionGetTicket(i);
if(tic<=0) continue;
if(!PositionSelectByTicket(tic)) continue;
if(PositionGetString (POSITION_SYMBOL)!=_Symbol) continue;
if(PositionGetInteger(POSITION_MAGIC)!=magic) continue;
if (tic1==0) { tic1=tic; time1=(datetime)PositionGetInteger(POSITION_TIME);}
else { tic2=tic; time2=(datetime)PositionGetInteger(POSITION_TIME);}
if(tic1>0 && tic2>0) break;}
if(time2>0 && time1>time2){ulong t=tic1; tic1=tic2; tic2=tic1;}}
Looking for 2 positions because there is still topping (ie, and looking for, and check if the position immediately) but not so important.
Here is the code at the beginning of the function that opened:
ulong t1, t2; Fn_pos_find_market(t1, t2, inp_magic);
if(t1>0 || t2>0) return(false);
The log clearly shows that the opening of the signal was 2 times with a difference of about 20ms (the message in the log writes when opening). At the time of execution of the second request, it is clear that the first one has already been executed (I sin that the broker may not have accepted it yet) They say that this happens when the volatility is increased.
According to the log (at 16: 00: 03 one transaction and 16: 00: 23 immediately another, the campaign for the next tick)
IP 0 16:00:03.884 Trades ‘15014283’: deal #1002308647 sell 0.02 USDJPY at 110.391 done (based on order #1003181634)
CN 0 16:00:03.885 Trades ‘15014283’: order #1003181634 sell 0.02 / 0.02 USDJPY at 110.391 done in 151.690 ms
—–
LO 0 16:00:23.083 Trades ‘15014283’: market sell 0.02 USDJPY sl: 110.445 tp: 108.510
CP 0 16:00:23.087 Trades ‘15014283’: accepted market sell 0.02 USDJPY sl: 110.445 tp: 108.510
EE 0 16:00:23.147 Trades ‘15014283’: deal #1002308940 sell 0.02 USDJPY at 110.352 done (based on order #1003181963)
JK 0 16:00:23.148 Trades ‘15014283’: order #1003181963 sell 0.02 / 0.02 USDJPY at 110.352 done in 64.595 ms
Or check not positions,but trades…
Re-opening the position…
Share
galina_bobro
Thank you very much for the idea, it would take me a very long time to get to this
fxsaber
This is an extra line.
The problem seems to be caused by this bug
Forum on trading, automated trading systems and testing of trading strategies
Libraries: mt4orders
fxsaber, 2017.07.24 23:39
When OrderSend was not synchronized with the trading environment of the terminal, automatic synchronization was built into mt4orders.
After a while, the developers built in synchronization and the old synchronization code was left in the library with a small exception – it began not only to synchronize, but also to check whether the synchronization of OrderSend from the developers works correctly. In case of an error, an alert should pop up
if (MT4ORDERS::OrderSendBug)
{
Alert("BUG!!!!!!");
There were reports that this Alert is triggered in rare cases (it seems, when the CPU is loaded), signaling that the OrderSend of developers is bad in matters of synchronization with the trading environment. How to report this to the developer in the SD-I do not know, because I can not reproduce it. But the fact remains.