How to close if open for time

How to create strategies and indicators
Message
Author
Matt_mm
Posts: 17
Joined: Sat Jun 06, 2009 8:40 pm

How to close if open for time

#1 Postby Matt_mm » Sat Jun 20, 2009 7:46 am

Hi,

I'm trying to close pending positions if open for more than a certain time

I've tried:

Code: Select all

for i:=0 to OrdersTotal - 1 do
begin
  GetOrderInfo(i, info);
  if OrderSelect(i, SELECT_BY_POS, MODE_TRADES) then
  begin
    if (OrderType in [tp_BuyStop, tp_SellStop]) and ((info.OpenTime + DateUtils.OneHour*24) < DateOf(time)) then
    begin
       DeleteOrder(OrderTicket);
    end;
  end;
end;


With no luck.

I'd appreciate any suggestions.

User avatar
Terranin
Site Admin
Posts: 833
Joined: Sat Oct 21, 2006 4:39 pm

Re: How to close if open for time

#2 Postby Terranin » Sat Jun 20, 2009 11:03 am

Matt_mm wrote:Hi,

I'm trying to close pending positions if open for more than a certain time

I've tried:

Code: Select all

for i:=0 to OrdersTotal - 1 do
begin
  GetOrderInfo(i, info);
  if OrderSelect(i, SELECT_BY_POS, MODE_TRADES) then
  begin
    if (OrderType in [tp_BuyStop, tp_SellStop]) and ((info.OpenTime + DateUtils.OneHour*24) < DateOf(time)) then
    begin
       DeleteOrder(OrderTicket);
    end;
  end;
end;


With no luck.

I'd appreciate any suggestions.


It is unclear for me what is Time variable? If you did not set it, then it is standard function returning current time (your computer time, not trading time). If you need current trading time, use TimeCurrent (this function is available with new 2.1 version) or iTime(Symbol, 1, 0) to get time of the last 1 minute bar.

Also there is no need in GetOrderInfo, you can use OrderOpenTime instead of info.OpenTime.
Hasta la vista
Mike

Matt_mm
Posts: 17
Joined: Sat Jun 06, 2009 8:40 pm

#3 Postby Matt_mm » Wed Jul 01, 2009 12:02 am

Thanks Terranin,

It's working now, thanks for pointing out with the time variable I hadn't defined it:-)

Cheers,

Matt


Return to “FT API”

Who is online

Users browsing this forum: No registered users and 38 guests