Exit before close of session  [SOLVED]

Questions about MultiCharts and user contributed studies.
paulc
Posts: 43
Joined: 26 Sep 2012
Has thanked: 7 times
Been thanked: 2 times

Exit before close of session

Postby paulc » 13 Nov 2012

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.

User avatar
TJ
Posts: 6584
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 970 times
Been thanked: 1907 times

Re: Exit before close of session  [SOLVED]

Postby TJ » 13 Nov 2012

paulc wrote: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
These users thanked the author TJ for the post:
paulc

paulc
Posts: 43
Joined: 26 Sep 2012
Has thanked: 7 times
Been thanked: 2 times

Re: Exit before close of session

Postby paulc » 15 Nov 2012

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?

User avatar
TJ
Posts: 6584
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 970 times
Been thanked: 1907 times

Re: Exit before close of session

Postby TJ » 15 Nov 2012

paulc wrote: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.

evdl
Posts: 399
Joined: 19 Jan 2011
Location: Netherlands
Has thanked: 84 times
Been thanked: 123 times

Re: Exit before close of session

Postby evdl » 15 Nov 2012

This bar is only for backtesting. You should use next bar.

Is in post 7 of the link TJ gave ;)
These users thanked the author evdl for the post:
TJ

paulc
Posts: 43
Joined: 26 Sep 2012
Has thanked: 7 times
Been thanked: 2 times

Re: Exit before close of session

Postby paulc » 15 Nov 2012

evdl wrote: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;

User avatar
TJ
Posts: 6584
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 970 times
Been thanked: 1907 times

Re: Exit before close of session

Postby TJ » 15 Nov 2012

paulc wrote:
evdl wrote: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.

paulc
Posts: 43
Joined: 26 Sep 2012
Has thanked: 7 times
Been thanked: 2 times

Re: Exit before close of session

Postby paulc » 15 Nov 2012

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.


Return to “MultiCharts”