for (int i = 0; i < OrdersTotal(); i++) { OrderSelect(i, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() == Symbol() && OrderMagicNumber()== Num && OrderType() >= 2) { return(0); } }
qjol:
i can't understand what you mean's withe this code??
this code is checking if a pending order exist, if there is one, then, the EA does nothing
qjol:
qjol:
this code is checking if a pending order exist, if there is one, then, the EA does nothing
this code is checking if a pending order exist, if there is one, then, the EA does nothing
THANK YOU.FOR YOUR REPLAY,BUT IN MY EA I HAVE MORE THAN ONE PENDING ORDER WITHE DIFERENT PRICE SO I WANT TO ADD ANOTHER PENDING ORDER WITH PRICE OF CLOSING ORDER.
izmnaari:
i m wrote a code but when executing in program my EA place more thane one order.
this is what u wrote & i gave u the solution
can u be more specific what r u trying to accomplish
if(TimeCurrent()==OrderCloseTime()) // i think that this my error in using this condition
OrderCloseTime will be when the order closed. It will never be the time right now.
Go through open orders and find your buys and sells.
Go though the history and find the last buy or sell.
Always test return codes including orderSelect.
bool buySet = false, sellSet= false; for(pos = OrdersTotal()-1; pos >= 0 ; pos--) if ( OrderSelect(pos, SELECT_BY_POS) // Only my orders w/ && OrderMagicNumber() == magic.number // my magic number && OrderSymbol() == Symbol() // and my pair. ){ if (Direction( OrderType() ) > 0) buySet = true; else sellSet = true; } double buyPrice = 0, sellPrice = 0; datetime lastClose = 0; for(int pos=0; pos < OrdersHistoryTotal(); pos++) if ( OrderSelect(pos, SELECT_BY_POS, MODE_HISTORY) // Only orders w/ && OrderCloseTime() > lastClose // not yet processed, && OrderMagicNumber() == magic.number // my magic number && OrderSymbol() == Symbol() // and my pair. && OrderType() <= OP_SELL // Avoid cr/bal forum.mql4.com/32363#325360 ){ lastClose = OrderCloseTime(); if (Direction( OrderType() ) > ) buyPrice = OrderOpenPrice(); else sellPrice = OrderOpenPrice(); } if (!buySet){ if (buyPrice == 0) // No buy history, no buy open, no buy pending... //open your buy } if (!sellSet)... : double Direction(int op_xxx){ return( 1. - 2. * (op_xxx%2) ); }
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hola.
Please who can i place one and just one pending order (buy limit or sell limit) when an order is closed(buy or sell) withe the open price of this order closed.
The problem that i have is that i m wrote a code but when executing in program my EA place more thane one order.