B
You could use this function (or some variation of it) to count orders by type
int OpenTradesForMNandPairType(int iMN, string sSymbol, int iType) { int icnt, itotal, retval; retval=0; itotal=OrdersTotal(); for(icnt=0;icnt<itotal;icnt++) { OrderSelect(icnt, SELECT_BY_POS, MODE_TRADES); // check for opened position, symbol & MagicNumber if (OrderMagicNumber() == iMN) if (OrderSymbol() == sSymbol) if (OrderType() == iType) { retval++; } } return(retval); }
Good Luck
-BB-
OrderType is usefull to check if order is buy or sell.
Try this example;
if (OrdersTotal() > 0) { if (OrderType() <= 1) { //https://docs.mql4.com/trading/OrderType Comment("It's An Open Order"); } else Comment("It's A Pending Order"); }OPForex
thanks, but still have problem if order is open or pending. I need to know if is open....
OrderType is usefull to check if order is buy or sell.
mabe you have the answer - how check it?
int OrderType( ) Returns order operation type for the currently selected order. It can be any of the following values: OP_BUY - buying position, OP_SELL - selling position, OP_BUYLIMIT - buy limit pending position, OP_BUYSTOP - buy stop pending position, OP_SELLLIMIT - sell limit pending position, OP_SELLSTOP - sell stop pending position. Note: order must be selected by OrderSelect() function.
OrderType() does show if an order is open or pending!
if you have an order from the MODE_TRADES pool then it will be one of these 6 types. If it is not either of OP_BUY or OP_SELL then it is a pending order.
OPForex's test of OrderType() <= 1 relies on the #define'd symbols having particular values and is not a "robust" coding style.
You can do it this way ...
int total= OrdersTotal(); for( n=0; n<total; n++ ){ // count how many open orders we have for ALGO trades only if( !OrderSelect(n,SELECT_BY_POS,MODE_TRADES) ) continue; if( OrderSymbol()!=Symbol() ) continue; if( OrderMagicNumber()!=MAGICNUMBER ) continue; if( OrderType()== OP_BUY ){ // it's a BUY order } else if( OrderType()== OP_SELL ){ // it's a sell order } else{ // it is a pending order } }
or if you prefer lots of indenting
int total= OrdersTotal(); for( n=0; n<total; n++ ){ // count how many open orders we have for ALGO trades only if( OrderSelect(n,SELECT_BY_POS,MODE_TRADES) ){ if( OrderSymbol()==Symbol() ){ if( OrderMagicNumber()==MAGICNUMBER ){ if( OrderType()== OP_BUY || OrderType()== OP_SELL ){ // it's a BUY or SELL order } else{ // it is a pending order } } } } }
or if you love over-complicated logical expressions
int total= OrdersTotal(); for( n=0; n<total; n++ ){ // count how many open orders we have for ALGO trades only if( OrderSelect(n,SELECT_BY_POS,MODE_TRADES) && OrderSymbol()==Symbol() && OrderMagicNumber()==MAGICNUMBER ){ if( OrderType()== OP_BUY || OrderType()== OP_SELL ){ // it's a BUY or SELL order } else{ // it is a pending order } } }
There is no speed penalty with any of the approaches. It is a question of what you are more comfortable with.
I prefer the first method. Putting too many tests on each line make debugging harder.
I prefer the first method. Putting too many tests on each line make debugging harder.
for(int pos=OrdersTotal()-1; pos>=0; pos-- ) if( // Select my orders OrderSelect(pos,SELECT_BY_POS) && OrderSymbol() ==Symbol() && OrderMagicNumber()==MAGICNUMBER ){ if( OrderType() <= OP_SELL){} // open order else{ } // pending }
Thank you..
A theme is closed
I've got everythink what I've been looking for:)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I need to know if order is pending or open.
Do you know how can I make it?