# Condition is false for past amount of bars

#### Gilgameash

##### New member
How would I write the following statement in thinkscript?

Condition3 =If condition1 or condition2 are false for the past x amount of bars.

Solution
the simplest way I know of is to write a series of 1 and 0 for the condition(s):
Code:
``````def condition_1 = if close > sma then 1 else 0;
def condition_2 = if close > ema then 1 else 0;
def condition_1_2 = if ( condition_1 == 0 OR condition_2 == 0 ) then 0 else 1;

def condition_3 = if sum(condition_1_2, n) == 0 then 1 else 0;``````
Condition_3 is true (1) if for all the bars in n bars, either condition_1 or condition_2 has been false (0) for each bar.

Be sure to adjust your if then else statements to put your actual conditions in place. I just used SMA and EMA as placeholders. THIS CODE WILL NOT RUN without defining them.

-mashume
the simplest way I know of is to write a series of 1 and 0 for the condition(s):
Code:
``````def condition_1 = if close > sma then 1 else 0;
def condition_2 = if close > ema then 1 else 0;
def condition_1_2 = if ( condition_1 == 0 OR condition_2 == 0 ) then 0 else 1;

def condition_3 = if sum(condition_1_2, n) == 0 then 1 else 0;``````
Condition_3 is true (1) if for all the bars in n bars, either condition_1 or condition_2 has been false (0) for each bar.

Be sure to adjust your if then else statements to put your actual conditions in place. I just used SMA and EMA as placeholders. THIS CODE WILL NOT RUN without defining them.

-mashume

87k+ Posts
110 Online

## The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
• Exclusive indicators
• Proven strategies & setups
• Private Discord community
• Exclusive members-only content
• 1 full year of unlimited support

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?