OCO order problem

How to create strategies and indicators
Message
Author
will111
Posts: 5
Joined: Fri Jun 29, 2012 4:27 am

OCO order problem

#1 Postby will111 » Fri Jun 29, 2012 4:43 am

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;

FT Support
Posts: 905
Joined: Sat Jul 11, 2009 10:54 am
Contact:

#2 Postby FT Support » Sat Jun 30, 2012 3:32 am

Hello,

Please explain why you select order by OrderHandle2 and then delete order by OrderHandle1
Check our other products here:
www.fx-metropolis.com
www.forexcopier.com

will111
Posts: 5
Joined: Fri Jun 29, 2012 4:27 am

#3 Postby will111 » Sat Jun 30, 2012 4:54 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;

FT Support
Posts: 905
Joined: Sat Jul 11, 2009 10:54 am
Contact:

#4 Postby FT Support » Sun Jul 01, 2012 9:09 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 products here:

www.fx-metropolis.com

www.forexcopier.com

will111
Posts: 5
Joined: Fri Jun 29, 2012 4:27 am

#5 Postby will111 » Sun Jul 01, 2012 9:22 am

This works! Thanks for your help!

themaxx
Posts: 5
Joined: Mon Feb 29, 2016 11:05 am

Re: OCO order problem

#6 Postby themaxx » Mon Feb 29, 2016 11:08 am

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?


Return to “FT API”

Who is online

Users browsing this forum: No registered users and 1 guest