Code to delete all pending orders but not open orders

How to create strategies and indicators
Message
Author
lhx
Posts: 5
Joined: Sun May 15, 2011 3:54 pm
Location: Texas

Code to delete all pending orders but not open orders

#1 Postby lhx » Tue May 17, 2011 9:47 pm

I'm trying to close all pending orders on a trigger... here's my code; for some reason I can't get it to close all 4 pending orders, only the first 2.

Code: Select all

begin
    if OrdersTotal > 4 then
     begin
     for i:=0 to OrdersTotal + 100 do
     begin
     OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
     if (OrderType = tp_BuyStop) then DeleteOrder(OrderTicket);
     if (OrderType = tp_SellStop) then DeleteOrder(OrderTicket);
     end
      end;
     end;

lhx
Posts: 5
Joined: Sun May 15, 2011 3:54 pm
Location: Texas

#2 Postby lhx » Tue May 17, 2011 11:06 pm

Solved:

Code: Select all

 for i:=-1 to MyOrderCounter do
           begin
            OrderSelect(i, SELECT_BY_TICKET, MODE_TRADES);
            if (OrderType = tp_SellStop) then DeleteOrder(i);
            if (OrderType = tp_BuyStop) then DeleteOrder(i);


Return to “FT API”

Who is online

Users browsing this forum: No registered users and 22 guests