![]() |
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
|
|||||||
| General Programming General NinjaScript programming questions. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Senior Member
Join Date: Mar 2008
Location: UK West Sussex
Posts: 665
Thanks: 9
Thanked 9 times in 7 posts
|
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. |
|
|
|
|
|
#2 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
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.
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Senior Member
Join Date: Mar 2008
Location: UK West Sussex
Posts: 665
Thanks: 9
Thanked 9 times in 7 posts
|
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)? |
|
|
|
|
|
#4 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
Yes it will be. If you only have 3 arguments just do Math.Max(Math.Max(___, ___), ___).
Josh
NinjaTrader Customer Service |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|