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.
Exit before close of session [SOLVED]
- TJ
- Posts: 7774
- Joined: Aug 29 2006
- Location: Global Citizen
- Has thanked: 1036 times
- Been thanked: 2233 times
see post #6My 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.
viewtopic.php?f=16&t=10811
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?
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?
- TJ
- Posts: 7774
- Joined: Aug 29 2006
- Location: Global Citizen
- Has thanked: 1036 times
- Been thanked: 2233 times
This is not what I have coded.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 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;
- TJ
- Posts: 7774
- Joined: Aug 29 2006
- Location: Global Citizen
- Has thanked: 1036 times
- Been thanked: 2233 times
Look at my example again, I do not have the "marketposition = 1".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;
You do not need marketposition because a SELL/BUYTOCOVER will execute only if you have a position.
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.
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.