Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Manually close position open thru strategy

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

    Manually close position open thru strategy

    Hi, I am very new to Ninjatrader and need some help related to positions opened through a strategy developed using strategy builder.
    A new position will be taken using a strategy developed by strategy builder. If I close the position manually before the strategy closes the position, what must I do so that the strategy takes new position as soon as all the entry criteria is met? If the entry criteria meets at the end of next candle also, a new position should be taken.
    Can I get some help here. Thanks in advance.

    regards,
    Sid

    #2
    Welcome to the forums!

    First, 'manually close the position' -- how are you doing that?

    I would recommend this technique:
    From your strategy code, add a toolbar button that closes the position
    opened by the strategy. To close a strategy position manually, use this
    button (and only this button) as your manual close.

    Comment


      #3
      Thank you for replying to the post. To close the trade I actually take an opposite position manually. This makes the net position as zero for my account.
      As soon as I do this, I want the strategy to take a new position as soon as all the entry criteria is met.
      I am using strategy builder, dont know coding.

      Comment


        #4
        I agree with bltdavid, button is the best choice. Because if you try to change you position manually your strategy will be terminated. I don't know any other workaround.
        You can see button example here: https://ninjatraderecosystem.com/use...bar-buttons-2/
        It's not that hard to change code for your needs.

        Comment


          #5
          Originally posted by sprithiani View Post
          Thank you for replying to the post. To close the trade I actually take an opposite position manually. This makes the net position as zero for my account.
          As soon as I do this, I want the strategy to take a new position as soon as all the entry criteria is met.
          I am using strategy builder, dont know coding.
          That's rather clever, but it just gets you into trouble. You
          shouldn't combine that manual technique with an automated
          strategy. Let's discuss the reasons why.

          [Are you trading futures? I will assume you are.]

          That technique makes your strategy position out of sync
          with your account position
          . An automated strategy does
          not know or monitor the account position (except for when
          the strategy first starts. NT has features allowing your
          strategy to adopt an existing account position, but you
          have to explicitly invoke those features. But I digress.)

          Anyways, in NinjaTrader, your account position and your
          automated strategy's position are two different things. If
          you get them out of sync, which is actually not that hard
          to do, you are playing with fire.

          So, what's the problem?
          When you make your account position go flat via your clever
          'manual intervention' technique, your strategy doesn't know
          you did that
          .

          You've effectively "orphaned" your strategy position (NT calls
          it 'out of sync') but it gets worse -- when your strategy finally
          does close its position, let's say it was 'Long 3', well, your
          strategy will effectively submit a 'Sell 3 at Market' to close
          the 'Long 3' position. Are you still with me?

          Yeah, so, why is that a problem?
          Because, sure, the strategy's 'Sell 3 at Market' to close makes
          the strategy position go flat, but that 'Sell 3 at Market' order was
          also sent to the exchange
          (like all orders are), and now your
          account position has become 'Short 3'.

          Your clever manual 'Sell 3' technique you used to prematurely go
          flat has screwed up the automated strategy, and the result is a
          'Short 3' position in your account.

          Huh?
          Yep. When your strategy finally does its own 'Sell 3' to close
          the position (I know, I know, you're screaming for the strategy
          not to do that since you've done it manually with your clever
          technique), the strategy thinks it's now flat, but you've made
          the account position go from flat to 'Short 3' -- this is, almost
          without exception, not what you want.

          Remember what I said about about your manual intervention
          technique? Your strategy doesn't know about it.

          Bottom line is: don't do it that way unless you really really
          know what you're doing -- even then, don't do it, it is a bad
          habit, even if you make it work for you. I mean, you'll probably
          screw up your account eventually using that bad habit. The folks
          at NT don't want you to adopt this bad habit, but the product allows
          you do it if you really want to (as you have discovered). But, please.
          Do. Not. Do. That. Seriously, drop it. No more, skip it, avoid it, sink
          the idea, throw it away, forget about it, just say no.

          Final Summary:
          Combining manual order entry & exit techniques with an automated
          strategy is not supported (that well). It's gotten better in NT8 because
          the chart trader and an automated strategy can cooperate in a few
          limited ways, but many things (like your clever technique) are just
          bad habits and will most likely just get your account into trouble.

          Ok, let's full circle back to my suggestion:
          Having your strategy code add a toolbar button that performs
          the close is the safest way to maintain your sanity. Keeping
          the account position and strategy position in sync is the real
          reason the close toolbar button technique is so useful -- it's not
          just for convenience.

          Just my 2˘.

          Comment


            #6
            Hi David,

            Thanks for the detailed explanation. I understand the risk here. Thanks for being so concerned. Actually, I have a entry and exit build into the strategy. But I am still looking for a manual exit. I will try to "add a toolbar button that closes the position opened by the strategy". Any idea if there is a standard button available to download, where we can indicate the strategy to use with.

            Regards,
            Siddharth

            Comment


              #7
              Hello Siddharth,

              The information provided by our community members is indeed accurate involving a manual exit on an automated strategy will desync the account from the strategy.

              Leeroy_Jenkins linked an example that adds a button here. I would suggest trying to implement that button code in a separate (unlocked) strategy, and then once you confirm that is working, to implement in a main larger strategy.

              If you are a Strategy Builder user and not familiar with using the NinjaScript Editor our NinjaScript Editor 401 course may be helpful to get you acquainted.

              NinjaScript Editor 401 (publicly available recording) — https://www.youtube.com/watch?v=BA0W4ECyVdc

              Comment


                #8
                Hi NinjaTrader,

                When running an automated strategy on NT8 & need to manually exit or have trade desk of brokerage flatten open position(s) (sometimes I'm not sure which strategy has the open position since run many at same time & need to do this asap if notice anything amiss), what is the correct procedure to ensure NT is synced properly again?

                I normally, disable all strategies & disconnect data then re-connect all again. Is this all necessary and/or should NT be re-started also?

                Manual exits are done very seldom but need to know for when performed.

                Thanks very much in advance!

                Comment


                  #9
                  Hello Algotrade12,

                  You should not run multiple strategies or trade manually on the same account/instrument pair.

                  If anything else other than the strategy is trading on the same account/instrument pair, it will cause the account to desync with the strategy.

                  You may check the positions tab of the Control Center to see open positions, and you can right click on a position from there, right click, and select Close Position. This Close Position order will also disable the strategy (or strategies) on the account.

                  If you want to perform manual exits in the strategy, you could consider implementing buttons to have the orders submitted through the strategy (so the strategy stays in sync with the account.) An example that adds buttons to a strategy for order submissions can be found below.



                  The link above is publicly available.

                  The NinjaTrader Ecosystem website is for educational and informational purposes only and should not be considered a solicitation to buy or sell a futures contract or make any other type of investment decision. The add-ons listed on this website are not to be considered a recommendation and it is the reader's responsibility to evaluate any product, service, or company. NinjaTrader Ecosystem LLC is not responsible for the accuracy or content of any product, service or company linked to on this website.

                  Comment


                    #10
                    Originally posted by NinjaTrader_Jim View Post
                    Hello Algotrade12,

                    You should not run multiple strategies or trade manually on the same account/instrument pair.

                    If anything else other than the strategy is trading on the same account/instrument pair, it will cause the account to desync with the strategy.

                    You may check the positions tab of the Control Center to see open positions, and you can right click on a position from there, right click, and select Close Position. This Close Position order will also disable the strategy (or strategies) on the account.

                    If you want to perform manual exits in the strategy, you could consider implementing buttons to have the orders submitted through the strategy (so the strategy stays in sync with the account.) An example that adds buttons to a strategy for order submissions can be found below.



                    The link above is publicly available.

                    The NinjaTrader Ecosystem website is for educational and informational purposes only and should not be considered a solicitation to buy or sell a futures contract or make any other type of investment decision. The add-ons listed on this website are not to be considered a recommendation and it is the reader's responsibility to evaluate any product, service, or company. NinjaTrader Ecosystem LLC is not responsible for the accuracy or content of any product, service or company linked to on this website.
                    Thanks very much for the helpful information & instructions Jim!

                    I'm still not sure what the proper procedure is in case the account becomes 'desynced' with strategy(s) due to a manual close via chart trader or through my brokerage trading desk (this happens a few times a year despite trades every day) in order for the account to become in sync with strategy(s) again.

                    Your advice is much appreciated.

                    Comment


                      #11
                      Hello Algotrade12,

                      If you interrupt the strategy while it is trading (submitting a manual order, or running another strategy on the account/instrument, the strategy and account will desync.

                      To stay in sync, only that strategy can be running. As advised above, if you implement a button for manual submissions within the strategy, the manual orders would come from the strategy and it will remain in sync.

                      If you desync your account from your strategy, you could try right clicking in the Strategies tab and selecting Synchronize All Strategies. (I still recommend handling the manual orders from within the strategy so it does not fall out of sync when you want to manually close a position.)

                      Synchronize All Strategies - https://ninjatrader.com/support/help...eAllStrategies

                      Otherwise, you should disable the strategy and re-enable it with your desired Start Behavior. Wait Until Flat will have the strategy wait until the next entry order needs to be submitted before an order can be submitted live and ImmediatelySubmit would be used to resume an existing position (assuming the account and strategy position are where you want.)

                      If the strategy and account are out of sync at this stage you could consider enabling with ImmediatelySubmit Synchronize Account, and this will have NinjaTrader submit an order that synchronizes the strategy position to the account.

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by NullPointStrategies, Yesterday, 05:17 AM
                      0 responses
                      56 views
                      0 likes
                      Last Post NullPointStrategies  
                      Started by argusthome, 03-08-2026, 10:06 AM
                      0 responses
                      132 views
                      0 likes
                      Last Post argusthome  
                      Started by NabilKhattabi, 03-06-2026, 11:18 AM
                      0 responses
                      73 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
                      49 views
                      0 likes
                      Last Post TheRealMorford  
                      Working...
                      X