# First red or green day

#### sasudt

##### New member
Hi guys how can I scan for first red day after 3 or 4 or 5 consecutive green days.
Example, 5 green days with red day on day 6.
Is there any script available?

Solution
Off the top of my head, you could do this:

Code:
``````def o = open(period = "DAY");
def c = close(period = "DAY");

# first green day after 3-5 red days
def threeR = c[1] < o[1] && c[2] < o[2] && c[3] < o[3];
def fourR = c[1] < o[1] && c[2] < o[2] && c[3] < o[3] && c[4] < o[4];
def fiveR = c[1] < o[1] && c[2] < o[2] && c[3] < o[3] && c[4] < o[4] && c[5] < o[5];

plot firstGreenDay = c > o && (threeR or fourR or fiveR);

# first red day after 3-5 green days
def threeG = c[1] > o[1] && c[2] > o[2] && c[3] > o[3];
def fourG = c[1] > o[1] && c[2] > o[2] && c[3] > o[3] && c[4] > o[4];
def fiveG = c[1] > o[1] && c[2] > o[2] && c[3] > o[3] && c[4] > o[4] && c[5] > o[5];

#plot firstRedDay = c < o && (threeG or...``````
Off the top of my head, you could do this:

Code:
``````def o = open(period = "DAY");
def c = close(period = "DAY");

# first green day after 3-5 red days
def threeR = c[1] < o[1] && c[2] < o[2] && c[3] < o[3];
def fourR = c[1] < o[1] && c[2] < o[2] && c[3] < o[3] && c[4] < o[4];
def fiveR = c[1] < o[1] && c[2] < o[2] && c[3] < o[3] && c[4] < o[4] && c[5] < o[5];

plot firstGreenDay = c > o && (threeR or fourR or fiveR);

# first red day after 3-5 green days
def threeG = c[1] > o[1] && c[2] > o[2] && c[3] > o[3];
def fourG = c[1] > o[1] && c[2] > o[2] && c[3] > o[3] && c[4] > o[4];
def fiveG = c[1] > o[1] && c[2] > o[2] && c[3] > o[3] && c[4] > o[4] && c[5] > o[5];

#plot firstRedDay = c < o && (threeG or fourG or fiveG); # commented out``````

Last edited:

87k+ Posts
153 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?