# I need help writing a simple line of code that I plan to use in a strategy

##### Well-known member
In my strategy I have multiple indicators I'm trying to work into it effectively and noticed that when one signal shows bullish or bearish for 4 strait bars, it is a good time to exit a long or short position. How would that be translated to code, essentially I need code that would coincide with [bearish data is true for the last 4 bars] but in proper format. Simple I know, but for a novice little things like this can take way more time then they need to to solve. I figured I could sleep and hopefully wake up with an answer.

#### markos

##### Well-known member
VIP
Now you've done it. You can't sleep and wake up to an answer. Sleep is over-rated.
Go into that Gold Mine I shared earlier and look at tab #2, i think, and you'll find an education tab.
Start there and come back when you get stuck with code.
It's not that simple, you didn't give enough info. Sorry.

#### horserider

##### Well-known member
VIP
low <low[1] .... blah,blah,blah. I am sure there is a way like. [low <low,4] Just off top of my had so may not b correct. Search and you shall find.
should be parenthesis... darn keyboard is failing

#### RobertPayne

##### Member
Let's just use @horserider 's example of low < low[1].

Ruby:
``````def lowerLow = low < low[1];
def four_in_a_row = Sum(lowerLow, 4) == 4;

AssignPriceColor(if four_in_a_row then Color.MAGENTA else Color.CURRENT);``````

How this works.

def lowerLow is a boolean that evaluates as either true (this low is lower than the previous one) or false (it's not). Remember, that true = 1 and false = 0. So, add up the last 4 lowerLow's using the Sum() function. If that adds up to 4, then you know that the condition has been true 4 times in a row.

##### Well-known member
thanks for the help!

## 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?