Is there a good way to do this? Right now I am using the following code: int numOrders
= OrdersTotal(); for (int i = 0; i numOrders; i++) { OrderSelect(0, SELECT_BY_POS,
MODE_TRADES); if (Symbol() == OrderSymbol()) { if (OrderType() == OP_BUY) { OrderClose(OrderTicket(),
OrderLots(), Bid, 3, Violet); } else { OrderClose(OrderTicket(), OrderLots(), Ask,
3, Violet); } } } But it doesn't seem to close them all in one tick... Is there
any reason for this? Thanks -Shane
- Close By - Trade - MetaTrader 5 for Android
- Close By - Trade - MetaTrader 5 for iPhone
- Real and Generated Ticks - Algorithmic Trading, Trading Robots
Can you do it without the 1 sec sleep?? When I am closing many trades, the price
changes while they are closing. Can this be avoided?
You can remove sleep but You must check price changes
How do you do that? Would it work if I just made the sleep shorter?
'How to place (and close correctly) multiple orders in an EA'
Just remove or comment line with Sleep function call
Just remove or comment line with Sleep function call
rowand33 wrote:
Is there a good way to do this? Right now I am using the following code: int numOrders = OrdersTotal(); for (int i = 0; i numOrders; i++) { OrderSelect(0, SELECT_BY_POS, MODE_TRADES); if (Symbol() == OrderSymbol()) { if (OrderType() == OP_BUY) { OrderClose(OrderTicket(), OrderLots(), Bid, 3, Violet); } else { OrderClose(OrderTicket(), OrderLots(), Ask, 3, Violet); } } } But it doesn't seem to close them all in one tick... Is there any reason for this? Thanks -Shane
Is there a good way to do this? Right now I am using the following code: int numOrders = OrdersTotal(); for (int i = 0; i numOrders; i++) { OrderSelect(0, SELECT_BY_POS, MODE_TRADES); if (Symbol() == OrderSymbol()) { if (OrderType() == OP_BUY) { OrderClose(OrderTicket(), OrderLots(), Bid, 3, Violet); } else { OrderClose(OrderTicket(), OrderLots(), Ask, 3, Violet); } } } But it doesn't seem to close them all in one tick... Is there any reason for this? Thanks -Shane
I took a completely different approach to this issue. I calculate where I want to exit and update the take profit value to that point. If the profit target changes use OrderModify to change the take profit value. You must be careful to do this prior to exceeding the minimum from the current price (usually around .0005 for the EURUSD). I have used this to exit dozens of orders in less than a second.
If you cannot easily calculate the take profit value well in advance, you can also put hedge orders in the opposite direction way above the market (in the case of longs), move them just prior to your exit and use OrderCloseBy for the actual exit. You won't incure the extra spread cost because most brokers don't charge the spread on a closing order.
ScottB wrote:
I took a completely different approach to this issue. I calculate where I want to exit and update the take profit value to that point. If the profit target changes use OrderModify to change the take profit value. You must be careful to do this prior to exceeding the minimum from the current price (usually around .0005 for the EURUSD). I have used this to exit dozens of orders in less than a second.
If you cannot easily calculate the take profit value well in advance, you can also put hedge orders in the opposite direction way above the market (in the case of longs), move them just prior to your exit and use OrderCloseBy for the actual exit. You won't incure the extra spread cost because most brokers don't charge the spread on a closing order.
rowand33 wrote:
Is there a good way to do this? Right now I am using the following code: int numOrders = OrdersTotal(); for (int i = 0; i numOrders; i++) { OrderSelect(0, SELECT_BY_POS, MODE_TRADES); if (Symbol() == OrderSymbol()) { if (OrderType() == OP_BUY) { OrderClose(OrderTicket(), OrderLots(), Bid, 3, Violet); } else { OrderClose(OrderTicket(), OrderLots(), Ask, 3, Violet); } } } But it doesn't seem to close them all in one tick... Is there any reason for this? Thanks -Shane
Is there a good way to do this? Right now I am using the following code: int numOrders = OrdersTotal(); for (int i = 0; i numOrders; i++) { OrderSelect(0, SELECT_BY_POS, MODE_TRADES); if (Symbol() == OrderSymbol()) { if (OrderType() == OP_BUY) { OrderClose(OrderTicket(), OrderLots(), Bid, 3, Violet); } else { OrderClose(OrderTicket(), OrderLots(), Ask, 3, Violet); } } } But it doesn't seem to close them all in one tick... Is there any reason for this? Thanks -Shane
I took a completely different approach to this issue. I calculate where I want to exit and update the take profit value to that point. If the profit target changes use OrderModify to change the take profit value. You must be careful to do this prior to exceeding the minimum from the current price (usually around .0005 for the EURUSD). I have used this to exit dozens of orders in less than a second.
If you cannot easily calculate the take profit value well in advance, you can also put hedge orders in the opposite direction way above the market (in the case of longs), move them just prior to your exit and use OrderCloseBy for the actual exit. You won't incure the extra spread cost because most brokers don't charge the spread on a closing order.
you need to add RefreshRates in your loop. this will give you latest bid/ask spread for each trade.
ScottB wrote:
... If you cannot easily calculate the take profit value well in advance, you can also put hedge orders in the opposite direction way above the market (in the case of longs), move them just prior to your exit and use OrderCloseBy for the actual exit. You won't incure the extra spread cost because most brokers don't charge the spread on a closing order.
... If you cannot easily calculate the take profit value well in advance, you can also put hedge orders in the opposite direction way above the market (in the case of longs), move them just prior to your exit and use OrderCloseBy for the actual exit. You won't incure the extra spread cost because most brokers don't charge the spread on a closing order.
Hi Scott,
Could you please explain how works and how to use OrderCloseBy ?
I have not found a clear explanation in the documentation neither any detailled example on the site.
thanks
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