- [ARCHIVE!] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Can't go anywhere without you - 4.
- Open opposite order
- EA is opening too many orders at same price and time
void Close_AllOrders()
{
//Close Orders according to FIFO Rule
bool Result_Close;
for(i=0; i<OrdersTotal(); i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
if(OrderSymbol()==Symbol())
{
switch(OrderType())
{
case OP_BUY:
Result_Close=OrderClose(OrderTicket(),OrderLots(),Bid,0);
if(Result_Close) i--;
break;
case OP_SELL:
Result_Close=OrderClose(OrderTicket(),OrderLots(),Ask,0);
if(Result_Close) i--;
break;
}
}
}
/*-------------------------------------------------------------------------------------------------*/
}
This what I use.
You may have to change it to suit your needs.
Thanks for your response Donald but my situation is a bit more complex. If there is a big gap up in the cross rate (due to a Fed statement, etc.) I can have 3 or 4 limit orders executed at the same price and time. I can't embed a value in the Comment field either since the limit orders may not have been created sequentially. I can code around this but it requires multiple array passes and array resizes which consumes cycles and is not desirable in a fast moving market.
Initial State (Cross Rate 1.0795):
Limit 4 - 1.0815
Limit 3 - 1.0810
Limit 2 - 1.0805
Limit 1 - 1.08
State 2 (Cross Rate 1.080):
Limit 4 - 1.0815
Limit 3 - 1.0810
Limit 2 - 1.0805
Open Order 1 - 1.080
State 3 (Cross Rate 1.0790 - TP Order 1):
Limit 4 - 1.0815
Limit 3 - 1.0810
Limit 2 - 1.0805
Close Order 1 - 1.0790
Limit 5 - 1.08 (Replaces original Limit 1)
State 4 (Gaps up to 1.0812 & all open orders have same OpenTime):
Limit 4 - 1.0815
Open Order 3 - 1.08120
Open Order 2 - 1.08120
Open Order 5 - 1.08120
Programatically how do I determine FIFO?
- You already answered your own question, and provided a solution. You can't because the order opened when you have two identical prices means they open in the same second.
- Either make sure you don't have identical prices so the timestamps differ.
- Or, don't use pending orders. Humans can't watch the screen 24/7 so they use pending orders; EA's can, so no need for pending orders, have it wait until the market reaches the trigger price and open an order. Thus the order is ascending ticket numbers.
- You already answered your own question, and provided a solution. You can't because the order opened when you have two identical prices means they open in the same second.
- Either make sure you don't have identical prices so the timestamps differ.
- Or, don't use pending orders. Humans can't watch the screen 24/7 so they use pending orders; EA's can, so no need for pending orders, have it wait until the market reaches the trigger price and open an order. Thus the order is ascending ticket numbers.
- You already answered your own question, and provided a solution. You can't because the order opened when you have two identical prices means they open in the same second.
- Either make sure you don't have identical prices so the timestamps differ.
- Or, don't use pending orders. Humans can't watch the screen 24/7 so they use pending orders; EA's can, so no need for pending orders, have it wait until the market reaches the trigger price and open an order. Thus the order is ascending ticket number
mz1zcd:
Thanks for your response Donald but my situation is a bit more complex. If there is a big gap up in the cross rate (due to a Fed statement, etc.) I can have 3 or 4 limit orders executed at the same price and time. I can't embed a value in the Comment field either since the limit orders may not have been created sequentially. I can code around this but it requires multiple array passes and array resizes which consumes cycles and is not desirable in a fast moving market.
Initial State (Cross Rate 1.0795):
Limit 4 - 1.0815
Limit 3 - 1.0810
Limit 2 - 1.0805
Limit 1 - 1.08
State 2 (Cross Rate 1.080):
Limit 4 - 1.0815
Limit 3 - 1.0810
Limit 2 - 1.0805
Open Order 1 - 1.080
State 3 (Cross Rate 1.0790 - TP Order 1):
Limit 4 - 1.0815
Limit 3 - 1.0810
Limit 2 - 1.0805
Close Order 1 - 1.0790
Limit 5 - 1.08 (Replaces original Limit 1)
State 4 (Gaps up to 1.0812 & all open orders have same OpenTime):
Limit 4 - 1.0815
Open Order 3 - 1.08120
Open Order 2 - 1.08120
Open Order 5 - 1.08120
Programatically how do I determine FIFO?
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use