Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Is there a DLL function for Quantity?

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

    Is there a DLL function for Quantity?

    Hi, I'm looking to use the DLL with tradestation. I would like to be able to call a Ninja Function to get the number of contracts in the OrderID.

    Is this possible?

    TIA

    AJNIN

    #2
    What you can get is the filled amount of an order. Provided you store the original order quantity amount upon submission, you could get the difference.
    RayNinjaTrader Customer Service

    Comment


      #3
      Please clarify...

      Ray, could you please clarify, this seems complicated. So if I want to know how many contracts I'm LONG or SHORT in a position, I have to call NTFilled(OrderId) for every order?

      For example, starting from Flat, I might BUY 10, then sell 5, and be stopped out on 2, giving a current position of 3; but to get this out of NTFilled(), am I going to have to know all of the possible standing orders and check them all on each bar?

      Comment


        #4
        Hello,

        In your case you could do this with NTFilled. However you could instead use for example
        string NTOrderStatus(stringorderId);

        You can tell from this if your order is filled or part filled or working.

        http://www.ninjatrader.com/support/h...=order%2Bstate

        If it is PartFilled, then you would need to take some action and use NTFilled() to find out how many you where filled on and then take any action on your side you need to adjust for on your strategy side or wait until you have reached a status of filled which means that the entire order is filled.
        BrettNinjaTrader Product Management

        Comment


          #5
          Using OrderId's seems to break when there are many orders to get to a position

          I never assume that the TradeStation and Ninja orders are in sync. For example, TradeStation might lose it's connection and restart. So, let's say you enter a trade in TradeStation and NinjaTrader, you lose the TradeStation connection which loses all your variables and TradeStation basically reloads the strategy when it comes back up, so you've lost all your variables such as OrderId. But consider that this might of been a complicated trade where I originally bought 10 (call that OrderId=Buy1), sold 5 (call that OrderId=Sell1), stopped out of 2 (call that OrderId=Stop1), rebought 4 (call that OrderId=Rebuy1), sold 2 again (call that OrderId=Sell2), and rebought 2 again (call that OrderId=Rebuy2), the question at this point is, the what is the current state of Ninja? You can easily get the MarketPosition as LONG, but how many contracts am I long? Without recreating the order sequence and knowing exactly what orders fired and filled, this seems impossible.

          It seems that Ninja is missing the function that returns the number of open contracts. You have MarketPosition, what's the equivalent to CurrentContracts?

          If I knew how many contracts were open and what my MarketPosition was, I could just resume managing the order where I left off, whether I had 5, 7, or 10 contracts, when I hit my next target, I simply want to lay off a certain percentage of my original lot size.

          Comment


            #6
            Hello,

            You would not be able to do this type of sync on an account level. This would need to be manually synced. This is the same in our NinjaScript strategies the run inside of NinjaTrader. We do this because you may have multiple strategies running on the same instrument which would cause syncing issues if each one was trying to sync to the master account.

            Therefor when or if you need to restart the strategy. The strategy runs on historical data and figures out that it is for example should be 10 long. Either this will match what your account position is and you can continue on with no manual process needed. If there is a discrepancy you would then need to submit an order manually on your account for 10 contracts long if you where flat or whatever the difference is needed to sync what the trade station strategy expects to what your actual account position is for the strategy to continue to run smoothly and not get our of sync.

            This would need to be done with a NinjaScript strategy as well.

            An option you have in a NinjaScript strategy and you can do this also with a Trade Station strategy is to wait for market position to go back to flat before allowing the Trade Station strategy to start submitting orders. This way you can manage the exit manually and then when the strategy is flat it will then take the next signal for a trade and this would be one method available to you to insure that the strategy position and account position are in sync. However with this method you would need to insure that your account position is also flat when the strategy starts submitting orders.

            More general information on this for NinjaScript strategies that also applies to tradestation run strategies can be found here.

            Strategy Position vs. Account Position:


            Let me know if I can be of further assistance.
            BrettNinjaTrader Product Management

            Comment


              #7
              I just discovered that NTMarketPosition returns the number of contracts you are LONG or SHORT, so if I'm LONG 15, it returns +15 and if I'm SHORT 15, it returns -15. This is exactly what I want. Is this an undocumented feature of NTMarketPosition?

              Comment


                #8
                douggreen,

                That would indeed be the behavior of NTMarketPosition.
                Josh P.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                0 responses
                630 views
                0 likes
                Last Post Geovanny Suaza  
                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                0 responses
                364 views
                1 like
                Last Post Geovanny Suaza  
                Started by Mindset, 02-09-2026, 11:44 AM
                0 responses
                105 views
                0 likes
                Last Post Mindset
                by Mindset
                 
                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                0 responses
                566 views
                1 like
                Last Post Geovanny Suaza  
                Started by RFrosty, 01-28-2026, 06:49 PM
                0 responses
                568 views
                1 like
                Last Post RFrosty
                by RFrosty
                 
                Working...
                X