MQL5 - Opening trades on multiple currency pairs at the same time

Kacper Górzyński
30
Kacper Górzyński  

Hi!

I have an EA that checks every new bar and opens position when conditions are met. I would like it to work on multiple currency pairs, but there will be a limited number of currently working pairs, probably 2 or 3, because I don't want to be wiped out by a drawdown. So if they are already open positions on 2 or 3 pairs, any other pair can't open another one.

I would like to store currently active pairs count in a global variable, but I found a problem. Let's say that when new bar is opening, 5 pairs want to open their positions. What will happen if they do it at the same time? How to prevent it?


I figured out a solution, but I don't think it's optimal. It is based on first come first served method. I would like to take a random number of milisecounds for every pair (for example from 1 to 10000) and force a delay (Sleep() function), so they don't open positions all at once.


Do you have any better ideas to make it work properly?

Khuman Bakhramirad
1231
Khuman Bakhramirad  
you can set a check before each opening, if you show the code we can help you more 
Kacper Górzyński
30
Kacper Górzyński  

I haven't implemented any mechanism yet, but I also don't want anyone to code it for me. I'm just looking for the right solution.

I was thinking about triggering a timer, but only one timer is allowed in expert advisor and I already use it for other purposes.