Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Ninjatrader cancelling limit orders

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

    Ninjatrader cancelling limit orders

    Hi

    I have a problem with Ninja trader ignoring the Take profit which are pre-entered as limit orders for a custom strategy. The function used are ExitLongLimit or ExitShortLimit Stop loss orders are created using ExitLongStop and ExitShortStop.

    All Exit functions are called with liveUntilCancelled parameter set to true.

    The strategy trades 3 lots and has 3 individual profit targets which are all limit orders.

    In most cases, when Target 1 (T1) limit is reached, it gets filled.

    However, the limit orders for Targets 2 and 3 get ignored and are never filled even when price reaches and exceeds well above (or below) the preset limit.

    Price trades right through the limit order levels and the limit order obviously doesn't get filled.

    Trades do eventually exit because the strategy does also have few other exit criterias (auxiliary exits) built into it. All this auxiliary exits are executed using at-market exit functions at which point, the strategy does cancel the unfilled and redundant Target and stop loss orders.

    This does not always result in trade loss. In case of one short order, the T3 limit price was set at 93.4 and trade was actually exited at 93.25. While the overall outcome is favorable, my concern is more to do with the function not behaving as expected. The problem is strictly confined to Exit...Limit failing to get filled as required.

    One interesting observation that is perhaps relevant is that this only happens on trades where the average price is more than 2 decimal places. Since the strategy is trading CL, if it gets a fill for the 3 lots at the same price, say 94.55, it works fine.

    But if it gets filled 2 lots at 94.55 and 1 lot at 94.56, the average price is 94.55333. These are the only trades that cause this problem.

    I don't know whether this has anything to do with it but I have taken over 50 trades and this pattern holds up so I suspect it may offer a clue.

    Every time the average price is 2 decimal places it works perfectly and every time it has more than 2 decimal places the limit orders are getting ignored.

    I would appreciate any help.

    Thanks
    Last edited by chadc; 04-10-2014, 02:48 AM.

    #2
    chadc, I would suggest to run with TraceOrders enabled as first step to understand exactly the reason for the ignored orders - http://www.ninjatrader.com/support/f...ead.php?t=3627

    This will give you more insight hopefully.

    Comment


      #3
      Originally posted by NinjaTrader_Bertrand View Post
      chadc, I would suggest to run with TraceOrders enabled as first step to understand exactly the reason for the ignored orders - http://www.ninjatrader.com/support/f...ead.php?t=3627

      This will give you more insight hopefully.
      Bertrand

      Added TraceOrder flag as suggested and ran a trade.

      In the most recent run, Strategy was unnecessarily and repeatedly calling ExitShortStop to move the stop loss which Ninja kept ignoring.

      JT: CB 63088.1 [13 Nov; 15:37:16]. MOVED Trailing Stop loss to 93.2798 from 93.2800. ATR using bar 63087[13 Nov; 15:37:16]. VALUE 93.2598; O: 93.1800; H: 93.1800; L: 93.1500; C: 93.1600
      13/11/2013 3:37:24 PM Entered internal PlaceOrder() method at 13/11/2013 3:37:24 PM: BarsInProgress=0 Action=BuyToCover OrderType=Stop Quantity=3 LimitPrice=0 StopPrice=93.29 SignalName='Stop Loss' FromEntrySignal='Shrt MRKT 63085'
      13/11/2013 3:37:24 PM Ignored PlaceOrder() method: Action=BuyToCover OrderType=Stop Quantity=3 LimitPrice=0 StopPrice=93.29 SignalName=Stop Loss' FromEntrySignal='Shrt MRKT 63085' Reason='There already is a matching order with same prices and quantity'


      This "placing-ignoring" nonsense happened about 31 times until Target 1's limit price was reached. At that point, according to the o/w sequence, just before T1 was filled, Ninja Trader cancelled off T2 limit, T3 limit and stop loss order

      13/11/2013 3:37:24 PM Cancelled pending exit order, since associated position is closed: Order='40550dcc079d415ab8cb43673c5f1631/Replay101' Name='Stop Loss' State=Accepted Instrument='CL 12-13' Action=BuyToCover Limit price=0 Stop price=93.29 Quantity=3 Strategy='JayTrader' Type=Stop Tif=Gtc Oco='' Filled=0 Fill price=0 Token='40550dcc079d415ab8cb43673c5f1631' Gtd='1/12/2099 12:00:00 AM'
      JT: CB 63088.1 [13 Nov; 15:37:16]. Unexpected Cancel order for Stop Loss. Qty 3 Stp 93.2900; O: 93.1800; H: 93.1800; L: 93.1500; C: 93.1600
      13/11/2013 3:37:24 PM Cancelled pending exit order, since associated position is closed: Order='0dac4464f69948a9bb2e1603f3a23344/Replay101' Name='Target 2' State=Working Instrument='CL 12-13' Action=BuyToCover Limit price=93.14 Stop price=0 Quantity=1 Strategy='JayTrader' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='0dac4464f69948a9bb2e1603f3a23344' Gtd='1/12/2099 12:00:00 AM'
      JT: CB 63088.1 [13 Nov; 15:37:16]. Unexpected Cancel order for Target 2. Qty 1 Lmt 93.1400; O: 93.1800; H: 93.1800; L: 93.1500; C: 93.1600
      13/11/2013 3:37:24 PM Cancelled pending exit order, since associated position is closed: Order='5d023860f213487d8e737bbb18297ed3/Replay101' Name='Target 3'State=Working Instrument='CL 12-13' Action=BuyToCover Limit price=93.13 Stop price=0 Quantity=1 Strategy='JayTrader' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='5d023860f213487d8e737bbb18297ed3' Gtd='1/12/2099 12:00:00 AM'
      JT: CB 63088.1 [13 Nov; 15:37:16]. Unexpected Cancel order for Target 3. Qty 1 Lmt 93.1300; O: 93.1800; H: 93.1800; L: 93.1500; C: 93.1600
      JT: CB 63088.1 [13 Nov; 15:37:16]. REACHED Target 1 for Shrt MRKT 63085!!. Exiting Qty 1 @ price 93.1500. FILLED @ 93.1500. SigBar 63083 ; O: 93.1800; H: 93.1800; L: 93.1500; C: 93.1600


      Because strategy does have a built in logic to recreate the stop loss with lowered quantity, for remaining legs, Stop loss order was recreated. T2 and T3 limit were reached but not executed since orders were already cancelled.

      Again "placing-ignoring" stop loss order nonsense reoccurred 300 times until the stop loss was actually moved and was hit. Strategy dutifully attempts to OCO cancel the pending order but its useless anyway.

      JT: CB 63104.1 [13 Nov; 16:48:01]. REACHED Stop Loss for Shrt MRKT 63085!!. Exiting Qty 2 @ price 93.1700. FILLED @ 93.1850. SigBar 63083 Last SL Change Break even; O: 93.1553; H: 93.1800; L: 93.1553; C: 93.1750
      JT: CB 63104.1 [13 Nov; 16:48:01]. OCO Cancelling Exit order for Target 2. Qty 1 Lmt 93.1400; O: 93.1553; H: 93.1800; L: 93.1553; C: 93.1750
      JT: CB 63104.1 [13 Nov; 16:48:01]. OCO Cancelling Exit order for Target 3. Qty 1 Lmt 93.1300; O: 93.1553; H: 93.1800; L: 93.1553; C: 93.1750


      I've already fixed the code that was causing unnecessary calls to ExitShortStop (and ExitLongStop) but still have no clue as to how Ninja decided that position was closed when it had no reason.
      Last edited by chadc; 04-11-2014, 01:42 AM.

      Comment


        #4
        chadc, I would only expect this to happen if you not scaled into the postition in managed mode that you're now trying to scale out of. So you would have for example 3 one contract entries and then could scale out as you link each exit uniquely to the entry names.

        Comment


          #5
          Originally posted by NinjaTrader_Bertrand View Post
          chadc, I would only expect this to happen if you not scaled into the postition in managed mode that you're now trying to scale out of. So you would have for example 3 one contract entries and then could scale out as you link each exit uniquely to the entry names.

          http://www.ninjatrader.com/support/f...ead.php?t=3751
          Bertrand

          Thank you for the the link and these two properties mentioned there seem to be playing a role in this error.

          EntriesPerDirection
          EntryHandling

          As mentioned before, If an entire entry order is filled in one (single) attempt, strategy works fine. If there is partial order fill, this error emerges.

          As far as I've understood, I am neither using fully managed mode nor fully managed mode
          because I use functions Enter*/Exit* but at the same time I have left Unmanaged property set to its default "false".

          My understanding is that "managed mode" methods are SetProfit.. SetStop... methods, whereas "unmanaged mode" methods are SubmitOrder. and I do not use either.

          Should I increase the EntriesPerDirection to 3?

          Should I increment the EntriesPerDirection every time there is a partial fill and reset it back to 1 when trade closes?

          As of now, I enter quantity for all 3 limit targets together by a single call and this is what call to so EnterLong looks like

          Code:
          longOrderName = "Long MRKT " + CurrentBar.ToString();
          longEntryOrder1 = EnterLong(0,target1Quantity + target2Quantity + target3Quantity, longOrderName);
          All variables are class variables. When the entry order gets fully filled, Exit orders are entered as follows

          Code:
          longExitOrderTgt3 = ExitLongLimit(0, true, target3Quantity, longTarget3Price, "Target 3", longOrderName);
          longExitOrderTgt2 = ExitLongLimit(0, true, target2Quantity, longTarget2Price, "Target 2", longOrderName);
          longExitOrderTgt1 = ExitLongLimit(0, true, target1Quantity, longTarget1Price, "Target 1", longOrderName);
          longExitOrderSL   = ExitLongStop (0, true, longFilledQuantity, longStopLossPrice, "Stop Loss", longOrderName);
          longOrderName variable plays a role in linking the two and hence it is set only once at start.

          Comment


            #6
            chadc, you are definitely in managed mode here (overview over both modes / methods used - http://www.ninjatrader.com/support/h...er_methods.htm).

            With your one entry order and then later scaleout you will be running into issues in managed. You need to scale in first to be able to scale in later, so have 3 unique entries for example if you want to scale out with 3 individual targets later.

            Comment


              #7
              Originally posted by NinjaTrader_Bertrand View Post
              chadc, you are definitely in managed mode here (overview over both modes / methods used - http://www.ninjatrader.com/support/h...er_methods.htm).

              With your one entry order and then later scale-out you will be running into issues in managed. You need to scale in first to be able to scale in later, so have 3 unique entries for example if you want to scale out with 3 individual targets later.
              QUERY ONE
              Can I not just increase EntriesPerDirection or EntryHandling thing?

              QUERY TWO
              Assuming that answer to Qry 1 is in negative, I am just confirming what you are recommending.

              Instead of 1 Enter Statement and 4 exit statement, I need to have 3 Enter and 6 exit statements (once for each target) (3 Filled Entries, 3 for Targets and 3 for Stop Loss). Correct?

              Instead of 5, I'd be seeing 9 trades per entry in Order tab, right?

              I had opted to enter all at once in order to reduce the overall impact Entry-time Slippage and also to have list of orders shown on in order tab small.

              Besides this minor aesthetic issues, strategy also has a concept of cancelling entry order if it does not get filled within certain number of ticks, profit tracking and multiple auxillary exits. With the entry split into 3, all that will become awfully more complicated.
              Last edited by chadc; 04-11-2014, 10:14 AM.

              Comment


                #8
                chadc, adjusting EntriesPerDirection would not help the signal tracking aspects here in managed mode.

                You are correct in your understanding of the implications.

                If you want to work with one just one entry and not be impacted then by the deeper signal tracking in managed you would need to switch over to unmanaged mode.

                Comment


                  #9
                  unmanaged mode works

                  Originally posted by NinjaTrader_Bertrand View Post
                  chadc, adjusting EntriesPerDirection would not help the signal tracking aspects here in managed mode.

                  You are correct in your understanding of the implications.

                  If you want to work with one just one entry and not be impacted then by the deeper signal tracking in managed you would need to switch over to unmanaged mode.
                  Thanks Bertrand

                  I moved the strategy to un-managed mode and it worked. Replacing Enter/Exit methods to Submit order was fairly straight forward with 1-1- mapping except with one very critical difference being parameter "fromEntrySignal" which is absent in "Unmanaged" mode.

                  Just wishing to confirm that fromEntrySignal" is useful only in managed mode functions work and completely irrelevant in unmanaged mode.

                  One thing that did surprise me was that the SubmitOrder does not understand when quantity is zero and actually reports back that it traded at XYZ price quantity 0. Fortunately, I do keep track of the outstanding quantity so it was not hard to correct.

                  Sometime ago, I had seen in this forum a short-cut method to flatten everything that essentially invokes File->Flatten Everything.

                  Comment


                    #10
                    chadc, correct signal tracking in unmanaged is limited and signal names would be merely a means for your identification / labeling.

                    The undocumented / unsupported FlattenEverything call would be
                    Code:
                    NinjaTrader.Gui.SuperDom.SuperDom.FlattenEverything()

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by argusthome, Yesterday, 10:06 AM
                    0 responses
                    17 views
                    0 likes
                    Last Post argusthome  
                    Started by NabilKhattabi, 03-06-2026, 11:18 AM
                    0 responses
                    16 views
                    0 likes
                    Last Post NabilKhattabi  
                    Started by Deep42, 03-06-2026, 12:28 AM
                    0 responses
                    14 views
                    0 likes
                    Last Post Deep42
                    by Deep42
                     
                    Started by TheRealMorford, 03-05-2026, 06:15 PM
                    0 responses
                    9 views
                    0 likes
                    Last Post TheRealMorford  
                    Started by Mindset, 02-28-2026, 06:16 AM
                    0 responses
                    36 views
                    0 likes
                    Last Post Mindset
                    by Mindset
                     
                    Working...
                    X