Close Position After certain number of hours

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

Close Position After certain number of hours

#1 Postby will111 » Sun Aug 05, 2012 3:30 am

Hi,

I am trying to write a code to send an instruction to close 2 open positions after the positions have been opened for longer than 15 hours, but I haven't been able to get it to work. Here's my code below. Would someone please help? Thanks!

if OrderSelect(OrderHandle1, SELECT_BY_TICKET, MODE_TRADES) then
if (HourOf(TimeCurrent)- HourOf(OrderOpenTime))> 15 then
begin
CloseOrder(OrderHandle1);
CloseOrder(OrderHandleL1);
OrderHandle1 := -1;
OrderHandleL1 := -1;
end;

Phil_Trade
Posts: 94
Joined: Tue Jan 31, 2012 5:14 am
Contact:

Re: Close Position After certain number of hours

#2 Postby Phil_Trade » Sun Aug 05, 2012 4:39 am

will111 wrote:Hi,

I am trying to write a code to send an instruction to close 2 open positions after the positions have been opened for longer than 15 hours, but I haven't been able to get it to work. Here's my code below. Would someone please help? Thanks!

if OrderSelect(OrderHandle1, SELECT_BY_TICKET, MODE_TRADES) then
if (HourOf(TimeCurrent)- HourOf(OrderOpenTime))> 15 then
begin
CloseOrder(OrderHandle1);
CloseOrder(OrderHandleL1);
OrderHandle1 := -1;
OrderHandleL1 := -1;
end;


Hi

I prefer to use

Code: Select all

HoursBetween(TimeCurrent , OrderOpenTime)>15

and I think you forget to OrderSelect(OrderHandleL1,...) before trying OrderClose(OrderHandleL1) ?
my live account - 8 based pairs with optimized parameters : +188%
http://www.myfxbook.com/members/Philipp ... jpg/519044
TradeSlide : http://bit.ly/14R9Nf6

to be informed about Windev/MT4 services : a04486-tradingsignal@yahoo.fr

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

#3 Postby will111 » Mon Aug 06, 2012 11:16 pm

Thanks for your reply!

I tried using the hoursbetween function but I realised my problem is that the system is pulling the wrong time. I used the print function and both the
timecurrent and opentime is giving 12:00:00 AM


Return to “FT API”

Who is online

Users browsing this forum: No registered users and 26 guests