Yes, there is. You need to write code from which you close all orders.
jdegenfellner:
hi guys,
can anyone tell me if there's a command that closes all open orders at once?
I'm having some problems with an invalid order ticket when closing a certain position, so I thought it would be easier to close all existing orders....
thanks
jürgen
when you post some code maybe we can help you
jdegenfellner:
You should figure out why you have an invalid ticket number.I'm having some problems with an invalid order ticket when closing a certain position, so I thought it would be easier to close all existing orders....
//+------------------------------------------------------------------+ //| Close all open orders of a type or magic number. | //+------------------------------------------------------------------+ void CloseAll(int op=-1){ /* A TP or SL can be not closer to the order price (open, limit, or * stop) or closing price (filled order) than this amount. A pending * order price can be no closer to the current price than this * amount. On IBFX it's equal to 30 (3.0 pips.) */ double minGapStop = MathMax( MarketInfo(Symbol(), MODE_STOPLEVEL)*Point , 2*pips2dbl ), // Tester started returning 0! /* If the current price is closer than this to the TP, SL, (or pend- * ing price,) then the existing order can not be modified, closed, * or deleted. On IBFX it's equal to zero (in tester,) but I still * can't change it if market is closer than minGapStop either. */ minGapChange= MathMax(minGapStop, MarketInfo( Symbol(), MODE_FREEZELEVEL )*Point); for(int 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 symbol if (op >= 0 && OrderType() != op) continue; double oo.SL = OrderStopLoss(), oo.TP = OrderTakeProfit(), oo.price = OrderOpenPrice(), now.close = OrderClosePrice(); int DIR = Direction( OrderType() ); // Too close to close? if (oo.SL !=0 && (now.close - oo.SL)*DIR < minGapChange) continue; if (oo.TP !=0 && (oo.TP - now.close)*DIR < minGapChange) continue; int oo.ticket = OrderTicket(); if (!OrderClose( oo.ticket, OrderLots(), now.close, Slippage.Pips*pips2points, Aqua )){ Alert( "OrderClose(ticket=", oo.ticket, ", ...) failed: ", GetLastError()); } } return; } // CloseAll int Direction(int op_xxx){ return( 1 - 2 * (op_xxx%2) ); } //++++ These are adjusted for 5 digit brokers. double pips2points, // slippage 3 pips 3=points 30=points pips2dbl; // Stoploss 15 pips 0.0015 0.00150 int Digits.pips; // DoubleToStr(dbl/pips2dbl, Digits.pips) int init(){ if (Digits == 5 || Digits == 3){ // Adjust for five (5) digit brokers. pips2dbl = Point*10; pips2points = 10; Digits.pips = 1; } else { pips2dbl = Point; pips2points = 1; Digits.pips = 0; } // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl ... }
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
hi guys,
can anyone tell me if there's a command that closes all open orders at once?
I'm having some problems with an invalid order ticket when closing a certain position, so I thought it would be easier to close all existing orders....
thanks
jürgen