Closing position at end of day

Questions about MultiCharts and user contributed studies.
Xyzzy
Posts: 156
Joined: 19 Mar 2011
Has thanked: 43 times
Been thanked: 76 times

Closing position at end of day

Postby Xyzzy » 18 Apr 2012

I currently have a signal that's applied to one-minute charts. It uses a bracket order for exiting the position (profit target and stop loss). If the strategy doesn't hit either of the exit conditions during the day, then it places an "exit at market" order five minutes before the session close, using the following code:

Code: Select all

SetProfitTarget(ProfitTargetAmount);
SetStopLoss(StopLossAmount);
SetExitOnClose();
If Time >= TimeToExit then begin
   sell ( "EOD LX" ) this bar on close;
   buytocover ( "EOD SX" ) this bar on close;
end;


"TimeToExit" is set to 3:10 PM Central time, which is 5 minutes before the session close for the e-mini. I also have SetExitOnClose() thrown in for good measure, but that's just a fallback -- normally, the "Time >= TimeToExit" code should close out the position.

This strategy normally works fine. However, I had a hiccup today when I lost Internet connectivity before 3:10 PM. Once the 3:10 PM bar rolled around, MultiCharts couldn't connect to my broker to close out the position. As a result, my position remained open after the session close and I had to close it manually.

Is there any way to avoid this in the future? I would like to transmit a time-delayed order to Interactive Brokers that says, in essence, "if this order remains open after 3:10 PM, then exit at market." MultiCharts could theoretically transmit this order to Interactive Brokers immediately after I opened the position, so that IB would execute the order at 3:10 PM even if I lost Internet access.

Is a "time delayed" order like this possible? Or are MultiCharts and IB limited to transmitting orders only for immediate execution? Is there any other way to avoid this problem?

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

Re: Closing position at end of day

Postby TJ » 18 Apr 2012

Xyzzy wrote:I currently have a signal that's applied to one-minute charts. It uses a bracket order for exiting the position (profit target and stop loss). If the strategy doesn't hit either of the exit conditions during the day, then it places an "exit at market" order five minutes before the session close, using the following code:

Code: Select all

SetProfitTarget(ProfitTargetAmount);
SetStopLoss(StopLossAmount);
SetExitOnClose();
If Time >= TimeToExit then begin
   sell ( "EOD LX" ) this bar on close;
   buytocover ( "EOD SX" ) this bar on close;
end;


"TimeToExit" is set to 3:10 PM Central time, which is 5 minutes before the session close for the e-mini. I also have SetExitOnClose() thrown in for good measure, but that's just a fallback -- normally, the "Time >= TimeToExit" code should close out the position.

This strategy normally works fine. However, I had a hiccup today when I lost Internet connectivity before 3:10 PM. Once the 3:10 PM bar rolled around, MultiCharts couldn't connect to my broker to close out the position. As a result, my position remained open after the session close and I had to close it manually.

Is there any way to avoid this in the future? I would like to transmit a time-delayed order to Interactive Brokers that says, in essence, "if this order remains open after 3:10 PM, then exit at market." MultiCharts could theoretically transmit this order to Interactive Brokers immediately after I opened the position, so that IB would execute the order at 3:10 PM even if I lost Internet access.

Is a "time delayed" order like this possible? Or are MultiCharts and IB limited to transmitting orders only for immediate execution? Is there any other way to avoid this problem?


re: SetExitOnClose

see post #7
viewtopic.php?f=16&t=6929

Xyzzy
Posts: 156
Joined: 19 Mar 2011
Has thanked: 43 times
Been thanked: 76 times

Re: Closing position at end of day

Postby Xyzzy » 18 Apr 2012

Thanks. I'm familiar with the limitations on SetExitOnClose. That's why I have this code:

Code: Select all

If Time >= TimeToExit then begin
   sell ( "EOD LX" ) this bar on close;
   buytocover ( "EOD SX" ) this bar on close;
end;


The problem here is that I lost internet connectivity before "TimeToExit" rolled around, so the order was never transmitted to IB. I'd like to be able to transmit this order earlier in the day, with delayed execution. Is that possible?

User avatar
JoshM
Posts: 2089
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1525 times
Been thanked: 1485 times
Contact:

Re: Closing position at end of day

Postby JoshM » 19 Apr 2012

Xyzzy wrote:The problem here is that I lost internet connectivity before "TimeToExit" rolled around, so the order was never transmitted to IB. I'd like to be able to transmit this order earlier in the day, with delayed execution. Is that possible?

Sadly, MultiCharts doesn't support the more 'advanced' order types for IB (like the Good After Time Order attribute) so this isn't possible (as far as I know, but I hope I'm wrong). It's quite a shame, since the IB API does support these order types. Perhaps a Project Management request is in order here. :)

The 'solution' could be to close positions 10 minutes before the close so that, if your internet is down, you have time to get out before the close.
These users thanked the author JoshM for the post:
Xyzzy

Xyzzy
Posts: 156
Joined: 19 Mar 2011
Has thanked: 43 times
Been thanked: 76 times

Re: Closing position at end of day

Postby Xyzzy » 19 Apr 2012

Thanks JoshM. I suspected as much, but I was hoping that there'd be some way to make it work.

User avatar
Henry MultiСharts
Posts: 8503
Joined: 25 Aug 2011
Has thanked: 1213 times
Been thanked: 2731 times

Re: Closing position at end of day

Postby Henry MultiСharts » 01 May 2012

Xyzzy, please make sure you have installed the latest updater for IB TWS connection from this thread.
Unfortunately at the moment that is not possible to send a delayed order from MultiCharts.
We will evaluate the possibility of adding "Good After Time Order attribute" for one of the future versions of MultiCharts.
These users thanked the author Henry MultiСharts for the post:
Fu510n

seneca
Posts: 87
Joined: 02 Apr 2012
Has thanked: 36 times
Been thanked: 22 times

Re: Closing position at end of day

Postby seneca » 13 Jun 2016

I came across this old thread as I'm looking for a function that sends a "Good After Time" order to IB TWS in order to close open positions before session end in case of internet connectivity issues. Are there any plans to implement this feature in one of the future releases?

User avatar
Henry MultiСharts
Posts: 8503
Joined: 25 Aug 2011
Has thanked: 1213 times
Been thanked: 2731 times

Re: Closing position at end of day

Postby Henry MultiСharts » 15 Jun 2016

seneca wrote:I came across this old thread as I'm looking for a function that sends a "Good After Time" order to IB TWS in order to close open positions before session end in case of internet connectivity issues. Are there any plans to implement this feature in one of the future releases?
Hello seneca,

This is not something that is in our to-do list at the moment. You may want to submit a feature request to the Project Management of our web site so other users can vote for it: https://www.multicharts.com/pm/


Return to “MultiCharts”