# how to check the number of orders

138

hi guys only an advice: i need to check the number of pending order ( for the currency and for the type of order )

i have tried in this way:

for (int i=0; i<ordertotal() ;i++)
orderselect(i,select by pos);
if(ordersymbol()==symbol() and ordertype==op_sell )
x++
break

if x=0 ===>>>> no orders for this currency and this type order

but it doesnt go. if i use total=ordertotal () i can check only the number of pending orders while i need to check that there is only one order type BUY for EUR USD . have u some suggestion??

141

```int NOofBuy=0;
for(int i= OrdersTotal() - 1; i>=0; i--)
{
if(OrderSelect(i,SELECT_BY_POS)==true)
{
int Tip=OrderType();
if (Tip==0)
{
{
break;
}
}
}
}```
2441

```int x;
for (int i=0; i<OrdersTotal() ;i++)
{
OrderSelect(i,SELECT_BY_POS);
if(OrderSymbol()==Symbol() && OrderType==OP_SELL )
x++;
}
```
Just a little correction.
2326

giulioron:

... i need to check the number of pending order ...

For pending orders u need to check that OrderType() is one of the following:

 OP_BUYLIMIT 2 Buy limit pending position. OP_SELLLIMIT 3 Sell limit pending position. OP_BUYSTOP 4 Buy stop pending position. OP_SELLSTOP 5 Sell stop pending position.
138

first at all, thanks for support

roger, for example, with your suggestion

```int x;
for (int i=0; i<OrdersTotal() ;i++)
{
OrderSelect(i,SELECT_BY_POS);
if(OrderSymbol()==Symbol() && OrderType==OP_SELL )
x++;
}

```
in my EA, i want to buy ...for example, if there is " n "orders of this EA ( eur/usd and BUY ) regarding some conditions.

so i could use your variable "x" to verify the number of orders. not??

if x=n
.....
....

if x=n+1
....
....

i have tried but it doesnt go. it's strange because in fact the logical is correct and "x" should be verify the number of orders, the currency and the type .

i am wrong something?
1760

G
Check out this EA https://www.mql5.com/en/code/8714
for a function that counts by OrderType and OrderSymbol
Good Luck
-BB-

138

barrow thanks but it doesnt solve my problem

i have tried with the roger's suggestion ...........

but when i check x=1 ======> for example buy with lot 0.2

x=2 ===> buy with lot 0.3
x=3 ==> buy with lot 0.4

seems that the program doesnt see the function x

if i use x=ordertotal() ......it ìs ok but obviously i need to check also the currancy and the type of order

have u an advice??? i can undestand which is the block

1577

Have you declared x as an integer before attempting to increment it?
In other words do you have "int x" anywhere in your code?

CB
138

yes....i have put INT X at the beginning of program.... the problem is that i have to do something if x=1 or x=2 or x=3...

2441

```int x;
for (int i=0; i<OrdersTotal() ;i++)
{
OrderSelect(i,SELECT_BY_POS);
if(OrderSymbol()==Symbol() && OrderType==OP_SELL )
x++;
}
double lot;
if(x==1)lot=0.2;
else if(x==2)lot=0.3;
else if(x==3)lot=0.4;
if(lot!=0)OrderSend(...,lot,...);```
138

i will try again Roger. :-))))))))))) i continue to thanks u :-))

but i have just tried in similar way and it seems that the program doesnt recognize X=1 or X=2 ....

i will inform u this evening