Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Stop Loss & Managed Exit fire together

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

    Stop Loss & Managed Exit fire together

    My strategy uses Stop Losses and Managed Exits. Today I had both orders fill on the same position. Here is what happened and the order in which it happened:

    Managed exit (buy to cover) submitted.
    Stop Loss filled.
    Managed exit Filled.

    I started out short two contacts, and ended up long two contracts. It turns out that my stop loss was set one tick away from where my managed exit order filled.

    I know that exiting the position will cancel the stop loss order, but there is a chance (as in this example) where I have two orders at the exchange at the same time. Should I cancel the stop order and get confirmation before submitting the exit order? If so, how do you cancel a Stop Loss order? Is there a better way to do this?

    Thanks,

    -Scott

    #2
    Is this version 6.0.1000.X? I suspect it is. In 6.5, we have taken some steps to reduce situations where this can happen. We have done this by limiting the types of simultaneous exit orders that can be live in the market. The information on this is in the Orders section of the NinjaScript section of the 6.5 Help Guide.
    RayNinjaTrader Customer Service

    Comment


      #3
      Hi Ray,

      I am using Ver. 6.5.0.5. I am also using the Sim account using Zen-Fire.

      I don't see an Orders Section under the NinjaScrip 6.5 Help Guide. Is that the exact section?

      I'm using the latest version. Could this be happening because I am running my strategy in sim mode? If not, I need to find a way around this - such as canceling the stop loss order.

      Thanks,

      -Scott

      Comment


        #4
        Can you be specific about the situation:

        IE

        Long 1
        SetStopLoss() working
        ExitLongStop() working

        etc...

        Thanks

        PS - Its under NinjaScript > NinjaScript Language Reference > Custom Strategies > Orders... I believe in the overview part at the bottom of the page.
        RayNinjaTrader Customer Service

        Comment


          #5
          Ray,

          I have attached a small piece of the log having to do with this transaction. There is probably more information than you need there, but I wanted to make sure you had ALL the data -again, I have only attached the part having to do with this order.

          A couple of things to note:

          The original order was for 2 contracts. I was partially filled, then completely filled.

          I adjusted the stop loss price once.

          I placed a Buy to Cover order to exit the position

          Both the Stop Loss and the Buy To Cover were filled.

          I started short 2 contracts and finished long 2 contracts.

          Please let me know if you need any other information...

          Thanks,

          -Scott

          Comment


            #6
            Forgot the attachment...

            If you want this in a different format, just ask. The forum is restricing xls and csv.

            Thanks,

            -Scott
            Attached Files
            Last edited by CashCache; 01-17-2008, 06:20 PM.

            Comment


              #7
              I need the specific method calls you used as per my post. That would really be helpful.
              RayNinjaTrader Customer Service

              Comment


                #8
                Ray,

                Let me know if you need anything else.

                Code:
                // I set the initial Stop Loss like this
                [FONT=Courier New][SIZE=2]SetStopLoss("name", CalculationMode.Ticks, 10[/SIZE][/FONT][FONT=Courier New][SIZE=2], [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]false[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]);[/SIZE][/FONT]
                 
                [FONT=Courier New][SIZE=2]// Enter the order[/SIZE][/FONT]
                [FONT=Courier New][SIZE=2]EnterShortLimit([/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2], [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]true[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2], orderQty, Bars[[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]], "Test1");[/SIZE][/FONT]
                 
                [FONT=Courier New]//Once a price target is hit, I adjust the stop to BE+1[/FONT]
                [FONT=Courier New][SIZE=2]SetStopLoss("name", CalculationMode.Ticks, -[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2], [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]false[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]);[/SIZE][/FONT]
                 
                [FONT=Courier New][SIZE=2]//Once one of my exit creteria is met, I exit the position[/SIZE][/FONT]
                [FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]ExitShort("Message[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000]"[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2], "Test1");[/SIZE][/FONT]
                [/SIZE][/FONT]



                Comment


                  #9
                  Thanks for this information, this is helpful.

                  - This is unfortunately a situation that can occur
                  - There are many approached from limiting this
                  - You can't cancel a SetStopLoss() order programatically

                  You can use the OnOrderUpdate() method and on confirmation of your entry order, submit a stop via ExitLongStop() and set the parameter liveUntilCancelled to true. Once your condition for exiting via ExitLong() is triggered, cancel the ExitLongStop() via CancelOrder(), wait for cancel confirmation on this order in OnOrderUpate() and once confirmed cancelled, issue the ExitLong(). This is advanced programming. Review the Help Guide on this and see the reference sample below.

                  Alternatively, you could just use ExitLongStop() in the OnBarUpdate() method but the problem there is that this will only trigger once the position is open. If you are using 5 minute bars for example, the stop would not be active until the next 5 minute bar if you run with CalculateOnBarClose. In this case, you could either run with it set to false for real-time so the stop order goes in on the first tick after the position is open or, add a lower time frame series such as a 10 second series and issue the ExitLongStop() in that context.

                  RayNinjaTrader Customer Service

                  Comment


                    #10
                    Sorry for Jumping in...
                    Ray , are you saying there's a problem/risk of accidental fills and we shouldn't modify stop losses as per http://www.ninjatrader-support.com/v...ead.php?t=3222 ?

                    Comment


                      #11
                      No, that's not what I am saying.

                      - CashCache has a stop order working via SetStopLoss()
                      - A condition in his strategy occurs causing him to exit early by calling ExitLong()
                      - His original stop loss was 1 tick away from inside market
                      ---> Risk of double fill is real high

                      I am just providing an alternate way to code a strategy to in affect remove the risk of getting double filled
                      RayNinjaTrader Customer Service

                      Comment


                        #12
                        Ray,

                        This makes sense to me. I am aleady using OnOrderUpdate() for most of my order processing. This should not be a big deal.

                        I'll report back my finding/issues.

                        Thanks again...

                        -Scott

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by Christopher_R, Today, 12:29 AM
                        0 responses
                        9 views
                        0 likes
                        Last Post Christopher_R  
                        Started by sidlercom80, 10-28-2023, 08:49 AM
                        166 responses
                        2,235 views
                        0 likes
                        Last Post sidlercom80  
                        Started by thread, Yesterday, 11:58 PM
                        0 responses
                        3 views
                        0 likes
                        Last Post thread
                        by thread
                         
                        Started by jclose, Yesterday, 09:37 PM
                        0 responses
                        8 views
                        0 likes
                        Last Post jclose
                        by jclose
                         
                        Started by WeyldFalcon, 08-07-2020, 06:13 AM
                        10 responses
                        1,415 views
                        0 likes
                        Last Post Traderontheroad  
                        Working...
                        X