Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Checking ATM Market Position

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

    Checking ATM Market Position

    is there a better way to check for position when using an atm in a strategy? I'm getting the error on every price change:
    'GetAtmStrategyMarketPosition' method error: Missing ATM strategy ID parameter
    'GetAtmStrategyMarketPosition' method error: Missing ATM strategy ID parameter
    'GetAtmStrategyMarketPosition' method error: Missing ATM strategy ID parameter
    'GetAtmStrategyMarketPosition' method error: Missing ATM strategy ID parameter
    'GetAtmStrategyMarketPosition' method error: Missing ATM strategy ID parameter
    'GetAtmStrategyMarketPosition' method error: Missing ATM strategy ID parameter
    'GetAtmStrategyMarketPosition' method error: Missing ATM strategy ID parameter
    'GetAtmStrategyMarketPosition' method error: Missing ATM strategy ID parameter
    'GetAtmStrategyMarketPosition' method error: Missing ATM strategy ID parameter
    'GetAtmStrategyMarketPosition' method error: Missing ATM strategy ID parameter
    'GetAtmStrategyMarketPosition' method error: Missing ATM strategy ID parameter
    'GetAtmStrategyMarketPosition' method error: Missing ATM strategy ID parameter
    'GetAtmStrategyMarketPosition' method error: Missing ATM strategy ID parameter
    'GetAtmStrategyMarketPosition' method error: Missing ATM strategy ID parameter
    'GetAtmStrategyMarketPosition' method error: Missing ATM strategy ID parameter
    'GetAtmStrategyMarketPosition' method error: Missing ATM strategy ID parameter
    'GetAtmStrategyMarketPosition' method error: Missing ATM strategy ID parameter
    'GetAtmStrategyMarketPosition' method error: Missing ATM strategy ID parameter
    'GetAtmStrategyMarketPosition' method error: Missing ATM strategy ID parameter​

    I'm currently using
    HTML Code:
    if (GetAtmStrategyMarketPosition(atmStrategyId) == MarketPosition.Flat)
                {
                  ExecuteLongEntry();
                }​
    The error seems like it would be expected, since there isn't an open position, but for it to be constantly echoing this makes me think there might be a quieter way to check?


    Second piece, what is the way to check position quantity when using ATMs? The following doens't seem to work:
    HTML Code:
              if (GetAtmStrategyPositionQuantity(atmStrategyId) < 5)
              {
                ExecuteShortEntry();
              }​

    #2
    Hello spencerduran,

    Ensure the Atm is started by checking the isAtmStrategyCreated bool is true. (This should be set to true in the AtmStrategyCreate() callback).
    Ensure GetAtmStrategyEntryOrderStatus(orderId)[2] is "Filled".
    Ensure the atmStrategyId is the same that was provided to AtmStrategyCreate and this has not changed or been set to an empty string.
    This should prevent the error by ensuring the entry has filled and the Atm is active.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thanks

      So to check if flat, i would first check if the strategycreated bool is false?

      Also, the second part of the question:
      what is the best way to find atmstrategypositionquantity?

      Comment


        #4
        Hello spencerduran,

        Yes, if the Atm is not active yet, there will be no atm object with a position to check, so an error will occur.

        GetAtmStrategyPositionQuantity() is the best way to get the atm position quantity, but only after the atm is created and the entry order has filled.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          That seems to work

          is it possible to add an additional atm order to increase position quantity? I think since this only works when the atmStrategyId.Length == 0, i need to change something about the first part of ExecuteShortEntry()

          HTML Code:
                    ##################################################################################################################
                      Shorts
                    ##################################################################################################################
                    */
                    //#################### Entries ####################    
                      if (dayBias == BiasState.Short
                        && shortLastEntryBar != CurrentBar
                        && (GetAtmStrategyPositionQuantity(atmStrategyId) < 5)
                        && signal == "short")
                      {
                          ExecuteShortEntry();
                      }
                  }
                }
              }
              /*
              ##################################################################################################################
                CUSTOM METHODS
              ##################################################################################################################
              */
          
              //#################### ENTRY  METHODS ####################
          
           private void ExecuteShortEntry() {
                        // Make sure this strategy does not execute against historical data
                  if(State == State.Historical)
                      return;
              
                  // Submits an entry limit order at the current low price to initiate an ATM Strategy if both order id and strategy id are in a reset state
                  // **** YOU MUST HAVE AN ATM STRATEGY TEMPLATE NAMED 'AtmStrategyTemplate' CREATED IN NINJATRADER (SUPERDOM FOR EXAMPLE) FOR THIS TO WORK ****
                  if (orderId.Length == 0 && atmStrategyId.Length == 0)
                  {
                      isAtmStrategyCreated = false;  // reset atm strategy created check to false
                      atmStrategyId = GetAtmStrategyUniqueId();
                      orderId = GetAtmStrategyUniqueId();
                      AtmStrategyCreate(OrderAction.Sell, OrderType.Limit, Close[0], High[0], TimeInForce.Day, orderId, "15-30", atmStrategyId, (atmCallbackErrorCode, atmCallBackId) => {
                          //check that the atm strategy create did not result in error, and that the requested atm strategy matches the id in callback
                          if (atmCallbackErrorCode == ErrorCode.NoError && atmCallBackId == atmStrategyId)
                              isAtmStrategyCreated = true;
                      });
                  }
              
                  // Check that atm strategy was created before checking other properties
                  if (!isAtmStrategyCreated)
                      return;
              
                  // Check for a pending entry order
                  if (orderId.Length > 0)
                  {
                      string[] status = GetAtmStrategyEntryOrderStatus(orderId);
              
                      // If the status call can't find the order specified, the return array length will be zero otherwise it will hold elements
                      if (status.GetLength(0) > 0)
                      {
                          // If the order state is terminal, reset the order id value
                          if (status[2] == "Filled" || status[2] == "Cancelled" || status[2] == "Rejected")
                              orderId = string.Empty;
                      }
                  }
                  // If the strategy has terminated reset the strategy id
                  else if (atmStrategyId.Length > 0 && GetAtmStrategyMarketPosition(atmStrategyId) == Cbi.MarketPosition.Flat)
                      atmStrategyId = string.Empty;
                shortEntryCount++;
                shortLastEntryBar = CurrentBar;
                shortEntryBarHigh = High[0] + 1;
              }​

          Comment


            #6
            Hello spencerduran,

            There isn't a way to scale into an existing Atm through NinjaScript.
            You could choose to start a second atm, instead of scaling in.
            Or we often suggest instead, placing an order to the account and then adjusting the quantity of the stop and limit orders to cover the quantity of the new entry.
            Chelsea B.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by argusthome, 03-08-2026, 10:06 AM
            0 responses
            110 views
            0 likes
            Last Post argusthome  
            Started by NabilKhattabi, 03-06-2026, 11:18 AM
            0 responses
            59 views
            0 likes
            Last Post NabilKhattabi  
            Started by Deep42, 03-06-2026, 12:28 AM
            0 responses
            37 views
            0 likes
            Last Post Deep42
            by Deep42
             
            Started by TheRealMorford, 03-05-2026, 06:15 PM
            0 responses
            41 views
            0 likes
            Last Post TheRealMorford  
            Started by Mindset, 02-28-2026, 06:16 AM
            0 responses
            78 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Working...
            X