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 argusthome, 03-08-2026, 10:06 AM
        0 responses
        65 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        41 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        23 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        26 views
        0 likes
        Last Post TheRealMorford  
        Started by Mindset, 02-28-2026, 06:16 AM
        0 responses
        52 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Working...
        X