Thanks
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
Calculating hypothetical results using position sizing in backtests
Collapse
X
-
Hello Bmatarese,
Thank you for your post.
When backtesting there is no means to set the values of the account. You would instead implement internal calculations in your strategy to calculate and track your own custom values for the desired account values, then calculate position size based on that. You could make the account starting balance a user input if you wish.
You should confirm with your broker the formula for calculating the funds required for each trade or contract.
Please let us know if we may be of further assistance to you.Kate W.NinjaTrader Customer Service
-
Hello Bmatarese,
Thank you for your reply.
Well, if you set up a user input for the account's starting cash value, you could use that to establish a position size this way:
onePercent = Convert.ToInt32(myCashValue * .01);
myOrderQuantity = onePercent / priceForOneContract;
Where myCashValue would be your user input for the cash value, and priceForOneContract would be the funds required for one contract. You'd likely need to round the resulting number to a whole number, for which you can use Math.Round, so here is publicly accessible documentation from Microsoft on that:
Please let us know if we may be of further assistance to you.
Kate W.NinjaTrader Customer Service
Comment
-
Hello Bmatarese,
Thank you for your reply.
You would need to track the PnL of each trade and add or subtract that from the variable for the cash value.
To get the PnL you'd need to use the TradeCollection to find the most recently completed trade and retrieve the PnL for it. I'd suggest taking a look at this example from our help guide:
As far as viewing the end result, you would likely want to use Print() statements in your code to print that information to a NinjaScript Output window.
This forum post goes into great detail on how to use prints to help figure out where issues may stem from — in your case you would want to use them to print the value of the variable you use to track the account balance. You can even add these using the Strategy Builder.
https://ninjatrader.com/support/foru...ns-not-working
Please let us know if we may be of further assistance to you.Kate W.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by Shansen, 08-30-2019, 10:18 PM
|
24 responses
938 views
0 likes
|
Last Post
by spwizard
Today, 01:29 AM
|
||
Started by Max238, Today, 01:28 AM
|
0 responses
3 views
0 likes
|
Last Post
by Max238
Today, 01:28 AM
|
||
Started by rocketman7, Today, 01:00 AM
|
0 responses
2 views
0 likes
|
Last Post
by rocketman7
Today, 01:00 AM
|
||
Started by wzgy0920, 04-20-2024, 06:09 PM
|
2 responses
27 views
0 likes
|
Last Post
by wzgy0920
Yesterday, 10:43 PM
|
||
Started by wzgy0920, 02-22-2024, 01:11 AM
|
5 responses
32 views
0 likes
|
Last Post
by wzgy0920
Yesterday, 10:33 PM
|
Comment