# Thread: How to count all open trades for specific pair with magicnumber?

1. Originally Posted by jidonk
Hi Jezzer,

Hopefully you don't mind teaching me another one:

for the EA to open another position ONLY when the previous position(s) are in a floating loss condition? I'm referring to dollar value of the loss, not based on pip step. (and still based on the specific pairs and magic)

For example,
if trade 1 & 2 are in -\$30, then open trade 3, .....

Thanks & Regards
It is easier to do that for your second example where the total of the open positions is negative than it is for the first example where just any single position is negative.

You can do the second example easily from within the existing function that has already been descibed.

Before anything else, you must define a variable

Code:
`double total_open_profit=0;`
In a new line between the OrderSelect() function and the if condition you then need to insert

Code:
`double individual_open_profit=OrderProfit()+OrderSwap()+OrderCommission();`
Then, within the braces where the orders are counted and after orders_total;, you need to insert

Code:
`total_open_profit=total_open_profit+individual_open_profit;`
What happens is that the function adds the profit from the current order to the previous total profit for every order that it counts. You can then use the value returned for total_open_profit to do your other things.

2. Originally Posted by jidonk
Hi Perky_Z,

Thanks for your help. But what I need is to COUNT all open trade not to Close all trades.

I'm using:

AllMyOrder = OrdersTotal();

but it seems to count all open trades regardless the the pair/magic.

Thanks
hehehe couldnt make it too easy :-)

3. Thanks a lot Jezzer

Regards