View Full Version : Recalculating position size based on account size, % risked and stop loss
clivehunt
02-05-2008, 09:11 AM
Does anyone know how to program NT so that when you backtest a system Ninjatrader recalculates the No. of contracts for each entry based on your current account size, % of account risked and your stop loss.
For example I trade with an account
> size of say $100,000 but only use a percentage of this per trade say
> 5% or $5000. To calculate the no of contracts traded for the Emini ES
> at $50/point and say 7pt stop loss with 5% of $100,000 = 5000/(7x50)
> which approximately equals 14 contracts. (I guess the calculation has
> to round down to the nearest integer too)! As my account goes up, so
> should the No. of contracts traded which compounds your account. How do I do this?
> Thanks in advance
>
> Clive
NinjaTrader_Dierk
02-05-2008, 09:19 AM
You would have to code your math logic in NinjaScript and calculate the "quantity" value which you could shift into the various Enter... methods.
dendy
03-09-2008, 10:29 AM
Hello Dierk and thanks to clivehunt for the question.
What would be the basic command for calling up the present account value so that it could be used in the way that clivehunt suggests. The account value would change after every trade and so the number of contracts would be adjusted accordingly per the math used. I use Interactive Brokers and NT 6.
Thanks,
dendy.
NinjaTrader_Josh
03-09-2008, 03:18 PM
You can use AccountSize along with Performance to get what you want.
dendy
03-10-2008, 07:11 AM
Thanks Josh for the reply,
From what I can tell, AccountSize will not give the Account Value but only allow one to specify the value as such:
protected override void Initialize()
{
AccountSize = 10000;
}
I am searching for a way that this can happen automatically by pulling in my actual account value and then allowing the type of mathematics that clivehunt talked about to do the rest.
Are you suggesting that this value cannot be obtained and by manually entering the AccountSize I can still calculate my values without NT6 automatically calculating my lot size for me based upon my entered margin requirements.
Thanks again for the help.
dendy.
NinjaTrader_Ray
03-10-2008, 07:24 AM
Pulling in the actual account value is not supported at this time.
dendy
03-11-2008, 09:47 AM
Thanks for the response Ray,
Do the following Perfomance commands work for the current NT6 session only? (I'm defining session as the time between NT6 start-up and shut-down.) Let's say we start NT6 in the morning and lose $1000 on short trades and make $1500 on long trades, will the "Performance.AllTrades.Performance.Currency.CumProf it" give the Cumulative Profit for the day only as $500? Does it care if the orders were entered by a strategy or manually or from the DynamicSuperDOM?
protected override void OnBarUpdate()
{
// Print out the maximum number of consecutive losing trades on all trades
Print(Performance.AllTrades.Performance.MaxConsecL oser);
// Print out the avg trade duration for winning long trades
Print(Performance.LongTrades.WinningTrades.Perform ance.AvgTradeDuration);
// Print out the realized profit in currency for all trades
Print(Performance.AllTrades.Performance.Currency.C umProfit);
}
Thanks for the help,
dendy.
NinjaTrader_Ray
03-11-2008, 10:09 AM
PnL relative to the strategy only and for the history of the strategy. If it only contained real-time trades then it would be for real-time only of course.
dendy
03-11-2008, 10:23 AM
Thanks Ray,
I think that what you're saying is that any trade made during the time the strategy is running will be picked up by these "Performance" commands and used in the strategy. Is there any way to make the "Performance" command only work for the trades entered by the strategy in which it resides?
For example,
I'm running a real time strategy (using real money) with the "Performance" command for Cumulative Profit. I then start up a strategy analyzer and run another strategy against historical data. This back tested strategy produces significant income. Does this back tested run have to impact the real time strategy's "Performance" command, or is there some way to insulate the strategy so that it does not pick up this other data?
Thanks,
dendy.
NinjaTrader_Ray
03-11-2008, 12:04 PM
Thats not what I am saying. What you want is how it works. Only trades generated by the strategy are included.
dendy
03-11-2008, 01:15 PM
Thanks again Ray,
I believe it is clear to me now.
dendy.
moon_rainz
07-23-2008, 01:27 AM
Hi,
I have a question about:
Performance.RealtimeTrades.TradesPerformance.Curre ncy.CumProfit
Suppose in Week 1, I first started running Strategy A on EURUSD, GBPUSD, USDCHF and USDJPY at the same time. At any time the above code is called, can I confirm that the cumulative profits is that of the realised profits/losses arising from Strategy A of the four pairs combined?
At the end of Week 1, I closed NinjaTrader and switched off my computer. At the start of Week 2, I powered up my computer, opened NinjaTrader and continued running Strategy A on EURUSD, GBPUSD, USDCHF and USDJPY. Can I confirm that the above code will include cumulative profits of both Week 1 and Week 2?
NinjaTrader_Dierk
07-23-2008, 01:38 AM
No, you would need to leave your strategy running to keep performance of your realtime trades accurate. Performance is NOT recalculated from the historical trades as you restart the strategy.
moon_rainz
07-23-2008, 01:49 AM
Hi Dierk,
Thanks for your reply.
With regards to the situation when Strategy A is run across four currency pairs, Performance will be the cumulative realised profits of all four pairs?
NinjaTrader_Dierk
07-23-2008, 01:50 AM
That is correct.
NinjaTrader_Josh
07-23-2008, 01:51 AM
Yup. You can try using some of the filters in getting the particular performance report pertaining to you though.
dendy
03-21-2009, 04:17 PM
Hello,
Do the performance commands work independently for each strategy and for each account. For example:
Strategy 1 running on ES for account A
Strategy 1 running on ES for account B
Will the performance commands add the gains and losses for these two accounts together? Or will the performance commands keep the real time gains and losses separate?
Any help is greatly appreciated,
dendy.
NinjaTrader_Ben
03-21-2009, 11:13 PM
Hello,
If you right click the strategy in the strategy tab, you will see stats on that strategy for whatever instruments it is trading. They are not mixed.
This may help:
http://www.ninjatrader-support.com/HelpGuideV6/StrategiesTab1.html
dendy
03-22-2009, 11:25 AM
Thanks Ben,
I really appreciate the quick response!
dendy.