Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to Reverse & keep separate order names?

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

    How to Reverse & keep separate order names?

    I need to be able to reverse; e.g., by entering a short order at the same price as my long stop. This is a sample of the short entry logic
    Code:
    // ============  GO SHORT ===============================
                    if (Position.MarketPosition != MarketPosition.Short)
                    {        
                        if (FirstTickOfBar && CrossDN) //entryOrderS == null && 
                        {    
                            if (entryOrderL != null) CancelOrder(entryOrderL);   // cancel any unfilled Long orders
                            shortEntry = Close[i] - entryBuffer;
                            if (Position.MarketPosition == MarketPosition.Long)  //  if currently Long, pull Long Stop up to Short entry 
                            {    
                                // in case we don't hit the limit, Trade Mgmt will go back to old stop if PL flips before exit...
                                if (isNewStop( ref stopLong, shortEntry, true)) stopLong = 0; 
                            }
                            stopShort = 0;  // Set short stops
                            isNewStop( ref stopShort, shortEntry+maxStopLoss*TickSize, false);  
                            entryOrderS = EnterShortStopLimit(0, true, DefaultQuantity, shortEntry, shortEntry, nameShort);
    Unfortunately, it does not reverse (it does exit the Long correctly).
    The names used are different: "Long " & "Short " respectively so there should be no conflict.

    I searched the help for "internal order handling" per the log message but got no hits.

    #2
    Hello Lost Trader,

    Below are the internal order handling rules, seen at the bottom of this page. http://www.ninjatrader-support.com/H...verview36.html

    By default entries will reverse a position. Your EnterShortStop statement should submit the needed exit order as well as the short entry order. These will be two distinct orders.
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      I need additional explanation of these bullets from that link, please.
      The following rules are true per unique signal name excluding market orders:

      Methods that generate orders (excluding market orders) to enter a position will be ignored if:
      • A position is open and an order submitted by an exit method (ExitLongLimit() for example) is active and the order is used to open a position in the opposite direction
      • A position is open and an order submitted by a set method (SetStopLoss() for example) is active and the order is used to open a position in the opposite direction

      Does this mean, if the two orders in opposite directions have the SAME unique signal name (both either "Long " or "Short ") the order will be ignored?
      Or if the names are different, the opposite entry will be ignored? because the latter appears to be what is happening...

      By default entries will reverse a position.
      So the code should NOT "Pull the Long Stop up to the Short Entry" ?

      P.S.
      "Interal Order Handling Rules that Reduce Unwanted Positions"
      Internal is misspelled in that link -- that explains why my search got no hits..
      Last edited by Lost Trader; 08-04-2010, 07:46 AM.

      Comment


        #4
        No, the signal name isn't important here. It's the opposing direction part. NinjaTrader won't submit both orders if they are used to send orders on both sides of the market. The first order submitted is accepted and the next is ignored.

        We introduced an unmanaged order system in version 7 which allows you to place orders that are not governed by these internal rules.


        So the code should NOT "Pull the Long Stop up to the Short Entry" ?
        Sorry, not following here. If you are after a reversal behavior, the entry statements can do this without having to specify an exit and subsequent entry. The entry order takes care of the closing and opening side of things. Let us know if you're looking for additional clarification.

        Thanks for letting us know about the typo. I will notify our education department.
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          I definitely require more clarification, please. I would rather not move to NT7 to make this work just yet.
          The first order submitted is accepted and the next is ignored.
          Well, the order submitted by me was accepted and filled (.i.e., Long). That order has a stop loss & profit target submitted by the strategy, also accepted. So are you saying because those are accepted, NO short entry order can be submitted successfully?

          Are you saying that because every position has a SetStopLoss(), that I cannot submit the opposite entry? That seems to contradict this statement:
          If you are after a reversal behavior, the entry statements can do this without having to specify an exit and subsequent entry. The entry order takes care of the closing and opening side of things.
          I am not ALWAYS after a reversal strategy -- only if a short setup appears while the long position has not hit either stop or profit targets.

          Comment


            #6
            Hi LostTrader,

            Yes, you should definitely get a good understanding of internal order handling rules before moving to an unmanaged system in version 7. I didn't meant to suggest that it offers a solution here- only that it's available if you find that these rules are limiting what you'd like to accomplish.

            You'll have to use TraceOrders output for your orders to identify which order is ignored based on internal order handling rules.

            That order has a stop loss & profit target submitted by the strategy, also accepted. So are you saying because those are accepted, NO short entry order can be submitted successfully?
            Yes, that violates the rule below in bold. You can submit market orders, but not Stop or Limit.



            Methods that generate orders (excluding market orders) to enter a position will be ignored if:
            • A position is open and an order submitted by an exit method (ExitLongLimit() for example) is active and the order is used to open a position in the opposite direction
            • A position is open and an order submitted by a set method (SetStopLoss() for example) is active and the order is used to open a position in the opposite direction
            You have the flexibility to code a reversal or a standard exit. What you can't do (based on internal order handling rules) is have two separate statements in the same block that attempt to do this.

            This code block will ignore the EnterShort order:
            if (myReversalConditions)
            {
            ExitLong();
            EnterShort();
            }
            Last edited by NinjaTrader_RyanM1; 08-04-2010, 09:39 AM. Reason: identified the rule you were running into.
            Ryan M.NinjaTrader Customer Service

            Comment


              #7
              I know which order is being ignored. In the code posted below, it is the entryOrderS = EnterShortStopLimit which has the same limit price as the long SetStopLoss().

              So I take it that switching to ExitLongStop() and ExitShortStop() will have the same problem, correct?

              So,somehow, I have to wait for the position to close, then submit a market order? Ugly.
              I would prefer to submit a limit or stoplimit but price is can be above, below, or equal to my entry limit.

              Would changing EntryHandling from UniqueEntries to AllEntries alter this behavior, given different long & short names are used?

              Comment


                #8
                It may be beneficial for you to move away from the set statements.

                You could then run different statements depending on whether you're after a reversal or a regular exit.


                if (yourExitLogic)
                {
                ExitLongStop();
                ExitLongLimit();
                }

                if (yourReversalLogic)
                {
                EnterShortStop();
                EnterShortLimit();
                }

                If these two branches aren't mutually exclusive (there's possibility both evaluate true), then moving to an unmanaged system may be what you're looking for.

                No, changing entryHandling properties will not affect this.
                Last edited by NinjaTrader_RyanM1; 08-04-2010, 10:39 AM.
                Ryan M.NinjaTrader Customer Service

                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