Stop losses outside normal trading hours

I noticed that when submitting bracket orders out side of normal trading hours the stop loss doesn't trigger. I found out that part of the reason this is is because I didn't have "Allow order to be activated outside of normal trading hours" selected under global configuration in TWS. Now if I where to place a trade manually the stop works outside of normal trading hours but it doesn't when I submit it through AmiBroker. Really glad I caught this issue. However I couldn't find the documentation on this in specific so I though id ask as im sure others will eventually have the same question.

In short im trying to figure out to to submit stop losses that will get triggered/filled outside of normal trading hours.

2 Likes

Heres the code im using for the orders:

        if( ( BuyTrigger || LastValue( Buy ) ) )
        {
            if( LastTrade == "Sell" OR LastTrade == "" )
            {
                if( SellStatus == "Filled" OR SellStatus == "" )
                {
                    BuyOrderID = ibc.ModifyOrder( BuyOrderID, Name(), "BUY", 1, "LMT", last, 0, "GTC", False, 2500, "", "outsideRTH");
                    lmtID = ibc.ModifyOrder( lmtID, Name(), "SELL", 1, "LMT", var1, 0, "GTC", False, 2500, "", BuyOrderID, "outsideRTH" );
                    childID = ibc.ModifyOrder( childID, Name(), "SELL", 1, "STP", var2 , var2 , "GTC", transmit, 2500, "", BuyOrderID, "outsideRTH" );
                    StaticVarSetText( "BuyOrderID", BuyOrderID );
                    StaticVarSetText( "childID", childID );
                    StaticVarSetText( "lmtID", lmtID );
                    StaticVarSetText( "LastTrade", "Buy" );
                    SetChartBkColor( colorBrightGreen ) ;
                }
            }
        }

im specifying "outsideRTH" in the attributes section as specified in https://www.amibroker.com/at/ and its still not triggering outside of RTH. Not sure what im doing wrong.

Thanks

I figured it out I was following the docs for subhmit order instead of modify order here is the correct code:

        if( ( BuyTrigger || LastValue( Buy ) ) )
        {
            if( LastTrade == "Sell" OR LastTrade == "" )
            {
                if( SellStatus == "Filled" OR SellStatus == "" )
                {
                    BuyOrderID = ibc.ModifyOrder( BuyOrderID, Name(), "BUY", 1, "LMT", last, 0, "GTC", False, 2500, "outsideRTH");
                    lmtID = ibc.ModifyOrder( lmtID, Name(), "SELL", 1, "LMT", var1, 0, "GTC", False, 2500, "outsideRTH", BuyOrderID);
                    childID = ibc.ModifyOrder( childID, Name(), "SELL", 1, "STP", var2 , var2 , "GTC", transmit, 2500, "outsideRTH" , BuyOrderID);
                    StaticVarSetText( "BuyOrderID", BuyOrderID );
                    StaticVarSetText( "childID", childID );
                    StaticVarSetText( "lmtID", lmtID );
                    StaticVarSetText( "LastTrade", "Buy" );
                    SetChartBkColor( colorBrightGreen ) ;
                }
            }
2 Likes

Nice work, thanks for sharing the solution.
Have you verified that outsideRTH works during both RTH as well as outside?

On other brokers I've used they had order types for just inside, just outside, and a third for both.

1 Like

Yes it works for both! The docs also verify this.

1 Like

Hi flip,

Can you show me how & where you set the flag to outsideRTH=True in the attributes?

Thanks,

Mike

Hi Flip,

I added the "outsideRTH" parameter and I can execute LMT orders outsideRTH. However, when I try to execute a Stop or MKT order, it will only execute during regular market hours.

I found the below blurb from IB. Is your solution still working? If so, how did you work around the below?

Thanks,

Mike

  • For stocks, Market orders and Stop orders (which, when triggered, become Market orders) are only active from 09:30 until 16:00 EST (the Nyse's regular trading hours session). To have the order active in all sessions including the Premarket hours, Regular Trading Hours and the Aftermarket hours, you must use a Limit or Stop Limit type order and add the attribute "Allow Outside RTH". The same settings apply for Globex/ECBOT/Nymex Future contracts. The Nybot accepts Stop orders and converts them internally to "Stop with Protection" orders that are active for all available hours. A Future contract's RTH session is detailed in the contract's description window.

Hi @reds,

Could you pls provide a link for the above quote - I can't find a page on the IB website which has it.

Thanks

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.