how to check the number of orders

 

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??

 
int NOofBuy=0;
for(int i= OrdersTotal() - 1; i>=0; i--)       
{
    if(OrderSelect(i,SELECT_BY_POS)==true)
    {
   int Tip=OrderType();                
   if (Tip==0)
     {
   NOofBuy++;
         if (NOofBuy>1)
         {
         Alert("more than one buy orders open);
         break;
         }
     }
   }
}
 
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.
 
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_BUYLIMIT2Buy limit pending position.
OP_SELLLIMIT3Sell limit pending position.
OP_BUYSTOP4Buy stop pending position.
OP_SELLSTOP5Sell stop pending position.
 

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?
 

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

 

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

 
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
 

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...

 
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,...);
 

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