Highest of all variables

greco26

Active member
Is there a way to get the highest of all variables or is the only way to use nested Max()?

def var1 = 1;
def var2 = 2;
def var3 = 3;
def var4 = ...... and so on....

#I want the next def to give me the highest value of all of these variables
def highestvar = ??
 

SleepyZ

Well-known member
VIP
Lifetime
Is there a way to get the highest of all variables or is the only way to use nested Max()?

def var1 = 1;
def var2 = 2;
def var3 = 3;
def var4 = ...... and so on....

#I want the next def to give me the highest value of all of these variables
def highestvar = ??

Nesting is one way

Ruby:
def var1 = 1;
def var2 = 3;
def var3 = 2;
def var4 = -1;
def var5 = 0;
def var6 = max(var1,max(var2,max(var3,max(var4,var5))));
def var7 = min(var1,min(var2,min(var3,min(var4,var5))));
addlabel(1,"max: " + var6 + " min: " + var7, color.yellow);
 

Svanoy

Active member
@greco26
Def the variables under the same variable and use highestall() or lowestall().
Code:
declare lower;
def var1 = 5;
def var2 = 8;
def var3 = 2;
def var4 = 9;
def var5 = 7;

def line = if IsNaN(line[1]) then var1 else if line[1]==var1 then var2 else if line[1]==var2 then var3
            else if line[1]==var3 then var4 else if line[1]==var4 then var5 else if line[1]==var5 then var1
            else Double.nan;

def highest = HighestAll(line);
def lowest = LowestAll(line);
addlabel(yes,highest,color.white);
addlabel(yes,lowest,color.white);

No reason to ever do it this way though....
 

halcyonguy

Well-known member
VIP
Lifetime
@greco26
Def the variables under the same variable and use highestall() or lowestall().
Code:
declare lower;
def var1 = 5;
def var2 = 8;
def var3 = 2;
def var4 = 9;
def var5 = 7;

def line = if IsNaN(line[1]) then var1 else if line[1]==var1 then var2 else if line[1]==var2 then var3
            else if line[1]==var3 then var4 else if line[1]==var4 then var5 else if line[1]==var5 then var1
            else Double.nan;

def highest = HighestAll(line);
def lowest = LowestAll(line);
addlabel(yes,highest,color.white);
addlabel(yes,lowest,color.white);

No reason to ever do it this way though....
that is a clever formula.

since the pattern of data is repeated, you only need to look at the last 5 values.

you could add a variable for the count of variables ,
def cnt = 5;

then use that as length in,
= lowest( line, cnt)
= highest( line, cnt)

and not have to use highestall, lowestall

.......

once you have a set of different variables copied to 1 variable, it becomes possible to apply some functions to the list.
i use a different method, that i will talk about one of these days.
 

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Top