Thanks much!
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Entering Position Based on Percentage of Account
Collapse
X
-
Hi trend747,
If you want to access programatically the value of your account, you can use GetAccountValue();
double myPositionSize = GetAccountValue(AccountItem.CashValue) * .03;
This is a real-time only value. To do the same in a backtest requires manually calculating an account balance with TradePerformance class:
Ryan M.NinjaTrader Customer Service
-
This is only for backtesting purposes
The $ risk should be 1% of my current capital (starting capital +- performance)Code:protected override void OnBarUpdate() { if (moneymanagement == 1 ) { double startingcapital = 1000000; DefaultQuantity = (int)((startingcapital-Performance.AllTrades.Count)*0.01 /(Instrument.MasterInstrument.PointValue * StopValue)) ; } }
doesn't seem like the performance variable is doing anything, and if i try to print the performance it does nothing. what is my mistake?
Comment
-
yep this is embedded in a actual strategy which is working even after adding the code, but the contract size is still not varying as expected
Set Order Quantity is set to "by strategy"
Comment
-
mmmh
but the strategy is exactly doing what i want when i choose "by strategy", the contract size is varying with the stopsize. => constant dollar risk per trade is working.
when choosing by defaultquantiy i have to choose a fix number
Comment
-
I guess I don't understand why you attempt to set a defaultquantity here for this process, this is meant to provide a basis to enter a custom quantity from the UI or program a hard coded default into the script. If you want to adapt on the fly with the script then I would suggest staying with calculating in a custom variable in OnBarUpdate() and feeding this to your Entry methods.
Comment
-
Old thread I know, but...
I would like to get a tip or at least a direction on what to think of and use in an Unmanaged Strategy in NinjaTrader 8 regarding only putting, for example 2% of cash value.
My strategy is building up Position.Quantities and I have to limit the amount.
Kennet
Comment
-
Hello Kennet,
Thank you for your post.
You can pull the cash value and calculate 2 percent of the CashValue in the following manner:
For information on pulling Account values in NinjaTrader 8 please visit the following link: http://ninjatrader.com/support/helpG.../en-us/get.htmCode:cash = Account.Get(AccountItem.CashValue, Currency.UsDollar); twoPercent = Convert.ToInt32(cash * .02);
Please let me k now if you have any questions.
Comment
-
-
Hello Kennet,
Thank you for your response.
You can refer to the details at the following link for information on pulling the cost of each trade: http://ninjatrader.com/support/forum...841#post493841
Please let me know if you have any questions.
Comment
-
Hello CoopersFX,
Thank you for your post and welcome to the NinjaTrader Support Forum!
You would use the calculation to determine the quantity of the order. This means you would take the output of the calculation as your quantity for your entry or exit order method. The code would likely need to be placed where you place your entry or exit method as an action for a condition.
Please let me know if you have any questions.
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
563 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
329 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
101 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
547 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
548 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment