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 CaptainJack, 05-29-2026, 05:09 AM
        0 responses
        335 views
        0 likes
        Last Post CaptainJack  
        Started by CaptainJack, 05-29-2026, 12:02 AM
        0 responses
        211 views
        0 likes
        Last Post CaptainJack  
        Started by charlesugo_1, 05-26-2026, 05:03 PM
        0 responses
        196 views
        1 like
        Last Post charlesugo_1  
        Started by DannyP96, 05-18-2026, 02:38 PM
        1 response
        288 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 05-11-2026, 05:56 AM
        0 responses
        245 views
        0 likes
        Last Post CarlTrading  
        Working...
        X