Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Multiple instruments order getting canceled immediately

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

    Multiple instruments order getting canceled immediately

    hello,

    I have a strat that works with multiple instruments. If a limit is crossed i'll but spy's and if another limit is crossed I'll sell the ES. Profit targets and Stop losses are then set for each. What's happening is the Spy's enter and set their profit target and stop loss. On the next bar update the ES is triggered and set's it's profit target and stop loss, but then within the same bar the ES order is immediately canceled/Exited as are the stops. I'm attaching the output as well as the trade ledger. Any help would be much appreciated.

    6/15/2010 8:39:00 AM Entered internal PlaceOrder() method at 6/15/2010 8:39:00 AM: BarsInProgress=0 Action=Buy OrderType=Limit Quantity=1,000 LimitPrice=110.44 StopPrice=0 SignalName='Buy Breakout Bias 1' FromEntrySignal=''
    6/15/2010 8:39:00 AM Entered internal SetStopTarget() method: Type=Target FromEntrySignal='' Mode=Ticks Value=65.9999999999981 Currency=0 Simulated=False
    6/15/2010 8:39:00 AM Entered internal SetStopTarget() method: Type=Stop FromEntrySignal='' Mode=Ticks Value=44.9999999999987 Currency=0 Simulated=False
    Time 83900

    Date 20100615

    High 110.41

    Low 110.2


    Range 0.209999999999994

    Profit Target 65.9999999999981

    Stop Loss 44.9999999999987


    Profit Target2 21.9999999999994

    Stop Loss2 14.9999999999996

    Entry Point 110.41


    6/15/2010 8:40:00 AM Entered internal PlaceOrder() method at 6/15/2010 8:40:00 AM: BarsInProgress=1 Action=SellShort OrderType=Limit Quantity=2 LimitPrice=1098.00 StopPrice=0 SignalName='Sell Reversal Bias 1' FromEntrySignal=''
    6/15/2010 8:40:00 AM Entered internal SetStopTarget() method: Type=Target FromEntrySignal='Sell Reversal Bias 1' Mode=Ticks Value=21.9999999999994 Currency=0 Simulated=False
    6/15/2010 8:40:00 AM Entered internal SetStopTarget() method: Type=Stop FromEntrySignal='Sell Reversal Bias 1' Mode=Ticks Value=14.9999999999996 Currency=0 Simulated=False
    Time 84000

    Date 20100615

    High 110.41

    Low 110.2



    Range 0.209999999999994

    Profit Target 65.9999999999981

    Stop Loss 44.9999999999987


    Profit Target2 21.9999999999994

    Stop Loss2 14.9999999999996

    Entry Point 110.41


    6/15/2010 8:40:00 AM Cancelled pending exit order, since associated position is closed: Order='NT-00011/Backtest' Name='Profit target' State=Working Instrument='ES 06-10' Action=BuyToCover Limit price=1097.75 Stop price=0 Quantity=2 Strategy='MarketBiasBASE_Long_Short' Type=Limit Tif=Gtc Oco='NT-00005' Filled=0 Fill price=0 Token='b919262576464d62ae90d680d9cdcc02' Gtd='12/1/2099 12:00:00 AM'
    6/15/2010 8:40:00 AM Cancelled OCO paired order: BarsInProgress=1: Order='NT-00011/Backtest' Name='Profit target' State=Cancelled Instrument='ES 06-10' Action=BuyToCover Limit price=1097.75 Stop price=0 Quantity=2 Strategy='MarketBiasBASE_Long_Short' Type=Limit Tif=Gtc Oco='NT-00005' Filled=0 Fill price=0 Token='b919262576464d62ae90d680d9cdcc02' Gtd='12/1/2099 12:00:00 AM'



    Ledger for both trades: The spy trade shows it exited based on it's profit target but the ES was immediately exited stating a Stop loss" but we can see from the output the stop loss was 14.9 ticks. I have live until canceled set to true.
    3 ES 06-10 Backtest MarketBiasBASE_Long_Short Short 2 1098 1098.25 6/15/2010 8:41:00 AM 6/15/2010 8:41:00 AM Sell Reversal Bias 1 Stop loss 1

    4 SPY Backtest MarketBiasBASE_Long_Short Long 1000 110.44 111.1 6/15/2010 8:40:00 AM 6/15/2010 12:16:00 PM Buy Breakout Bias 1 Profit target 647.999999999997 1978.99999999999 12 230.000000000004 659.999999999997 12 217


    thanks

    #2
    Hello,

    Thank you for your forum post.

    What approach are you using are you using an unmanaged or managed entry appoach?

    If you are unsure I would need to see the line in your code that you are entering both of these orders in the market.

    I look forward to assisting you further.
    BrettNinjaTrader Product Management

    Comment


      #3
      Managed. But i during my trouble shooting I've tried unmanaged to no avail.

      Here's the code. I cleaned it up a little so it wouldn't be so lengthy.

      protected override void Initialize()
      {
      Add("ES 06-10", PeriodType.Minute ,1);

      TraceOrders = true;
      CalculateOnBarClose = true;
      }
      /// <summary>
      /// Called on each bar update event (incoming tick)
      /// </summary>
      protected override void OnBarUpdate()
      {

      if (BarsInProgress != 0)
      return;
      {
      if ( ToTime(Time[0]) > rangeStart && ToTime(Time[0]) <= rangeEnd)
      {

      profitTarget1 = Some Formula;
      stopLoss1 = Some Formula;
      profitTarget2 = Some Formula;
      stopLoss2 = Some Formula ;

      }
      }

      if(CrossAbove(Close, top, 1) && buyBreakoutBias1 == null)
      {
      buyBreakoutBias1 = EnterLongLimit(0, true,ent1,(top+ n ), "Buy Breakout Bias 1");
      SetProfitTarget(CalculationMode.Ticks, profitTarget1);
      SetStopLoss(CalculationMode.Ticks, stopLoss1);

      }

      if(CrossBelow(Close, entrypointtop, 1) && sellReversalBias1 == null)
      {
      sellReversalBias1 = EnterShortLimit(1,true, ent2, Closes[1][0], "Sell Reversal Bias 1");
      SetProfitTarget("Sell Reversal Bias 1", CalculationMode.Ticks, profitTarget2);
      SetStopLoss("Sell Reversal Bias 1",CalculationMode.Ticks, stopLoss2 , false);
      }

      if(ToTime(Time[0]) == exitTrade)
      {
      ExitShort("","");
      ExitLong("","");
      ExitShort(1,ent2, "", "");
      ExitLong(1,ent2, "", "");
      bottom= 0;
      top= 0;
      range = 0;
      profitTarget1 = 0;
      profitTarget2 = 0;
      stopLoss1 = 0;
      stopLoss2 = 0;

      }

      Comment


        #4
        Hello,

        Here is the issue I believe at first glance:

        if(CrossAbove(Close, top, 1) && buyBreakoutBias1 == null)
        {
        buyBreakoutBias1 = EnterLongLimit(0, true,ent1,(top+ n ), "Buy Breakout Bias 1");

        Once buyBreakoutBias1 because !null then this stops executing. Which is what you want for an unmanaged approach but not for managed.

        You have to continually call EnterLongLimit until your filled as when you stop calling it the order is cancelled. Please see here:



        Specifically this: By default, orders submitted via Entry() and Exit() methods automatically cancel at the end of a bar if not re-submitted
        BrettNinjaTrader Product Management

        Comment


          #5
          Ahhh okay. That fixes another problem that i didn't realize i had until now but not this specific problem. The problem is not that the ES entry "sellReversalBias1" is getting canceled before it has a chance to fill it's just the opposite. The ES entry is getting filled it's just exiting immediately instead of waiting for the stop loss or profit target. By eliminating the null check It's now resubmitting every time that condition is met.

          Comment


            #6
            Hello,

            Awesome. Glad your on the right track now.

            Let me know if I can be of further assistance.
            BrettNinjaTrader Product Management

            Comment


              #7
              i still have my original problem of the ES exiting in the same bar it enters. Any other suggestions for that?

              Comment


                #8
                Hello,

                How is it exiting, Can you find this section in the output window with TraceOrders=True enabled where the entry is closed out.

                I would suggest also adding Print() lines to all your exit logic to make sure its executing as you expect.
                BrettNinjaTrader Product Management

                Comment


                  #9
                  i have trace orders= true that's where the output from ealier came from. You'll notice in the output i submitted in post #1 that it does not specify exiting the order. It states that the strat is canceling pending order since associated position is closed. See the order below. It Enters at 1098 then sets a profit target then a stop loss and then cancels those stops because the position was closed.

                  6/15/2010 8:40:00 AM Entered internal PlaceOrder() method at 6/15/2010 8:40:00 AM: BarsInProgress=1 Action=SellShort OrderType=Limit Quantity=2 LimitPrice=1098.00 StopPrice=0 SignalName='Sell Reversal Bias 1' FromEntrySignal=''

                  6/15/2010 8:40:00 AM Entered internal SetStopTarget() method: Type=Target FromEntrySignal='Sell Reversal Bias 1' Mode=Ticks Value=21.9999999999994 Currency=0 Simulated=False

                  6/15/2010 8:40:00 AM Entered internal SetStopTarget() method: Type=Stop FromEntrySignal='Sell Reversal Bias 1' Mode=Ticks Value=14.9999999999996 Currency=0 Simulated=False

                  6/15/2010 8:40:00 AM Cancelled pending exit order, since associated position is closed: Order='NT-00017/Backtest' Name='Profit target' State=Working Instrument='ES 06-10' Action=BuyToCover Limit price=1097.75 Stop price=0 Quantity=2 Strategy='MarketBiasBASE_Long_Short' Type=Limit Tif=Gtc Oco='NT-00009' Filled=0 Fill price=0 Token='47082fb4d12745c5845f4809c3956263' Gtd='12/1/2099 12:00:00 AM'

                  6/15/2010 8:40:00 AM Cancelled OCO paired order: BarsInProgress=1: Order='NT-00017/Backtest' Name='Profit target' State=Cancelled Instrument='ES 06-10' Action=BuyToCover Limit price=1097.75 Stop price=0 Quantity=2 Strategy='MarketBiasBASE_Long_Short' Type=Limit Tif=Gtc Oco='NT-00009' Filled=0 Fill price=0 Token='47082fb4d12745c5845f4809c3956263' Gtd='12/1/2099 12:00:00 AM'

                  Comment


                    #10
                    Hello wahooj,

                    Beyond the stops and targets, the only exit condition I can see on ES is:
                    ExitShort(1,ent2, "", "");

                    Is this what's causing the exit or something else? You should be able to look at the report for one of the ES trades and identify a signal name for the exit condition. Hopefully that will provide some clues.

                    After running the report, click Trades tab and then look at Exit Name for one of the trades.
                    Ryan M.NinjaTrader Customer Service

                    Comment


                      #11
                      Sry, my first post must have been a little confusing. I posted the data from the trade report there, but called it the Ledger.

                      It's assigning the exit name as Stop loss. I'm not sure why though because we can see from the output that a stop loss of 14.9 ticks was set after the order was executed as was a Profit Target of 21.99 ticks.
                      Something is changes those stops to only 5 ticks away because you'll notice the "Cancel pending exit order" is canceling the Profit Target at a price of 1097.75 which is not 21.99 ticks away. Here's the trade report again.

                      3 ES 06-10 Backtest MarketBiasBASE_Long_Short Short 2 1098 1098.25 6/15/2010 8:41:00 AM 6/15/2010 8:41:00 AM Sell Reversal Bias 1 Stop loss -25 1331 0 25 0 0 1

                      Comment


                        #12
                        I see. It may help to print out the order details for the stop loss. The value of the variable is 14.999 but the following block may help you identify the actual value submitted with the order.

                        protectedoverridevoid OnOrderUpdate(IOrder order)
                        {
                        if (order.Name == "Stop loss")
                        Print(order.ToString());
                        }
                        Ryan M.NinjaTrader Customer Service

                        Comment


                          #13
                          ah okay, i didn't know i could print order details like that. I'll try and post .

                          Comment


                            #14
                            Well, it doesn't give a value of ticks but it confirms the price of 1098.25 which would be a value of 5 ticks. Not sure why it's not using the value of the variable. I'll keep playing around with it and let you know.
                            Thanks.

                            Order='NT-00010/Backtest' Name='Stop loss' State=PendingSubmit Instrument='ES 06-10' Action=BuyToCover Limit price=0 Stop price=1098.25 Quantity=2 Strategy='MarketBiasBASE_Long_Short' Type=Stop Tif=Gtc Oco='NT-00005' Filled=0 Fill price=0 Token='b21815e9ab1e4377b23606cdb076b498' Gtd='12/1/2099 12:00:00 AM'
                            Order='NT-00010/Backtest' Name='Stop loss' State=Accepted Instrument='ES 06-10' Action=BuyToCover Limit price=0 Stop price=1098.25 Quantity=2 Strategy='MarketBiasBASE_Long_Short' Type=Stop Tif=Gtc Oco='NT-00005' Filled=0 Fill price=0 Token='b21815e9ab1e4377b23606cdb076b498' Gtd='12/1/2099 12:00:00 AM'
                            Order='NT-00010/Backtest' Name='Stop loss' State=Working Instrument='ES 06-10' Action=BuyToCover Limit price=0 Stop price=1098.25 Quantity=2 Strategy='MarketBiasBASE_Long_Short' Type=Stop Tif=Gtc Oco='NT-00005' Filled=0 Fill price=0 Token='b21815e9ab1e4377b23606cdb076b498' Gtd='12/1/2099 12:00:00 AM'

                            Comment


                              #15
                              wahooj, good to hear you're getting closer. Please keep playing around with it and let us know if you need specific assistance. As always, it is a great idea to print out everything that could be related to the issue at hand.

                              Brett's order update code is a nice start, but you can also print out the status of every single order update, like this:
                              Code:
                              protected override void OnOrderUpdate(IOrder order)
                              {
                                  Print(order.ToString());
                              }
                              AustinNinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

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