# Thread: Help! Check for 2 opne Buy Orders...

1. ## Help! Check for 2 opne Buy Orders...

I'm having trouble with a simple line of code. Say I have 10 orders.... Both "Buys" and "Sells" open (hedge) in a single currency pair. I want to check if I have 2 buys (and 8 sells)... I want to do this to close other limit orders but this line of code is not working....

if((OrderType()==OP_SELL)&& OrdersTotal()==2)

2. Originally Posted by BillR
I'm having trouble with a simple line of code. Say I have 10 orders.... Both "Buys" and "Sells" open (hedge) in a single currency pair. I want to check if I have 2 buys (and 8 sells)... I want to do this to close other limit orders but this line of code is not working....

if((OrderType()==OP_SELL)&& OrdersTotal()==2)
The OrdersTotal() function returns the total number of of open orders in the pool regardless of their symbol, magic number or anything else. It will therefore include open buys and sells from other EAs as well.

You need to select your orders relating to just this EA and count them. You could do that through a function similar to this at the end of your code.

Code:
```int MyOrdersTotal(int Magic)
{
int c=0;
int total  = OrdersTotal();

for (int cnt = 0 ; cnt < total ; cnt++)
{
OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
if (OrderMagicNumber() == Magic && OrderSymbol()==Symbol())
{
c++;
}
}
return(c);
}```
You would then introduce a rule to do whatever you wanted according to the value returned by this function:

Code:
`if(MyOrdersTotal(Magic)==//you need to fill this in yorself;`
The function will return the total open orders for this EA. You might want to modify it to just return a count of open buy or open sell orders.

3. Jezzer Thanks...for your help!

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•