Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

ExitLongStopLimit confusion

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

    ExitLongStopLimit confusion

    I'm looking to set a price target (stop order) to exit a long position and I want to get filled with a limit order = stop order.

    I'm backtesting this on 1 minute bars and my fills have some slippage.
    Q1: Is this slippage an artifact of using 1 minute bar test data or for some other reason? Q2: If I run the strategy live on 1 minute bars should I expect to get filled at the limit order price or at the nearest 1 minute bar close?

    Here's an example of how I'm using ExitLongStopLimit:
    Given: a longLimitEntry = 1.0000 and PriceTarget_1 = 0.0050

    exitlong_1 = ExitLongStopLimit(0, true, quantity, ((longLimitEntry * (1 + PriceTarget_1))), longLimitEntry * (1 + PriceTarget_1), signalName, fromEntrySignal);

    #2
    I just realized that the ExitLongStopLimit isn't working at all. In taking a look at the Orders tab in the Strategy Analyzer, the Exits are appearing as Order Type = Market. Any suggestions?

    Comment


      #3
      Please double check then what condition is exactly triggered the exit you see, could this be coming from another set / exit also in place?
      BertrandNinjaTrader Customer Service

      Comment


        #4
        Bertrand,
        I threw too much at you at once. First, is the premise correct? Do you see any problem with what I'm trying to accomplish in the text immediately below or any problem with the code statement?

        I'm looking to set a price target (stop order) to exit a long position and I want to get filled with a limit order = stop order. Here's how I've coded it below. Is there any problem with this code statement?


        Here's an example of how I'm using ExitLongStopLimit:
        Given: a longLimitEntry = 1.0000 and PriceTarget_1 = 0.0050

        exitlong_1 = ExitLongStopLimit(0, true, quantity, ((longLimitEntry * (1 + PriceTarget_1))), longLimitEntry * (1 + PriceTarget_1), signalName, fromEntrySignal);

        Comment


          #5
          Hi bluelou,

          From what I can tell this order would be rejected.

          ExitLongStopLimit() will submit a sell stop limit order. This order is rejected if you try to place above the last traded price.

          What is the TraceOrders output you get when submitting this order?
          Ryan M.NinjaTrader Customer Service

          Comment


            #6
            Ryan,
            TraceOrders didn't reveal anything except the PnL stats I already had going to the Output Window. Before we get into the intricacies of ExitStopLimits please tell me what kind of trade you would suggest?

            To clarify, here's what I'm trying to accomplish:
            1) Enter long position using EnterLongLimit and managed with liveUntilCancelled //This code works properly.

            2) Exit long position with the objective of getting a near exact fill based on a price target in decimals. I.e., PriceTarget_1 = 0.0050 is the same as 0.50% or 50 basis points from my entry price.

            For the price target exits I had been using ExitLong() but the slippage during thin or fast markets was too great. So, I'm trying to get more control over the exit using some form of limit order and I don't want the limit order to expire after just 1 bar. In effect, I want to exit my long at a limit price or higher. What type of order would you suggest?

            Thx,
            Lou

            Comment


              #7
              Hi Lou,

              It sounds like you want ExitLongLimit(). This would place a sell limit order, typically placed above the entry price, and allows you to specify the worst fill price you're willing to receive.
              Ryan M.NinjaTrader Customer Service

              Comment


                #8
                Ryan,
                My issue with using ExitLongLimit was how to incorporate liveUntilCancelled. I think I interpreted liveUntilCancelled incorrectly here.

                For instance, following the example below taken from the Help file. If I used liveUntilCancelled here would I be using a bar counter where bar_counter = 0 when CrossBelow = true? And, then I could set a constraint of max_bars that would result in a CancelOrder(), right?

                // Exits position
                if (CrossBelow(SMA(10), SMA(20), 1))
                ExitLongLimit(GetCurrentBid());

                Comment


                  #9
                  liveUntilCancelled can be used the same way for both these order types. Both have an overload that allows you to specify liveUntilCancelled = true.

                  For ExitLongLimit, it's the following:
                  ExitLongLimit(int barsInProgressIndex, bool liveUntilCancelled, int quantity, double limitPrice, string signalName, string fromEntrySignal)

                  Whatever cancellation technique you use is the same for both order types as well. It sounds like you're wanting to capture CurrentBar and then compare this some bars later to Cancel. Since this order would typically be placed at the same time as your entry, a shortcut you should consider is just using the built in BarsSinceEntry()
                  Ryan M.NinjaTrader Customer Service

                  Comment


                    #10
                    Ryan, does this code look okay? I'm still not getting any limit exits. It just stays in the position til I get stopped out.

                    exitlong_1 = ExitLongLimit(0, true, quantity, ((longLimitEntry * (1 + PT1_up)) + 0.0000), signalName, fromEntrySignal);

                    Also, your suggestion to use BarsSinceEntry() wouldn't work in this case. I want to count the number of bars since the exit condition = true (not the entry condition) and then cancel the ExitLimit order if it's not filled within X bars. Does that make sense to you.

                    Comment


                      #11
                      .

                      Originally posted by bluelou View Post
                      Ryan, does this code look okay? I'm still not getting any limit exits. It just stays in the position til I get stopped out.

                      exitlong_1 = ExitLongLimit(0, true, quantity, ((longLimitEntry * (1 + PT1_up)) + 0.0000), signalName, fromEntrySignal);

                      Also, your suggestion to use BarsSinceEntry() wouldn't work in this case. I want to count the number of bars since the exit condition = true (not the entry condition) and then cancel the ExitLimit order if it's not filled within X bars. Does that make sense to you.
                      You should print to output window your formula to see if it is correct.


                      Also, I keep a pvt variable I set in my strategy to keep what happened on a bar.
                      So then you can do currentbar -exitbar.

                      on position update callback, you could probably set your exit bar there

                      Comment


                        #12
                        sledge,
                        I'm already doing most of what you've mentioned. I'm posting here just to make sure I'm not misusing any of the methods and to get a better idea of how they work. But, thx for the suggestions.

                        Comment


                          #13
                          The market has to trade at your limit price or higher before it will be filled. Check the price of your order by looking at orders tab of control center, printing your variable, or looking at the TraceOrders output for it.
                          Ryan M.NinjaTrader Customer Service

                          Comment


                            #14
                            Ryan, of course. The prices are way over the limit order. For instance, the MFE on some of the long trades is >900 bps and I'm only looking for 60 bps. That can only mean that the limit order is being ignored for some reason. Also, there's nothing in the Output Log except my open trade equity; i.e., no error messages.

                            Again, I'm just trying to make sure I'm not misinterpreting the method itself. So, Going back to my question...
                            does this code look okay? I'm still not getting any limit exits. It just stays in the position til I get stopped out.

                            exitlong_1 = ExitLongLimit(0, true, quantity, ((longLimitEntry * (1 + PT1_up)) + 0.0000), signalName, fromEntrySignal);

                            Also, your suggestion to use BarsSinceEntry() wouldn't work in this case. I want to count the number of bars since the exit condition = true (not the entry condition) and then cancel the ExitLimit order if it's not filled within X bars. Does that make sense to you.

                            Comment


                              #15
                              Code looks fine. Is the issue with order submission or with the order being filled? Are you using this in a real time or backtest / historically?
                              Ryan M.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Fran888, 02-16-2024, 10:48 AM
                              3 responses
                              43 views
                              0 likes
                              Last Post Sam2515
                              by Sam2515
                               
                              Started by martin70, 03-24-2023, 04:58 AM
                              15 responses
                              114 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Started by The_Sec, Today, 02:29 PM
                              1 response
                              7 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Started by jeronymite, 04-12-2024, 04:26 PM
                              2 responses
                              31 views
                              0 likes
                              Last Post NinjaTrader_BrandonH  
                              Started by Mindset, 05-06-2023, 09:03 PM
                              10 responses
                              265 views
                              0 likes
                              Last Post NinjaTrader_BrandonH  
                              Working...
                              X