Two orders with the same ticket number - page 3

 
yoriz #:

@fxsaber, thank you for your advice.

Some of my strategies must act very fast on each tick to update a very tight trailing SL. My most extreme trade lately was only open during 20 seconds, did 30 SL modifications in that time and made 1740 euros profit.

I am worried that reading the trading environment on each tick is too slow. Will that not take a lot of time?

It is not too slow. You are talking microseconds. If you are using non asynchronous ordersend you are already into the milliseconds.

Edit: Convenient way to measure speed of code https://www.mql5.com/ru/code/31279
 
yoriz #:

I don't trust anything anymore. If the ticket is invalid, the magic number might also be invalid.

I am disappointed in the MT5 platform. I did not expect a race-condition bug in a platform that must handle millions of ticks, hunderdthousands of orders, thousands of accounts, 24/7 day and night.

For me this was a very expensive way to learn about a bug in the MT5 platform. I don't think I can ask my money back at MetaQuotes?

You are right . I just mention that because the test case picks up the different magic number , so that works for now .

But indeed the best thing to do is wait for a fix .

Usually when @fxsaber reports an error it is fixed quickly .

 
Enrique Dangeroux #:

It is not too slow. You are talking microseconds. If you are using non asynchronous ordersend you are already into the milliseconds.

Edit: Convenient way to measure speed of code https://www.mql5.com/ru/code/31279

Thank you.

I measured this on 3 different VPSes (both small and large) on a live account with multiple open orders and open positions. It takes on average 14 usec to read the environment and get all the ticket numbers. That is certainly fast enough to do every tick.

 
Not trying to nitpick but 14 is rather slow. Avoid comparing strings like _Symbol==OrderSymbol(), string comparisons are slow. With only a hand full of orders/positions you should be able to come close to zero.
 
@Enrique Dangeroux #: Not trying to nitpick but 14 is rather slow. Avoid comparing strings like _Symbol==OrderSymbol(), string comparisons are slow. With only a hand full of orders/positions you should be able to come close to zero.
It is 14 microseconds, not milliseconds.
 
Fernando Carreiro #:
It is 14 microseconds, not milliseconds.

I know. I did say i was nitpicking.

In the spirit of Lorenzo 


 
Enrique Dangeroux #:
Not trying to nitpick but 14 is rather slow. Avoid comparing strings like _Symbol==OrderSymbol(), string comparisons are slow. With only a hand full of orders/positions you should be able to come close to zero.

Interesting. How can I filter out my orders and positions without checking the symbol? I do check the magic number first (integer comparison), but eventually need to verify the symbol, right?

--Edit-- Ok, I can swap the symbol (string comparison) and PositionType (enum comparison) checks, to postpone the string comparison until as late as possible. But I can not prevent the check, or can I?


for (int i = PositionsTotal()-1; i >= 0; i--) {
        CPositionInfo pos;
        if (pos.SelectByIndex(i)) {
                if (pos.Magic() != MagicNumber) continue;
                if (pos.Symbol() != _Symbol) continue;

                if (pos.PositionType() == POSITION_TYPE_BUY) {
                        buyTicket = pos.Ticket();
                }
        }
}
for (int i = OrdersTotal()-1; i >= 0; i--) {
        COrderInfo order;
        if (order.SelectByIndex(i)) {
                if (order.Magic() != MagicNumber) continue;
                if (order.Symbol() != _Symbol) continue;

                if (order.OrderType() == ORDER_TYPE_BUY_STOP) {
                        buyTicket = order.Ticket();
                }
        }
}
 

Checking last is best if you have to. I use unique magic for each ea as wel as per symbol. I can leave out checking for it. But you can encode the symbol into the magic. You do need some kind of system for that.

But like i said. Nitpicking. How much work to shave of some microseconds.

 
Enrique Dangeroux #:

I know. I did say i was nitpicking.

In the spirit of Lorenzo 


🤣

Enrique Dangeroux #:

Checking last is best if you have to. I use unique magic for each ea as wel as per symbol. I can leave out checking for it. But you can encode the symbol into the magic. You do need some kind of system for that.

But like i said. Nitpicking. How much work to shave of some microseconds.

do you produce the magic automatically oninit ? 

 
Lorentzos Roussos #:

🤣

do you produce the magic automatically oninit ? 

No, i use unique magic per symbol. But William gave an example recently.

Different timeframe, different symbol, they are all apples.