Page 1 of 1

Exit before close of session

Posted: Nov 13 2012
by paulc
My broker IB does not allow me to use exitonclose successfully. Sometimes it works and sometimes the market closes before the closing trade is executed.

I therefore want to close just before the end of session. I have the following code which i want to execute a closing trade if there is a position open, 1 minute before 9pm. Should this work or is there another way?

if marketposition <> 0 and currenttime = 2059 then close

Thanks.

Re: Exit before close of session  [SOLVED]

Posted: Nov 13 2012
by TJ
My broker IB does not allow me to use exitonclose successfully. Sometimes it works and sometimes the market closes before the closing trade is executed.

I therefore want to close just before the end of session. I have the following code which i want to execute a closing trade if there is a position open, 1 minute before 9pm. Should this work or is there another way?

if marketposition <> 0 and currenttime = 2059 then close

Thanks.
see post #6
viewtopic.php?f=16&t=10811

Re: Exit before close of session

Posted: Nov 15 2012
by paulc
Hi TJ, thanks again.

whilst the following works on a backtest it doesnt work with live trading. no closing trade is placed when live.

input:
Last.Order.Time(1555);

if Time > Last.Order.Time then
begin
if marketposition = 1 then sell this bar;
if marketposition = -1 then buytocover this bar;
end;

Is there any reason why this would be?

Re: Exit before close of session

Posted: Nov 15 2012
by TJ
Hi TJ, thanks again.

whilst the following works on a backtest it doesnt work with live trading. no closing trade is placed when live.

input:
Last.Order.Time(1555);

if Time > Last.Order.Time then
begin
if marketposition = 1 then sell this bar;
if marketposition = -1 then buytocover this bar;
end;

Is there any reason why this would be?
This is not what I have coded.

Re: Exit before close of session

Posted: Nov 15 2012
by evdl
This bar is only for backtesting. You should use next bar.

Is in post 7 of the link TJ gave ;)

Re: Exit before close of session

Posted: Nov 15 2012
by paulc
This bar is only for backtesting. You should use next bar.

Is in post 7 of the link TJ gave ;)

thanks evdl,

im hoping the following will work:

Code: Select all

input:
Last.Order.Time(1555);

if Time > Last.Order.Time then
begin
if marketposition = 1 then Sell next Bar at market ;
if marketposition = -1 then buytocover next bar at market ;
end;

Re: Exit before close of session

Posted: Nov 15 2012
by TJ
This bar is only for backtesting. You should use next bar.

Is in post 7 of the link TJ gave ;)

thanks evdl,

im hoping the following will work:

Code: Select all

input:
Last.Order.Time(1555);

if Time > Last.Order.Time then
begin
if marketposition = 1 then Sell next Bar at market ;
if marketposition = -1 then buytocover next bar at market ;
end;
Look at my example again, I do not have the "marketposition = 1".

You do not need marketposition because a SELL/BUYTOCOVER will execute only if you have a position.

Re: Exit before close of session

Posted: Nov 15 2012
by paulc
thanks all but now my strategy opens another position immediately after closing the last one.

i think it will be easier to get the exitonclose trade accepted by IB. i know i can trade after hours so it should be possible to use this existing script.