NinjaTrader Support Forum  
X

Attention!

This website will be down for maintenance from Friday May 24th at 6PM MDT until Saturday May 25th at 11AM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com


Go Back   NinjaTrader Support Forum > Application Technical Support > Automated Trading

Automated Trading Support for automated trading systems using NinjaScript. Support for our ATI (Automated Trading Interface) used to link an external application such as TradeStation and eSignal to NinjaTrader.

Reply
 
Thread Tools Display Modes
Old 06-27-2012, 03:53 PM   #1
pandyav
Member
 
Join Date: Oct 2011
Posts: 70
Thanks: 2
Thanked 1 time in 1 post
Default 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.
pandyav is offline  
Reply With Quote
Old 06-27-2012, 04:01 PM   #2
NinjaTrader_RyanM
NinjaTrader Customer Service
 
NinjaTrader_RyanM's Avatar
 
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
Default

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()
http://www.ninjatrader.com/support/h...countvalue.htm

Code:
double orderQuantity = GetAccountValue(AccountItem.CashValue) / 10000;
EnterLong(Math.Min((int)orderQuantity, 1)); //Math.Min used in case you get below 10000.
NinjaTrader_RyanM is offline  
Reply With Quote
Old 10-04-2012, 06:57 PM   #3
cfp462
Junior Member
 
Join Date: Oct 2012
Posts: 24
Thanks: 0
Thanked 1 time in 1 post
Default

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
cfp462 is offline  
Reply With Quote
Old 10-05-2012, 02:21 AM   #4
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,421
Thanks: 252
Thanked 982 times in 964 posts
Default

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

http://www.ninjatrader.com/support/h...countvalue.htm

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
NinjaTrader_Bertrand is offline  
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Number of contracts with ATM ssg10 Strategy Development 1 06-17-2009 05:58 AM
Number of lots traded in a session John833 Strategy Development 2 01-09-2009 05:49 AM
Total Number of Contracts Trades pivot44 Miscellaneous Support 4 05-23-2007 03:53 PM
Number of contracts is bumped up deanldavis475 SuperDOM and other Order Entry Windows 2 05-14-2007 09:17 PM
Total Contracts Traded pivot44 Miscellaneous Support 1 03-26-2006 05:40 AM


All times are GMT -6. The time now is 03:47 PM.