Hi, I am trying to code an OCO order 10pips above bar 1 high and 10 pips below bar 1 low. The pending orders go thru but it won't delete the other pending order after one order is executed. Could someone please help with my code below? Thanks!
//assign price
pBuy := High(1) + 10*Point;
pSell := Low(1) - 10*Point;
begin
SendPendingOrder(Symbol, op_BuyStop, 0.1, pBuy - 50*Point, pBuy + 60*Point, pBuy, '', 0, OrderHandle1);
SendPendingOrder(Symbol, op_SellStop, 0.1, pSell + 50*Point, pSell - 60*Point, pSell, '', 0, OrderHandle2);
end;
//OCO orders
if (OrderHandle1 <> -1) or (OrderHandle2 <> -1) then
begin
if OrderSelect(OrderHandle1, SELECT_BY_TICKET, MODE_TRADES) and (OrderType in [tp_BuyStop, tp_SellStop]) then
begin
DeleteOrder(OrderHandle2);
OrderHandle2 := -1;
end
else
if OrderSelect(OrderHandle2, SELECT_BY_TICKET, MODE_TRADES) and (OrderType in [tp_BuyStop, tp_SellStop]) then
begin
DeleteOrder(OrderHandle1);
OrderHandle1 := -1;
end;
end;
end;
OCO order problem
-
- Posts: 905
- Joined: Sat Jul 11, 2009 10:54 am
-
- Posts: 5
- Joined: Fri Jun 29, 2012 4:27 am
Hi,
Thanks for your reply. Sorry I am new to programming.
I want to select orderHandle1 and if it's a buy or sell order that is executed then I want to delete the other order. When the executed order is closed I want to restart the criteria for executing the pending orders again.
I made some changes but still not quite working. Could you please tell me what changes to the code I need to make? Thanks!
begin
SendPendingOrder(Symbol, op_BuyStop, 0.1, pBuy - 50*Point, pBuy + 60*Point, pBuy, '', 0, OrderHandle1);
SendPendingOrder(Symbol, op_SellStop, 0.1, pSell + 50*Point, pSell - 60*Point, pSell, '', 0, OrderHandle2);
end;
//OCO orders
if (OrderHandle1 <> -1) and (OrderHandle2 <> -1) then
begin
if OrderSelect(OrderHandle1, SELECT_BY_TICKET, MODE_TRADES) and (OrderType in [tp_Buy, tp_Sell]) then
begin
DeleteOrder(OrderHandle2);
end
else
if OrderSelect(OrderHandle2, SELECT_BY_TICKET, MODE_TRADES) and (OrderType in [tp_Buy, tp_Sell]) then
begin
DeleteOrder(OrderHandle1);
end;
end;
//Restart orders
if OrderClosed(OrderHandle1) and OrderClosed(OrderHandle2) then
begin
OrderHandle1 := -1;
OrderHandle2 := -1;
end;
Thanks for your reply. Sorry I am new to programming.
I want to select orderHandle1 and if it's a buy or sell order that is executed then I want to delete the other order. When the executed order is closed I want to restart the criteria for executing the pending orders again.
I made some changes but still not quite working. Could you please tell me what changes to the code I need to make? Thanks!
begin
SendPendingOrder(Symbol, op_BuyStop, 0.1, pBuy - 50*Point, pBuy + 60*Point, pBuy, '', 0, OrderHandle1);
SendPendingOrder(Symbol, op_SellStop, 0.1, pSell + 50*Point, pSell - 60*Point, pSell, '', 0, OrderHandle2);
end;
//OCO orders
if (OrderHandle1 <> -1) and (OrderHandle2 <> -1) then
begin
if OrderSelect(OrderHandle1, SELECT_BY_TICKET, MODE_TRADES) and (OrderType in [tp_Buy, tp_Sell]) then
begin
DeleteOrder(OrderHandle2);
end
else
if OrderSelect(OrderHandle2, SELECT_BY_TICKET, MODE_TRADES) and (OrderType in [tp_Buy, tp_Sell]) then
begin
DeleteOrder(OrderHandle1);
end;
end;
//Restart orders
if OrderClosed(OrderHandle1) and OrderClosed(OrderHandle2) then
begin
OrderHandle1 := -1;
OrderHandle2 := -1;
end;
-
- Posts: 905
- Joined: Sat Jul 11, 2009 10:54 am
Hello, i'm not sure if it will help but please try the code below
Code: Select all
begin
SendPendingOrder(Symbol, op_BuyStop, 0.1, pBuy - 50*Point, pBuy + 60*Point, pBuy, '', 0, OrderHandle1);
SendPendingOrder(Symbol, op_SellStop, 0.1, pSell + 50*Point, pSell - 60*Point, pSell, '', 0, OrderHandle2);
end;
//OCO orders
if (OrderHandle1 <> -1) and (OrderHandle2 <> -1) then
begin
if OrderSelect(OrderHandle1, SELECT_BY_TICKET, MODE_TRADES) then
if (OrderType in [tp_Buy, tp_Sell]) then
begin
DeleteOrder(OrderHandle2);
end
else
if OrderSelect(OrderHandle2, SELECT_BY_TICKET, MODE_TRADES) then
if (OrderType in [tp_Buy, tp_Sell]) then
begin
DeleteOrder(OrderHandle1);
end;
end;
//Restart orders
if OrderClosed(OrderHandle1) then
begin
OrderHandle1 := -1;
end;
if OrderClosed(OrderHandle2) then
begin
OrderHandle2 := -1;
end;
Check our other product here:
http://www.forexcopier.com
http://www.forexcopier.com
-
- Posts: 6
- Joined: Mon Feb 29, 2016 11:05 am
Re: OCO order problem
Could anyone please help me modify this code, to create a pending order script which opens a buy stop 5 pips above the current bar high, with the stoploss 5 pips below the current bar low?
Who is online
Users browsing this forum: No registered users and 20 guests