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
        BertrandNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by wzgy0920, 04-20-2024, 06:09 PM
        2 responses
        26 views
        0 likes
        Last Post wzgy0920  
        Started by wzgy0920, 02-22-2024, 01:11 AM
        5 responses
        32 views
        0 likes
        Last Post wzgy0920  
        Started by wzgy0920, Yesterday, 09:53 PM
        2 responses
        49 views
        0 likes
        Last Post wzgy0920  
        Started by Kensonprib, 04-28-2021, 10:11 AM
        5 responses
        191 views
        0 likes
        Last Post Hasadafa  
        Started by GussJ, 03-04-2020, 03:11 PM
        11 responses
        3,230 views
        0 likes
        Last Post xiinteractive  
        Working...
        X