Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 Perr0Grande, Today, 08:16 PM
                0 responses
                2 views
                0 likes
                Last Post Perr0Grande  
                Started by elderan, Today, 08:03 PM
                0 responses
                5 views
                0 likes
                Last Post elderan
                by elderan
                 
                Started by algospoke, Today, 06:40 PM
                0 responses
                10 views
                0 likes
                Last Post algospoke  
                Started by maybeimnotrader, Today, 05:46 PM
                0 responses
                12 views
                0 likes
                Last Post maybeimnotrader  
                Started by quantismo, Today, 05:13 PM
                0 responses
                7 views
                0 likes
                Last Post quantismo  
                Working...
                X