Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Clarification on Closing ATM Strategies Programmatically

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

    Clarification on Closing ATM Strategies Programmatically

    ​Dear NinjaTrader Support Team,

    I hope this message finds you well. I am currently developing an add-on for NinjaTrader and am encountering challenges when attempting to close an ATM strategy programmatically.

    Specifically, I have the following questions and issues:
    1. Closing an ATM Strategy Using AtmStrategyClose:
      • I found the AtmStrategyClose method in the NinjaTrader documentation, which appears to be the correct method for closing an ATM strategy.
      • However, I am unclear about:
        • On what object this method should be called.
        • How to obtain the required strategyId parameter referenced in the documentation. Could you provide guidance on how to retrieve the strategyId for an ATM strategy that was started programmatically using StartAtmStrategy?
    2. Using Flatten on the Account:
      • I attempted to flatten the account using the Flatten() method, expecting it to close all open orders and positions. While the positions flattened successfully, the ATM orders remained in states such as "Cancel Submitted" or "Initialized", and they were not cleared.
      • Could you clarify why this behavior occurs and whether AtmStrategyClose is required to handle ATM-specific orders in such scenarios?

    Any insights into how to correctly close an ATM strategy or clear its associated orders programmatically would be greatly appreciated.

    Thank you for your time and assistance!

    Best regards,
    Zadolaya Omani
    ​​​

    #2
    Actually I also get those two alerts after using the flatten method
    Click image for larger version  Name:	{6CFBA7D5-8450-4043-B180-66ED02C73B2B}.png Views:	0 Size:	5.8 KB ID:	1324955
    Click image for larger version  Name:	{469D1649-29A5-4DD8-88DF-0B07B0BFA76F}.png Views:	0 Size:	5.2 KB ID:	1324956

    Comment


      #3
      Hello Zadomani,

      Thank you for your post.

      AtmStrategyClose() should be used if you are working with an Atm strategy within your script. The ID should be the same as the ID used to start the Atm Strategy.

      For example,

      Code:
      atmStrategyId = GetAtmStrategyUniqueId();
      atmStrategyOrderId = GetAtmStrategyUniqueId();
      
      AtmStrategyCreate(OrderAction.Buy, OrderType.Market, 0, 0, TimeInForce.Day,
      atmStrategyOrderId, "MyTemplate", atmStrategyId, (atmCallbackErrorCode, atmCallbackId) => {
      
      // checks that the call back is returned for the current atmStrategyId stored
      if (atmCallbackId == atmStrategyId)
      {
      // check the atm call back for any error codes
      if (atmCallbackErrorCode == Cbi.ErrorCode.NoError)
      {
      // if no error, set private bool to true to indicate the atm strategy is created
      isAtmStrategyCreated = true;
      }
      }
      });
      
      AtmStrategyClose(atmStrategyId);​

      Flatten() can be called on the account and an instrument must be specified to flatten. It should also flatten all orders generated by the Atm Strategy on that account.

      From the error, it looks like one of the positions may have failed to close out. This likely means there was a connection loss between your computer and the servers. Please see this support article:




      Regarding the object reference error, Object reference not set to an instance of an object indicates that there is a null value in a variable being used in your script.

      I recommend you debug the script to narrow now exactly which line your code is hitting this error at.

      You can use prints, place a print every few lines with a new number: Print("1"); etc. That will help you see where the script gets in execution when you hit the error. Once you know what line throws the error its much easier to debug. After you have confirmed which line is throwing the error, you can add another print to then check which variable or object is null.

      Checking for Null References - https://ninjatrader.com/support/help...references.htm

      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