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 NullPointStrategies, Yesterday, 05:17 AM
            0 responses
            62 views
            0 likes
            Last Post NullPointStrategies  
            Started by argusthome, 03-08-2026, 10:06 AM
            0 responses
            134 views
            0 likes
            Last Post argusthome  
            Started by NabilKhattabi, 03-06-2026, 11:18 AM
            0 responses
            75 views
            0 likes
            Last Post NabilKhattabi  
            Started by Deep42, 03-06-2026, 12:28 AM
            0 responses
            45 views
            0 likes
            Last Post Deep42
            by Deep42
             
            Started by TheRealMorford, 03-05-2026, 06:15 PM
            0 responses
            50 views
            0 likes
            Last Post TheRealMorford  
            Working...
            X