Thanks much!
Announcement
Collapse
Looking for a User App or Add-On built by the NinjaTrader community?
Visit NinjaTrader EcoSystem and our free User App Share!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less
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
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.BertrandNinjaTrader Customer Service
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:
Code: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 Nickgiaco, 02-26-2024, 10:23 AM
|
2 responses
70 views
0 likes
|
Last Post Today, 05:12 AM | ||
Started by Johndc, Today, 04:39 AM
|
0 responses
2 views
0 likes
|
Last Post
by Johndc
Today, 04:39 AM
|
||
Started by johntraderuser2, Today, 02:34 AM
|
0 responses
8 views
0 likes
|
Last Post Today, 02:34 AM | ||
Started by IanS00, 03-27-2024, 11:24 AM
|
2 responses
13 views
0 likes
|
Last Post Today, 02:00 AM | ||
Started by Mariawilcoxi, Today, 01:32 AM
|
0 responses
5 views
0 likes
|
Last Post
by Mariawilcoxi
Today, 01:32 AM
|
Comment