Code: Select all
If Time >= TimeToExit then begin
sell ( "EOD LX" ) this bar on close;
buytocover ( "EOD SX" ) this bar on close;
"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?