Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Cancelling all Orders

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

    Cancelling all Orders

    Is it possible to cacel all currently working orders in Ninjascript?

    If yes, what would be the code?

    Thanks!

    #2
    It is just a matter of using CancelOrder().
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      I tried this, but I cannot address some orders.

      To be exact the problem is the following:

      I enter an order with EnterLongLimit or EnterShortLimit. The strategy is always in the market, so it reverses. But I have some conditions that cancel the limit order. When the order is cancelled only the new entry is cancelled. The BuytoClose or SelltoCover order that is generated together with the reversal signal stays is working status and no new orders are generated for the strategy until the order that is still in the market is filled.

      I thought it would make sense to cancel all active orders for an instrument under certain conditions to solve this problem.

      Thanks!

      Comment


        #4
        I suspect you are using the SetStopLoss() and SetProfitTarget() and as such, the behaviour you experienced is expected.
        RayNinjaTrader Customer Service

        Comment


          #5
          No, I am using EnterLongLimit and EnterShortLimit to reverse positions.

          For example I am long.

          Now I have a condition to go short, for example Stochatics are above 80.

          So I use a conditional EnterShortLimit to do this, with a limit for example EMA of 3 periods + 1.

          If the Limit is filled while the condition is still true (Stoch > 80 for example) the position is successfully reversed.

          But if the Limit gets not filled before Stochastics fall below 80 the EnterShort Limit is correctly cancelled but the BuytoCover order is still working.

          I want that my strategy cancels both orders and waits with the original position until the condition is true again to enter the order again and try to get it filled this time.

          So is it somehow possible to cancel both orders that are generated by EnterShortLimit or EnterLongLimit?

          Thanks!

          Comment


            #6
            Can you provide a simple reference sample that demonstrates this and can it be replicated in a backtest?
            RayNinjaTrader Customer Service

            Comment


              #7
              protected override void OnBarUpdate()

              {


              if(UltimateOscillator(7, 14, 28)[0] > 65)
              {
              Sell = EnterShortLimit(1 , KeltnerChannel(0.5, 3).Upper[0], "Sell");
              }

              if(UltimateOscillator(7, 14, 28)[0] < 35)
              {
              Buy = EnterLongLimit(1, KeltnerChannel(0.5, 3).Lower[0], "Buy");
              }

              if(Position.GetProfitLoss(Close[0], PerformanceUnit.Currency) <= - 1000)
              {
              ExitLong("", "");
              ExitShort("", "");
              }
              }

              Essentially thats the order generating code.

              It does not really work in backtest, but you can see the error with market replay.
              If the ultimate oscillator condition is not ture anymore, the entry part of the Limit Order is cancelled but not the close part.

              Comment


                #8
                I suggest debugging your strategy by setting TraceOrders=true (see docs for details) and per here: http://www.ninjatrader-support.com/v...ead.php?t=3418

                Comment

                Latest Posts

                Collapse

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