Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 MatthewLesko, 05-21-2021, 09:37 PM
            4 responses
            163 views
            0 likes
            Last Post Mahmad1323  
            Started by samish18, Today, 03:02 PM
            3 responses
            15 views
            0 likes
            Last Post bltdavid  
            Started by Jakub, Today, 11:06 AM
            1 response
            16 views
            0 likes
            Last Post NinjaTrader_LuisH  
            Started by samish18, Today, 03:50 AM
            10 responses
            19 views
            0 likes
            Last Post samish18  
            Started by Mestor, 06-03-2018, 10:09 AM
            16 responses
            2,872 views
            0 likes
            Last Post myaha1000  
            Working...
            X