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 > General Programming

General Programming General NinjaScript programming questions.

Reply
 
Thread Tools Display Modes
Old 11-06-2008, 10:19 AM   #1
Mindset
Senior Member
 
Join Date: Mar 2008
Location: UK West Sussex
Posts: 665
Thanks: 9
Thanked 9 times in 7 posts
Default MaxList

Is there a code line that will output the maximum value of a list of numbers

eg Math.Max(n1,n2,n3,.....n) - obviously Math.Max only takes 2 arguments and I am looking to analyse more than that.
Mindset is offline  
Reply With Quote
Old 11-06-2008, 10:24 AM   #2
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 could do Math.Max(Math.Max(___, ____), ___) and cascade it. If you have a ton of values you could create a DataSeries and use MAX(myDataSeries, 20)[0] to get the max value of the last 20 values. You could also just create a loop to go through Math.Max against your list, storing the higher value each time and returning the max at the end.
NinjaTrader_Josh is offline  
Reply With Quote
Old 11-06-2008, 10:29 AM   #3
Mindset
Senior Member
 
Join Date: Mar 2008
Location: UK West Sussex
Posts: 665
Thanks: 9
Thanked 9 times in 7 posts
Default

Thanks Josh - I shall try and use either of those methods and see if I can get it to work. I only have 3 arguments so it shouldn't be too onerous.

If I call a function like MAX is it much more cpu intensive than writing say a nested Math.Max set of functions ( say 2)?
Mindset is offline  
Reply With Quote
Old 11-06-2008, 10:31 AM   #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

Yes it will be. If you only have 3 arguments just do Math.Max(Math.Max(___, ___), ___).
NinjaTrader_Josh 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


All times are GMT -6. The time now is 12:41 PM.