# How to do a multiple condition if statement?

#### TRexing

##### New member
Hi everyone! This is probably an easy question. I'm trying to figure out how to do a multiple condition if statement. If you look at the following, I'm trying to do something like this:

Code:
``````if cond1 > 0 && cond2 > 0 && cond3 > 0 && cond4 > 0 && cond5 > 0 {
# plot green arrow on chart
} else {}``````

How would I do this?

Solution
Hi everyone! This is probably an easy question. I'm trying to figure out how to do a multiple condition if statement. If you look at the following, I'm trying to do something like this:

Code:
``````if cond1 > 0 && cond2 > 0 && cond3 > 0 && cond4 > 0 && cond5 > 0 {
# plot green arrow on chart
} else {}``````

How would I do this?
something like this:
Code:
``plot buy = if condition_1 > 0 AND condition_2 >= 0 and condition_3 > 0 then LOW else double.nan;``

BUT

ToS works better, in my experience, with breaking it up into smaller code chunks:
Code:
``````def a = if condition_1 > 0 then 1 else 0;
def b = if condition_2 > 0 then 1 else 0;
def c = if condition_3 > 0 then 1 else 0;
plot buy = if a + b + c == 3 then LOW else double.nan;``````

it's...

#### mashume

##### Well-known member
VIP
Hi everyone! This is probably an easy question. I'm trying to figure out how to do a multiple condition if statement. If you look at the following, I'm trying to do something like this:

Code:
``````if cond1 > 0 && cond2 > 0 && cond3 > 0 && cond4 > 0 && cond5 > 0 {
# plot green arrow on chart
} else {}``````

How would I do this?
something like this:
Code:
``plot buy = if condition_1 > 0 AND condition_2 >= 0 and condition_3 > 0 then LOW else double.nan;``

BUT

ToS works better, in my experience, with breaking it up into smaller code chunks:
Code:
``````def a = if condition_1 > 0 then 1 else 0;
def b = if condition_2 > 0 then 1 else 0;
def c = if condition_3 > 0 then 1 else 0;
plot buy = if a + b + c == 3 then LOW else double.nan;``````

it's also cleaner when debugging to separate the arguments. I also stay away from && and the rest of all that as it reminds me too much of java and since thinkscript allows me to use niceties like "AND" I use it.

-mashume