Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy order with name "Close Position"

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

    Strategy order with name "Close Position"

    My NinjaScript strategy is placing correct Profit Target and Stop Loss orders when it is executing but I am getting another order named "Close Position" popping up. What is this order, why is it placed, how can I prevent it from being placed?

    Thanks.

    #2
    This order is internally generated when you have an open position and you cross to the other side.

    For example:

    You are long 1.
    Then your code calls EnterShort().
    It will generate an order tagged with Close Position to close the long and then enter the short position. The reverse is true from short to long.
    RayNinjaTrader Customer Service

    Comment


      #3
      OK. I can understand that. However, when my orginal position (say I was Long) hits my profit target, this Close Position order stays open along with my other order to go short (which is above my original long profit target).
      When does this order cancel?

      This order is screwing up my system. How can I prevent this or cancel this order from my strategy?

      Comment


        #4
        For clarification.

        You are long.
        You have SetProfitTarget() called and an order is working.
        What other orders are working? An entry and close order generated by an EnterShortLimit() ?

        Assuming the above is accurate, your target order is filled so you then become flat but both the Close and Enter short orders are still working?

        Thanks
        RayNinjaTrader Customer Service

        Comment


          #5
          My strategy manages its own profit target and stop loss. Sometimes I have BOTH a buy limit AND a sell limit working at the same time. Here is an example:

          1. Enter buy limit and/or sell limit orders if conditions exist for either or both
          2. Determine if I am long or short
          3. If long, place sell limit and sell stop limit orders
          (entry sell short limit order can still be valid along with the triggered sell to close and sell to stop orders).
          4. If short, do the same as #3 but for shorts.

          I am continuously adjusting the entry orders based on market conditions but I *can* be long and still have a short entry order working. I know where this level is and automatically adjust my targets/stops accordingly.

          So managing my own targets/stops causes this "Close Position" order to hang out there because Profit Target is never getting hit as it is never getting entered.

          Comment


            #6
            Thanks for the clarification.

            Right now, orders expire (cancel) at the close of a bar unless re-submitted.

            So for final clarification, when your target or stop is hit, the EnterShortLimit() is still working (which is what you want) but the associated close position order generated by the EnterShortLimit() is also still working but you want it cancelled as soon as the position goes flat.

            Assuming I understand this correctly, I will take a look to see what can be done.
            RayNinjaTrader Customer Service

            Comment


              #7
              I think that may be the issue. I think the "Close Position" order is being submitted upon my EnterLongLimit() order being filled but after my long position is closed, this order is being maintained because my EnterShortLimit() order is still working. The "Close Position" order should be tied to the long position since that is what generated that order. Once that position is closed, the "Close Position" order should be cancelled/closed as well.

              There should be an override for this as I see the need for it (for simple strategies) but I also see (and am experiencing) it as a nuisance.

              Comment


                #8
                This is what I am now doing in my strategy code for profit target and stop loss order handling after the prior discussions:
                ================================================== ====
                if (Position.MarketPosition == MarketPosition.Flat)
                { // Set default profit/stop loss
                myProfitTarget = Math.Max(Math.Abs(longTargetPrice - longEntryPrice), Math.Abs(shortEntryPrice - shortTargetPrice)) / TickSize;
                SetProfitTarget(CalculationMode.Ticks, myProfitTarget);
                myStopLoss = Math.Min(Math.Abs(longEntryPrice - longStopPrice), Math.Abs(shortStopPrice - shortEntryPrice)) / TickSize;
                SetStopLoss(CalculationMode.Ticks, myStopLoss);
                }

                if (Position.MarketPosition == MarketPosition.Long)
                {
                myProfitTarget = (longTargetPrice - longEntryPrice) / TickSize;
                SetProfitTarget(CalculationMode.Ticks, myProfitTarget);
                myStopLoss = (longEntryPrice - longStopPrice) / TickSize;
                SetStopLoss(CalculationMode.Ticks, myStopLoss);
                }

                if (Position.MarketPosition == MarketPosition.Short)
                {
                myProfitTarget = (shortEntryPrice - shortTargetPrice) / TickSize;
                SetProfitTarget(CalculationMode.Ticks, myProfitTarget);
                myStopLoss = (shortStopPrice - shortEntryPrice) / TickSize;
                SetStopLoss(CalculationMode.Ticks, myStopLoss);
                }
                ================================================== ====

                I am now using SetProfitTarget and SetStopLoss for managing orders instead of manually doing it. I am still getting the "Close Position" order remaining open once the OCO pair has closed for the position.

                I am not setting SetProfitTarget or SetStopLoss in the Initialize() method because I do not know what these levels will be at the time of initialization. It depends on the market and chart interval selected. Should I even be setting these to defaults when the position is flat?

                Remember, my strategy *can* be long and simultaneously have a limit order entered waiting to go short. I make sure that the ProfitTarget for the long is the same as or less than the short limit order. Therefore, the "Close Position" order is already duplicating the process of getting flat before reversing.

                Anything I should be doing differently?

                Would the "Close Position" order go away when the position flattened if I used the overloaded method for SetStopLoss to include the order name?
                Attached Files
                Last edited by ThePatientOne; 05-29-2007, 09:28 PM. Reason: Attached a graphic is order issue.

                Comment


                  #9
                  You should always call the SetStopLoss() and equivalent methods prior to the opening of any position. That is the requirement since at this time, these methods must be called prior to the opening of a position so that protective orders are submitted.

                  Regarding the "Close position" order. We are still thinking about what can be done here. There is no way to get around having this order cancelled on the close of a position at this time.

                  - With your current approach, even if the order was cancelled, you still run the risk of getting double filled if the market moved fast enough and filled both the short entry limit and close position order before NT could cancel it. If you get double filled, your strategy logic will be off and you will have bigger issues.

                  Other options -

                  - Wait until the target limit is filled before submitting the short entry limit
                  - Use short entry market
                  RayNinjaTrader Customer Service

                  Comment


                    #10
                    1) Waiting until the target is filled before entering the short limit order gives me a very poor position in the order depth at that price.

                    2) Entering a market order doesn't gaurantee me my price or better ... only possibly my price or worse.

                    You ARE correct in that this issue is causing me all sorts of other problems. Why do you even have to kick off this order? Can't you create some property or method in the strategy object that I can set to inhibit the generation of this order? There has *got* to be a way of getting this done.

                    When I run this strategy and keep cancelling this "Close Position" order when it is generated, my strategy runs without issue and works nicely.

                    Comment


                      #11
                      Have you guys had any progress with this issue? My strategy runs perfectly if I sit here and keep cancelling the "Close Position" order.

                      Can you give me a programatic way of performing this from my strategies?

                      Thanks.

                      Comment


                        #12
                        Nope, sorry not yet. We still are not sure how to 100% reliably resolve this issue. We still have it on our list.

                        Comment


                          #13
                          "Close Position" Order submitted along with Exit Order

                          I created a simple strategy using the Strategy Wizard that basically reverses position when criteria are met. So on historical backtesting it looks something like this:

                          Enter Long (Buy) 5 contracts

                          Exit Long (Sell) 5 contracts
                          Enter Short (SellShort) 5 contracts

                          The last 2 orders occur on the same condition at the same price.

                          On Live testing I get the following:

                          Enter Long (Buy) 5 contracts

                          Exit Long (Sell) 5 contracts
                          Close Position (Sell) 5 contracts
                          Enter Short (SellShort) 5 contracts

                          I get this extra order labelled "Close Position" that ends up doubling the size of my short position, so that I am short 10 contracts rather than 5 contracts. What is this extra order that is generated, and how do you get it to stop generating it. This would be very frightening if trading live.

                          Thank you for your help.

                          Comment


                            #14
                            NTWolfe, welcome to our forums - if you want to just reverse on signals triggered, just use the Enter() methods only (and no Exit()'s as in your snippet) as they would revese automatically for you.

                            Please also ensure you're properly synched up as you start the strategy for realtime trading then -

                            Comment


                              #15
                              Thank you

                              Thanks I thought it would be something simple to correct.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              649 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              370 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              109 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              574 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              576 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X