Questions from Beginners MQL5 MT5 MetaTrader 5 - page 320

 

Dear programmers, please advise who knows!

I have an Expert Advisor for MT4 which closes a bunch of orders (500-2500) when reaching a total profit. As I noticed it closes orders one by one sorting them according to magic - from lesser to greater.

So, here is the question: is it possible to add to your Expert Advisor the function of launching a script at order closing which would close orders but sorting them by magician from the end - from larger to smaller?

Will this idea accelerate the speed of closing orders?

Somewhere I was told that up to 4 requests can be sent to server simultaneously.
 
Tapochun:
Then you need to look at the code... maybe it's the code... is there a line like that in the prints?
No. It's all been tested before, no questions asked... What else could it be?


 
Novikov:

Dear programmers, please advise who knows!

I have an Expert Advisor for MT4 which closes a bunch of orders (500-2500) when reaching a total profit. As I noticed it closes orders one by one sorting them according to magic - from lesser to greater.

So, the question is whether it is possible to add to Expert Advisor a function to launch a script at order closing which closes orders but sorts them by magician from the end - from larger to smaller?

And will this idea speed up the speed of closing orders?

Somewhere I was told that up to 4 requests can be sent to the server simultaneously.

You cannot run the script from the Expert Advisor. You can really send to the server several requests from different EAs at the same time. If you synchronize several EAs, you may indeed get some performance gain.

But if I were you, I wouldn't bash my head against the open door. I'd rather switch to MetaTrader5. The OrderSendAsync function allows you to close positions in batches at an incredible speed of 100-200 orders in a couple of seconds:

Forum on Trading, Automated Trading Systems and Strategy Tests

Developers! Error 10024 (Too many requests)

C-4, 2014.11.07 15:55

Anyway summing up my little research.

I managed to push 50 requests in 50 milliseconds; 100 requests in 180msec; 200 in 2100msec; 500 requests in 9000msec; 1000 requests in 23000msec. (the time is an average). I.e. the more we need to push the more time it takes. It may be a matter of illiterate coding.

The actual execution time of a bundle of requests is of course longer. This time seems to be equal to the worst case scenario - time of sending the request + time of request execution. In any case, in the limit it tends to the average time of order execution by the exchange + time spent on communication with the trade server. If the number of requests is less than 60, we do not need to communicate with the trading server, send all requests and wait for their fulfillment. The sending itself takes 40-60 milliseconds. If there are more requests, it is more difficult. You have to wait for the server's reply, switch on sending orders again, wait for the rejection, etc. So there is this exchange of messages over the network. When there are a lot of requests the pool is released gradually as the requests are fulfilled. Subsequent dispatches come in small portions, one or two requests at a time, and this is the network. Consequently the time grows. Anyway, the code seems to work correctly, you just need to understand the mechanism of sending/receiving requests.

I attached the code that tests such sending.

p.s. To sum it up, 60 requests is more than enough even for HFT trading. You actually need a conscious analysis of trade actions - you send an order, get the result, analyze the trade environment, send a new one if necessary. The whole cycle will clearly exceed the scale of 40-60 milliseconds + average execution time of 1 order.


 
R0MAN:
No. Everything used to test with no questions asked... any tips on what else could it be?


Try testing with fresh data. Have you tried running it in a different terminal?
 
Tapochun:
Try testing with fresh data. Have you tried running it in a different terminal?
No. I installed a new one today from bx. Tried to test on it. I'll try another one... I'll post the results here.
 
C-4:

It is not possible to run a script from an EA. It is indeed possible to send several requests from different EAs to the server at the same time. If you synchronize several EAs, it is indeed possible to get some performance gain.

But if I were you, I wouldn't bang my head against the open door. I'd rather switch to MetaTrader5. The OrderSendAsync function there allows you to close positions in batches at an incredible speed of 100-200 orders in a couple of seconds:



What does MT5 and moreover 100-200 orders have to do with it? And what 100-200 orders in MT5? These are 100-200 trading instruments in MT5! After all, only 1 order can be opened on 1 symbol - if I am not mistaken!

And I have an accumulation of a large number of orders on 28 instruments, and at the same time, partly with lots!

If you have something to suggest in the subject of the question, I would be grateful, and giving advice that is not related to the question is unnecessary and not constructive!

 
C-4:

It is not possible to run a script from an EA. It is indeed possible to send several requests from different EAs to the server at the same time. If you synchronize several EAs, it is indeed possible to get some performance gain.

But if I were you, I would not bang my head against the open door. I'd rather switch to MetaTrader5. The OrderSendAsync function there allows you to close positions in batches at an incredible speed of 100-200 orders in a couple of seconds:


О! Vasiliy, if you are here please look through my question, thank you.

 
R0MAN:
Oh! Vasily, if here, please look at my question, thank you.

Hi! Checked it out. Unfortunately, I have never encountered such an error before. The only thing that comes to mind is to check the history folder in the tester for example here y:\MetaTrader 5\tester\bases\AdmiralMarkets-MT5\history\. If there are no files for the required symbol, try to copy the data manually from the main folder y:\MetaTrader 5\bases\AdmiralMarkets-MT5\ and restart the tester. No other ideas so far.

s.e. Although it is strange. The tester should automatically copy the history. But there's no telling what.

 
C-4:
Hi! Checked it out. Unfortunately, I have never encountered such an error before. The only thing that comes to mind is to check the history folder in the tester for example here y:\MetaTrader 5\tester\bases\AdmiralMarkets-MT5\history\. If there are no files for the required symbol, try to copy the data manually from the main folder y:\MetaTrader 5\bases\AdmiralMarkets-MT5\ and restart the tester. I have no other ideas so far.
Thank you. I'll get back to campus... I'm on my mobile phone right now.
 
Novikov:

What does MT5 have to do with it, and especially 100-200 orders? And what are those 100-200 orders in MT5? These are 100-200 trading instruments in MT5! After all, only 1 order may be opened for 1 symbol - if I am not mistaken!

And I have an accumulation of a large number of orders on 28 instruments and at the same time partly with lots!

If you have something to suggest in this subject, I would be grateful, and to give advice that is not related to the question is useless and unconstructive!

Once again (read carefully):

In MetaTrader4 you can close orders only sequentially: send an order to close an order, wait for its execution, move on to the next order, etc. For this reason the time to close a batch of orders in MetaTrader4 is substantial and cannot be reduced by trivial means. However, you can upload several Expert Advisors to your own charts and make them exchange information with each other and close orders by a common command. Each expert closes orders only at its symbol. Since there are several trade threads in MetaTrader4, they would not block each other and send orders to each other. However, the organization of such a pool of experts is complicated, and judging by your level of knowledge, I would not advise you anything like that.

If you still think I've written too many words, here's a brief summary:

1. The answer to your question is no, you cannot run a script from an Expert Advisor.

2. You cannot increase execution speed of trade orders in MetaTrader4 without using complex methods.

The only way to solve your question normally is using the OrderSendAsync function, which does not exist in MetaTrader4.

Reason: