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 > NinjaScript Development Support > Strategy Development

Strategy Development Support for the development of custom automated trading strategies using NinjaScript.

Reply
 
Thread Tools Display Modes
Old 02-05-2008, 09:11 AM   #1
clivehunt
Junior Member
 
Join Date: Jan 2008
Posts: 1
Thanks: 0
Thanked 0 times in 0 posts
Default Recalculating position size based on account size, % risked and stop loss

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
Last edited by clivehunt; 02-05-2008 at 09:19 AM.
clivehunt is offline  
Reply With Quote
Old 02-05-2008, 09:19 AM   #2
NinjaTrader_Dierk
Administrator
 
NinjaTrader_Dierk's Avatar
 
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
Default

You would have to code your math logic in NinjaScript and calculate the "quantity" value which you could shift into the various Enter... methods.
NinjaTrader_Dierk is offline  
Reply With Quote
Old 03-09-2008, 10:29 AM   #3
dendy
Member
 
Join Date: Jun 2007
Posts: 79
Thanks: 0
Thanked 0 times in 0 posts
Default

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.
dendy is offline  
Reply With Quote
Old 03-09-2008, 03:18 PM   #4
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

You can use AccountSize along with Performance to get what you want.
NinjaTrader_Josh is offline  
Reply With Quote
Old 03-10-2008, 07:11 AM   #5
dendy
Member
 
Join Date: Jun 2007
Posts: 79
Thanks: 0
Thanked 0 times in 0 posts
Default

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:

Quote:
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.
dendy is offline  
Reply With Quote
Old 03-10-2008, 07:24 AM   #6
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Default

Pulling in the actual account value is not supported at this time.
NinjaTrader_Ray is offline  
Reply With Quote
Old 03-11-2008, 09:47 AM   #7
dendy
Member
 
Join Date: Jun 2007
Posts: 79
Thanks: 0
Thanked 0 times in 0 posts
Default

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.CumPro fit" 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?

Quote:
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.
dendy is offline  
Reply With Quote
Old 03-11-2008, 10:09 AM   #8
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Default

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.
NinjaTrader_Ray is offline  
Reply With Quote
Old 03-11-2008, 10:23 AM   #9
dendy
Member
 
Join Date: Jun 2007
Posts: 79
Thanks: 0
Thanked 0 times in 0 posts
Default

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.
dendy is offline  
Reply With Quote
Old 03-11-2008, 12:04 PM   #10
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Default

Thats not what I am saying. What you want is how it works. Only trades generated by the strategy are included.
NinjaTrader_Ray is offline  
Reply With Quote
Old 03-11-2008, 01:15 PM   #11
dendy
Member
 
Join Date: Jun 2007
Posts: 79
Thanks: 0
Thanked 0 times in 0 posts
Default

Thanks again Ray,

I believe it is clear to me now.

dendy.
dendy is offline  
Reply With Quote
Old 07-23-2008, 01:27 AM   #12
moon_rainz
Junior Member
 
Join Date: Jul 2008
Posts: 16
Thanks: 0
Thanked 0 times in 0 posts
Default

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?
moon_rainz is offline  
Reply With Quote
Old 07-23-2008, 01:38 AM   #13
NinjaTrader_Dierk
Administrator
 
NinjaTrader_Dierk's Avatar
 
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
Default

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.
NinjaTrader_Dierk is offline  
Reply With Quote
Old 07-23-2008, 01:49 AM   #14
moon_rainz
Junior Member
 
Join Date: Jul 2008
Posts: 16
Thanks: 0
Thanked 0 times in 0 posts
Default

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?
moon_rainz is offline  
Reply With Quote
Old 07-23-2008, 01:50 AM   #15
NinjaTrader_Dierk
Administrator
 
NinjaTrader_Dierk's Avatar
 
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
Default

That is correct.
NinjaTrader_Dierk 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
Account Size - Safety Measure funk101 Strategy Development 7 04-28-2008 02:50 PM
Account Size / Set Account Programatically VagyokC4 Strategy Development 1 09-20-2007 11:40 AM
Last Size MrBaffalo Indicator Development 2 07-09-2007 07:02 AM
Looking for mechanism to scale down size based on performance scriabinop23 Strategy Development 11 05-16-2007 01:04 PM
Stop Loss Size JohnnyB Suggestions And Feedback 0 07-21-2005 04:04 AM


All times are GMT -6. The time now is 10:13 AM.