| / | Forum |
|
rowand33
2006.08.08 19:49
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
|
|
All about Automated Trading Championship: Reporting the Championship 2007 The present article contains Weekly Reports of the ATC 2007. These materials are like snapshots, they are interesting-to-read not only during the Championship, but years later as well. |
5198 |
stringo
2006.08.09 11:47
|
|
rowand33
2006.08.10 05:40
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?
|
5198 |
stringo
2006.08.10 10:40
You can remove sleep but You must check price changes
|
|
rowand33
2006.08.10 19:33
How do you do that? Would it work if I just made the sleep shorter?
|
5198 |
stringo
2006.08.11 11:13
'How to place (and close correctly) multiple orders in an EA'
Just remove or comment line with Sleep function call |
|
ScottB
2006.08.12 23:01
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 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. |
|
irusoh1
2006.08.13 18:14
ScottB wrote: 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 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. |
|
irusoh1
2006.08.13 18:18
you need to add RefreshRates in your loop. this will give you latest bid/ask spread for each trade.
|
|
flag
2006.10.31 13:41
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. 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 |