How to check the total number of open orders?

 

How to check the total number of open orders?


Is there any function can do that?

I still don't get the meaning of OrdersTotal(), does it include all current open orders and stop loss/take profit orders?

or it only include open orders, if so my problem is solved.

hope someone can answer this, sorry if the questions too elementary...

 
Here, do your part read the Book.
 
ubzen:
Here, do your part read the Book.

int open_orders = 0;

for( int j = 0; j < Total; j ++){
OrderSelect(j, SELECT_BY_POS, MODE_TRADES);
if(OrdersTotal()==0) break;
if(OrderType()==OP_BUY) open_orders++; continue;
if(OrderType()==OP_SELL) open_orders++; continue;

}


I used the above code to check the total number of open orders, but it didn't work well, please correct me or give me a better solution, thanks!

 

Something like this, if you don't want to include the pending orders.

void start(){
    int open_orders = 0; int iMagic=777;
    for(int j=OrdersTotal()-1;j>=0;j--){
        if(OrderSelect(j,SELECT_BY_POS,MODE_TRADES)){
            if(OrderType()<2
            && OrderMagicNumber()==iMagic
            //&& OrderSymbol()==Symbol()
            ){
                open_orders++;
            }
        }
    }
}
 
ubzen:

Something like this, if you don't want to include the pending orders.

thanks, ubzen, i further added code to determine the trailing stop level. In this case, if there's 0 open orders, stoploss level will be 60pips below the open price.

double StopLossLevel;

for(int i=0;i<OrdersTotal(); i++){

if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)){

if(OrderSymbol() == Symbol()){

if(Ordertype() == OP_SELL && ) {

if(open_orders == 0) StopLossLevel == (Ask - 60*point);

if(open_orders == 1) StopLossLevel == (Ask - 40*point);

if(open_orders == 2) StopLossLevel == (Ask -20*point);

}

}

}

}

if(Signal_Buy == True)

Ordersend(...)

...


is it the correct way? I want to setup different Stoploss orders to multiple entries.

 
leonardodv:

is it the correct way?

no
 
qjol:
no
that's too hard to understand...can you please give a more detailed answer? thanks!
 
If your orders are all BUYs what will your StopLossLevel be set to ? and Ask is a moving target, what happens to Ask in between you setting your StopLossLevel and you actually using it ? and why is Ask the OpenPrice, when did you place the Order ? and it's bad practice to increment up in a loop going through the Open Orders.
 
leonardodv:

How to check the total number of open orders?


Is there any function can do that? <,,,yes

I still don't get the meaning of OrdersTotal(), does it include all current open orders and stop loss/take profit orders? <<<< all open & pending orders

or it only include open orders, if so my problem is solved.<<< what is your problem?

hope someone can answer this, sorry if the questions too elementary...????? stop this sorry thoughts & nothing to be sorry about. we will help you if you help yourself

"...even the most heinous deserves a fair chance at education..."
 
RaptorUK:
If your orders are all BUYs what will your StopLossLevel be set to ? and Ask is a moving target, what happens to Ask in between you setting your StopLossLevel and you actually using it ? and why is Ask the OpenPrice, when did you place the Order ? and it's bad practice to increment up in a loop going through the Open Orders.

m trying to divide my trades into 3 portions in a given trend, and each have different stoplosses, my goal is to control them seperately in a program.

e.x. in a uptrend:

1st entry will be buy signal == true, stoploss at 60*points below open price.

2nd entry will trigger when first entry price reach the openprice_1+ 60*points+spread, then move the stoploss to break even level. and stoploss for 2nd entry will be 40*points below openprice2.

3rd entry will trigger when 2nd entry price reach the openprice_2 + 40*points+spread, then move the stoploss of 1st entry and 2nd entry to each respective levels.

but if stoploss for 3rd and 2nd are triggered, there will be no re entries... is it a bad idea? m doing this in my manual trading though...

 
diostar:
"...even the most heinous deserves a fair chance at education..."

i have read the materials, it seems that these functions does not work as I understood them...but m trying really hard to find out why...thanks for helping me out, nice forum and really nice people!

Reason: