Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Changing number of contracts traded

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

    Changing number of contracts traded

    Hello,
    I am wondering if there is a way to change the number of contracts traded by a strategy in an automated way.

    Eg. I'd like my strategy to buy one contract for every $10000 of balance that I have in my account. So, if the balance goes up to $20000, it will place trade for 2 contracts for $30000 it will place 3 contracts. But if the balance comes down to $20000 for some reason, it will automatically place trade for only 2 contracts.

    Is there a way to accomplish this in NT?
    Thanks.

    #2
    Hi pandyav,

    Yes, this is possible. You can have a variable for order quantity that is calculated any way you like. If you wanted access to the real time account values, there is method GetAccountValue()


    Code:
    double orderQuantity = GetAccountValue(AccountItem.CashValue) / 10000;
    EnterLong(Math.Min((int)orderQuantity, 1)); //Math.Min used in case you get below 10000.
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Hi,

      I am new to NinjaTrader, and am just starting to evaluate the software and trying to set up some of my strategies to trade automatically.

      I am having a similar problem to pandyav, but when I inserted the lines of code into my program, it still only trades one contract, while back testing; regardless of what I set the starting account value at.

      Any help on this matter would be appreciated.

      Thank You

      Comment


        #4
        Welcome to our forums - the GetAccountValue call would only work in real-time simulated / live trading, it would not work on historical data.



        For backtesting, to use the entered AccountSize parameter please ensure your order qty for the strategy is driven ByAccount - http://www.ninjatrader.com/support/h...a_strategy.htm

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by DannyP96, 05-18-2026, 02:38 PM
        1 response
        78 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 05-11-2026, 05:56 AM
        0 responses
        131 views
        0 likes
        Last Post CarlTrading  
        Started by CarlTrading, 05-10-2026, 08:12 PM
        0 responses
        79 views
        0 likes
        Last Post CarlTrading  
        Started by Hwop38, 05-04-2026, 07:02 PM
        0 responses
        242 views
        0 likes
        Last Post Hwop38
        by Hwop38
         
        Started by Mindset, 04-21-2026, 06:46 AM
        0 responses
        330 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Working...
        X