NexusFi: Find Your Edge


Home Menu

 





Math.Max, Max help with int


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one kidvic with 4 posts (0 thanks)
    2. looks_two cory with 1 posts (0 thanks)
    3. looks_3 sam028 with 1 posts (0 thanks)
    4. looks_4 Quick Summary with 1 posts (0 thanks)
    1. trending_up 2,664 views
    2. thumb_up 0 thanks given
    3. group 3 followers
    1. forum 6 posts
    2. attach_file 0 attachments




 
Search this Thread
  #1 (permalink)
kidvic
Los Angeles, CA
 
Posts: 92 since Mar 2015
Thanks Given: 13
Thanks Received: 3

Need some NinjaScript help!

so I have 10 conditions (bool) ranging from c1 - c10.
if any of those conditions are true, then they give me the appropriate int.
ex. if c1 is true, then m2 = 3.

This is all under BarUpdate()

int m2 = c1 ? 3 : 0;
int m3 = c2 ? 4 : 0;
int m4 = c3 ? 5 : 0;
int m5 = c4 ? 6 : 0;
int m6 = c5 ? 7 : 0;
int m7 = c6 ? 8 : 0;
int m8 = c7 ? 9 : 0;
int m9 = c8 ? 10 : 0;
int m10 = c9 ? 11 : 0;
int m11 = c10 ? 12 : 0;

int max1 = Max(m2, m3);
int max2 = Max(max1, m4);
int max3 = Max(max2, m5);
int max4 = Max(max3, m6);
int max5 = Max(max4, m7);
int max6 = Max(max5, m8);
int max7 = Max(max6, m9);
int max8 = Max(max7, m10);
int max9 = Max(max8, m11);

int maxcondition = max9;



Now, what I want to do is have maxcondition extract the highest value between m1 - m11, by using the max function (max1 - max9).

However, I get the following error:

the name 'max' does not exist in the current context.

The errors are on ints max1- max9

Thanks in advance.


Reply With Quote

Can you help answer these questions
from other members on NexusFi?
requesting .nrd replay files from 2026 spy and qqq
The Elite Circle
Building a free browser DOM/SMC simulator - need some ad …
Platforms and Indicators
What we know about Binances $6.3bn hack - BBC News
Cryptocurrency
My Rant with AMP Futures
Trading Reviews and Vendors
Bitcoin’s 2022 low, 2025 high and 2026 low so far arou …
Cryptocurrency
 
  #3 (permalink)
 
sam028's Avatar
 sam028 
Site Administrator
 
Posts: 3,779 since Jun 2009
Thanks Given: 3,840
Thanks Received: 4,709


Try Math.Max() and not Max().

And using an array of int would have been better...


Success requires no deodorant! (Sun Tzu)
Reply With Quote
  #4 (permalink)
kidvic
Los Angeles, CA
 
Posts: 92 since Mar 2015
Thanks Given: 13
Thanks Received: 3


sam028 View Post
Try Math.Max() and not Max().

Awesome!
Worked.

- Working around the ThinkScript version.

Thank you!


Reply With Quote
  #5 (permalink)
kidvic
Los Angeles, CA
 
Posts: 92 since Mar 2015
Thanks Given: 13
Thanks Received: 3

I shouted glory too soon. Is all my coding correct?
It doesn't produce any more errors, but it also doesn't draw a trendline.
The trendline when placed in a fresh new indicator under BarUpdate, works fine alone.

However, when I introduce the bools, and ints, and max ints, it does not.

What am I doing wrong?


Reply With Quote
  #6 (permalink)
 
cory's Avatar
 cory 
virginia
 
Experience: Intermediate
Platform: ninja
Trading: NQ
Posts: 6,099 since Jun 2009
Thanks Given: 877
Thanks Received: 8,098


kidvic View Post
I shouted glory too soon. Is all my coding correct?
It doesn't produce any more errors, but it also doesn't draw a trendline.
The trendline when placed in a fresh new indicator under BarUpdate, works fine alone.

However, when I introduce the bools, and ints, and max ints, it does not.

What am I doing wrong?

make sure you have enough bars before plotting a line

for example you are looking for max of 5 bars then wait for 5 bar values first thus;

protected override void OnBarUpdate()
{
// wait for 5 bar values before plotting
if (CurrentBar < 5)
return;


Reply With Quote
  #7 (permalink)
kidvic
Los Angeles, CA
 
Posts: 92 since Mar 2015
Thanks Given: 13
Thanks Received: 3


cory View Post
make sure you have enough bars before plotting a line

for example you are looking for max of 5 bars then wait for 5 bar values first thus;

protected override void OnBarUpdate()
{
// wait for 5 bar values before plotting
if (CurrentBar < 5)
return;

Thank you for that, I started commenting out the code, and I have come to this:



The rest of the code is working, its just some bools are what are causing the issue.


Reply With Quote




Last Updated on October 17, 2015


© 2026 NexusFi®, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Downloads - Top
no new posts