How to Do Multiple Trades at the Same Time with MQL4
Okay, so far, we had only one trade at a time. But we are going to change that right now. If you would like to trade several trades at a time, you actually need to know how much open trades you have. To count the open trades, I have included the GetOpenTradesThisPair.mq4 module and here is how it works. First, we will need a counter and set it to zero. Then, we need to count all the open orders, check if the currently selected order is the right currency pair, and if that is the case, the counter will be incremented by 1.
After the calculation is done, we are going to return the counter value, and right here, we are going to call the new GetOpenTradesThisPair() function with the current symbol. If you mark symbol and hit the F1 key, you will see that it returns the name of the symbol of the current chart. So, for the very first time, we would be able to trade different currency pairs and have a counter for each symbol.
Let’s see how it works. Hit the F4 key and start a back test. As you can see, we have multiple open orders here. Let’s include a comment line to count them. It will say OpenOrdersThisPair and it will call the function getOpenTradesThisPair with the current currency pair. Let’s recompile that and start a new back test. And here is the counter.