Hi,
I'm entering both a buy and sell order at the same time using the lines:
SendPendingOrder(Symbol, op_BuyStop, Lots, LongStopPrice,0, LongBreakoutPrice, '', 0, OrderHandleLong);
SendPendingOrder(Symbol, op_SellStop, Lots, ShortStopPrice,0, ShortBreakoutPrice, '', 0, OrderHandleShort);
The problem I'm having is resetting the OrderHandleLong and OrderHandleShort to -1 when the trades were closed automatically (by stop loss) during the week. Here's my code:
if OrderHandleLong <> -1 then
begin // select the order
if not(OrderSelect(OrderHandleLong, SELECT_BY_TICKET, MODE_TRADES)) then
begin
OrderHandleLong := -1;
exit;
end;
if OrderType = tp_BuyStop then // Delete pending long order
begin
DeleteOrder(OrderHandleLong);
OrderHandleLong := -1;
end;
if OrderProfit > 1 then // Close open position if profitable
begin
CloseOrder(OrderHandleLong);
OrderHandleLong := -1;
end;
end;
if OrderHandleShort <> -1 then
begin // select the order
if not(OrderSelect(OrderHandleShort, SELECT_BY_TICKET, MODE_TRADES)) then
begin
OrderHandleShort := -1;
exit;
end;
if OrderType = tp_SellStop then // Delete pending short order
begin
DeleteOrder(OrderHandleShort);
OrderHandleShort := -1;
end;
if OrderProfit > 1 then // Close open position if profitable
begin
CloseOrder(OrderHandleShort);
OrderHandleShort := -1;
end;
end;
Trades that I delete or close with this code have the OrderHandle set to -1 correctly, but trades that were already closed are not. According to 'Lesson 3 - Working with orders' if the OrderSelect 'function returns false then we assume that the order was closed by stop loss or take profit' but it doesnt seem to be working in my case. Is there an issue with my code (or understanding of how this works) or is this a bug?
I can reset the OrderHandles using OrderClosed() but I'd like to understand why the above code doesn't work. Any ideas?
cheers,
Swannyfx.
OrderHandle not resetting for closed trades
-
- Posts: 35
- Joined: Fri Jun 18, 2010 12:35 am
-
- Posts: 905
- Joined: Sat Jul 11, 2009 10:54 am
-
- Posts: 905
- Joined: Sat Jul 11, 2009 10:54 am
Hello Swannyfx,
OrderSelect function ignores "pool" parameter value if you pass "SELECT_BY_TICKET" value into flags parameter.
MetaTrader's OrderSelect function works in the same way, please see MT documentation:
http://docs.mql4.com/en/trading/OrderSelect
So please use OrderClose function for your purposes.
OrderSelect function ignores "pool" parameter value if you pass "SELECT_BY_TICKET" value into flags parameter.
MetaTrader's OrderSelect function works in the same way, please see MT documentation:
http://docs.mql4.com/en/trading/OrderSelect
So please use OrderClose function for your purposes.
Check our other product here:
http://www.forexcopier.com
http://www.forexcopier.com
Who is online
Users browsing this forum: No registered users and 26 guests