NinjaTrader Support Forum  

Go Back   NinjaTrader Support Forum > NinjaScript Development Support > Indicator Development

Indicator Development Support for the development of custom indicators using NinjaScript.

Reply
 
Thread Tools Display Modes
Old 07-11-2009, 05:20 AM   #1
Shansen
Senior Member
 
Join Date: Jan 2009
Location: Melbourne
Posts: 178
Thanks: 3
Thanked 0 times in 0 posts
Default The maximum of two variables

Is there a simple function that can be used to compare two (double) variables and store the maximum (the larger of the two) value for later reference?

The structure I'm using to achieve this currently is a little long in the tooth:
If (variable1 > variable2)
{
variable3 = variable1;
}
else
{
variable3 = variable2;
}
Thanks
Shannon
Shansen is offline  
Reply With Quote
Old 07-11-2009, 05:54 AM   #2
zweistein
Senior Member
 
Join Date: Jan 2009
Posts: 584
Thanks: 2
Thanked 20 times in 12 posts
Default

you could try

Math.Max(variable1,variable2);
zweistein is offline  
Reply With Quote
Old 07-11-2009, 11:27 AM   #3
NetTecture
Senior Member
 
Join Date: Mar 2009
Posts: 172
Thanks: 0
Thanked 1 time in 1 post
Default

Math.Max is the best answer.

That said, the second best would be:

variable3 = variable1>variable2 ? variable1 : variable2;

The original post (if) indicates... the need to read a good book about C#
NetTecture is offline  
Reply With Quote
Old 07-13-2009, 04:45 AM   #4
Shansen
Senior Member
 
Join Date: Jan 2009
Location: Melbourne
Posts: 178
Thanks: 3
Thanked 0 times in 0 posts
Default

zweistein & NetTecture,

Thanks for your advice. It worked a treat.

Shannon
Shansen 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
maximum number of simultaneously open positions andrgm Strategy Development 1 06-03-2009 12:21 PM
Maximum uptime Radical Miscellaneous Support 8 02-20-2009 06:18 PM
maximum daily loss / drawdown starrynight Miscellaneous Support 3 11-10-2008 01:59 PM
Maximum Volume Value innovation Miscellaneous Support 6 10-20-2008 06:51 AM
Tick chart maximum? PKFFW Miscellaneous Support 1 05-13-2008 07:26 AM


All times are GMT -6. The time now is 03:01 AM.