Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to close/cancel all positions & orders?

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

    How to close/cancel all positions & orders?

    Hello,

    At the beginning and end of my session I would like to close out any lingering positions and orders.

    To exit a position:
    1. I have found MarketPosition which tells me whether the position is long or short
    2. I can use ExitLong() or ExitShort() accordingly (and no I'm not using SetProfitTarget or SetStopLoss)

    For orders it's murkier, there is no method to get all active orders.
    How would I go about canceling all active orders?

    I see Account.CancelAllOrders() is that accessible from the Strategy class/namespace?

    Many Thanks, Caesar.

    #2
    Hello Caesar,

    Thanks for your post.

    <Account>.CancelAllOrders() could be used to cancel all orders on an instrument. This method can be used in a NinjaScript strategy.

    See this help guide page for more information about accessing the Account class and sample code: https://ninjatrader.com/support/help...ount_class.htm

    See this help guide page about <Account>.CancelAllOrders() and sample code: https://ninjatrader.com/support/help...lallorders.htm

    Another way to cancel all orders from the strategy is you can loop through the orders in the account and cancel them with CancelOrder().

    See this forum thread for more information about looping through orders on the account and canceling them with CancelOrder(): https://ninjatrader.com/support/foru...17#post1130617

    Please let me know if I may further assist.
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment


      #3
      Hello Brandon,

      CAncelAllOrders require an Instrument parameter be passed, where do I get Instrument from?

      Many Thanks, Caesar.

      Comment


        #4
        Hello Skechers,

        Thanks for your note.

        You could pass in Instrument for the CancelAllOrders(Instrument instrument) argument.

        For example, <Account>.CancelAllOrders(Instrument).

        Instrument: https://ninjatrader.com/support/help...instrument.htm

        Let me know if I may further assist.
        <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

        Comment


          #5
          Many Thanks!

          Comment


            #6
            Originally posted by Skechers View Post
            Hello Brandon,

            CAncelAllOrders require an Instrument parameter be passed, where do I get Instrument from?

            Many Thanks, Caesar.
            You could use Bars.Instrument to dynamically detect the instrument whose bars are being rendered on the chart. I tried that recently and works for me by using <Account>.CancelAllOrders(Bars.Instrument);

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Mindset, 04-21-2026, 06:46 AM
            0 responses
            88 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by M4ndoo, 04-20-2026, 05:21 PM
            0 responses
            134 views
            0 likes
            Last Post M4ndoo
            by M4ndoo
             
            Started by M4ndoo, 04-19-2026, 05:54 PM
            0 responses
            68 views
            0 likes
            Last Post M4ndoo
            by M4ndoo
             
            Started by cmoran13, 04-16-2026, 01:02 PM
            0 responses
            119 views
            0 likes
            Last Post cmoran13  
            Started by PaulMohn, 04-10-2026, 11:11 AM
            0 responses
            67 views
            0 likes
            Last Post PaulMohn  
            Working...
            X