Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

TimeInForce - TIF - Entries and Stops

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    TimeInForce - TIF - Entries and Stops

    I have been backtesting a strategy for some time against DX and today was my first live day. The first trade it took was rejected. After reviewing the logs, CQG rejected a GTC Market Order.

    I then changed the GTC timeinforce parameter in the strategy to Day. I re-enabled the strategy and excuted another trade that CQG accepted.

    My problem now is that when I backtest with Strategy Analyzer, the stops are not GTC, even though I'm issuing this:

    TradeStopOrder=ExitLongStop(0,true,qty,Price,"Stop loss",TradeName);

    1. I know I can't dynamically change the TIF parameter.
    2. I know for this DX instrument, it has to be DAY
    3. I'm not sure what to do with the Stop that runs multi-day. Do I have to write code to put the Stop back on every night?
    4. Why can't I override the ENTERLONG with a timeinforce (DAY) option and leave the strategy TIF parameter set to GTC?
    5. Or, why doesn't the true flag actually send the ExitLongStop with a GTC flag when using the strategy TIF parameter set to DAY?

    Thanks
    John

    #2
    Hi John,

    TIF (time in force) is an order flag and is used across brokerages for manual and automatic trading. This is a separate component compared to NT's internal order management in a strategy. TIF is set per strategy, but each order you send in the strategy can be either liveUntilCancelled true or false.

    By default, orders are cancelled if they are not filled on the bar they're submitted to. This is the liveUntilCancelled = false behavior. If the condition remains true from bar to bar they're resubmitted.

    You are using the liveUntilCancelled = true property for your orders, so you should expect that the stop order has "GTC behavior". The actual TIF flag isn't changed, but the order will stay active until manually cancelled or the position is closed.

    What you will have to do next to track strategy order submission in a backtest is enable TraceOrders = true; in your strategies Initialize() method, and view output in Tools > Output Window. This will let you know all messages related to strategy orders and highlight those that may be generating internal order handling rules.

    In a backtest, you can't visualize live orders - only the fills, so the only way to properly evaluate if this is working is to use trace orders output and well-placed print statements. Take a look at the output, and let us know if we can offer additional assistance.

    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Ryan,

      I already have very verbose tracing in a separate file of Ninja and I can see the orders being placed. I'm still looking for direction and an answer to my original questions.

      Since this particular instrument must have the TIF=DAY, then what do I do with my Stop Orders that are NOT being submitted and treated as GTC? The one example was that I was long at 5PM at night and by 9PM, those Stop Orders were canceled by Ninja in the strategy (because they were Day orders only). Now, I have a naked position. The trade then ended up losing huge because the stop never hit because it was cancelled.

      Besides coding around this, is there another option to keep the Stops as GTC? Or, if you could, please address questions 3-5.

      Thanks.

      Comment


        #4
        Originally posted by bobcat70 View Post
        3. I'm not sure what to do with the Stop that runs multi-day. Do I have to write code to put the Stop back on every night?
        4. Why can't I override the ENTERLONG with a timeinforce (DAY) option and leave the strategy TIF parameter set to GTC?
        5. Or, why doesn't the true flag actually send the ExitLongStop with a GTC flag when using the strategy TIF parameter set to DAY?
        Thanks
        John
        3) What environment are you trying to do this in? If backtesting set TIF to GTC. If live, you may have to work with the broker to see what type of position / order handling they do at end of session and then code appropriately.

        4) This is not the way it's designed. TIF is set per strategy, not order. Edit: See the suggestion later on for a way to dynamically set this for an individual order.

        5) The true flag you refer to does not change the TIF. Please see my previous post for an explanation on the differences between TIF and NT's internal order management.
        Last edited by NinjaTrader_RyanM1; 07-22-2011, 08:41 AM.
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          Ryan,

          I'm with CQG. The issue was that the ICE exchange does not accept GTC TIF on a Market Order. Although, you can do this with QM, YM, etc because they are on different exchanges.

          Since NT can't get around this issue, what have others done about this scenario? Again, the scenario being: The exchange requires the TIF to be 'Day' on a Market Order. The TIF can only be set per strategy as Day or GTC. If its Day, you cannot issue a GTC Stop Loss order. When the 'Day' ends, beyond putting the stop loss back on in code, is there another solution?

          Seems to me that NT should really address this situation and have a cleaner approach to solving this issue. I really don't like the idea of having to re-issue the stop position every night because NT can't issue a GTC because the Strategy overall is set to Day.

          Thanks.

          Comment


            #6
            Yes, good points. I'm currently checking into this with development and will update this thread tomorrow.
            Ryan M.NinjaTrader Customer Service

            Comment


              #7
              Originally posted by bobcat70 View Post
              Ryan,

              I'm with CQG. The issue was that the ICE exchange does not accept GTC TIF on a Market Order. Although, you can do this with QM, YM, etc because they are on different exchanges.

              Since NT can't get around this issue, what have others done about this scenario? Again, the scenario being: The exchange requires the TIF to be 'Day' on a Market Order. The TIF can only be set per strategy as Day or GTC. If its Day, you cannot issue a GTC Stop Loss order. When the 'Day' ends, beyond putting the stop loss back on in code, is there another solution?

              Seems to me that NT should really address this situation and have a cleaner approach to solving this issue. I really don't like the idea of having to re-issue the stop position every night because NT can't issue a GTC because the Strategy overall is set to Day.

              Thanks.
              What about on a StopLimit() order? Will they accept GTC on that?

              If so, you can always use a StopLimit() with the stop at your exit price, and the limit behind the price, effectively issuing a market order, as the limit order, once sprung, will be filled at "price or better".

              Comment


                #8
                Koganam:

                At times, the trade needs to execute as a Market Order. The issue is that the Market Order has to be a DAY order when trading DX. The only way to do that is to set the TIF on the strategy to DAY. Which then leaves the strategy unable to issue a GTC order because ALL orders will be DAY.

                Comment


                  #9
                  Originally posted by bobcat70 View Post
                  Koganam:

                  At times, the trade needs to execute as a Market Order. The issue is that the Market Order has to be a DAY order when trading DX. The only way to do that is to set the TIF on the strategy to DAY. Which then leaves the strategy unable to issue a GTC order because ALL orders will be DAY.
                  Well, the suggestion I made is to NOT use a Mar****rder directly, but to create an equivalent order using a StopLimit order, so that the question about TIF for Mar****rder becomes moot.

                  Comment


                    #10
                    You can toggle TimeInForce property for your market orders. Set the strategy as Gtc, but then use something like the following in the code blocks that place market orders.

                    if (mar****rderConditions)
                    {
                    TimeInForce = TimeInForce.Day;
                    EnterLong();
                    TimeInForce = TimeInForce.Gtc;
                    }
                    Last edited by NinjaTrader_RyanM1; 07-22-2011, 08:27 AM.
                    Ryan M.NinjaTrader Customer Service

                    Comment


                      #11
                      THANK YOU RYAN!!!! That will be a HUGE help.

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by rocketman7, Today, 02:12 AM
                      1 response
                      16 views
                      0 likes
                      Last Post NinjaTrader_ChelseaB  
                      Started by briansaul, Today, 05:31 AM
                      1 response
                      12 views
                      0 likes
                      Last Post NinjaTrader_Jesse  
                      Started by PaulMohn, Today, 03:49 AM
                      1 response
                      12 views
                      0 likes
                      Last Post NinjaTrader_BrandonH  
                      Started by frslvr, 04-11-2024, 07:26 AM
                      6 responses
                      106 views
                      1 like
                      Last Post NinjaTrader_BrandonH  
                      Started by trilliantrader, 04-18-2024, 08:16 AM
                      6 responses
                      26 views
                      0 likes
                      Last Post trilliantrader  
                      Working...
                      X