# Find number of red candles after the market opened

#### rengagopal

##### Member
VIP
Hello,

I need a code to find out number of red candles [open > close] and total number of candles after the market has opened.

Thank you!!

Solution
Hello,

I need a code to find out number of red candles [open > close] and total number of candles after the market has opened.

Thank you!!

This might help with bubbles to track the accumlation of red candles during the day and a label option.

Code:
``````#Exampl_Red_Candle_Count_RTH

input showbubbles = yes;
input showlabel   = yes;
def red = if !(SecondsFromTime(0930) >= 0 and
SecondsTillTime(1600) > 0)
then 0
else if SecondsFromTime(0930) >= 0 and
SecondsTillTime(1600) > 0 and open > close
then red[1] + 1
else red[1];

def all = if !(SecondsFromTime(0930) >= 0 and
SecondsTillTime(1600)>0)
then 0
else if...``````
Hello,

I need a code to find out number of red candles [open > close] and total number of candles after the market has opened.

Thank you!!

This might help with bubbles to track the accumlation of red candles during the day and a label option.

Code:
``````#Exampl_Red_Candle_Count_RTH

input showbubbles = yes;
input showlabel   = yes;
def red = if !(SecondsFromTime(0930) >= 0 and
SecondsTillTime(1600) > 0)
then 0
else if SecondsFromTime(0930) >= 0 and
SecondsTillTime(1600) > 0 and open > close
then red[1] + 1
else red[1];

def all = if !(SecondsFromTime(0930) >= 0 and
SecondsTillTime(1600)>0)
then 0
else if SecondsFromTime(0930) >= 0 and
SecondsTillTime(1600) > 0
then  all[1] + 1
else all[1];

AddChartBubble(showbubbles and SecondsFromTime(0930) >= 0 and SecondsTillTime(1600) > 0,
high * 1.0025,
"Red: " + red +
"\nRTH: " + all +
"\n%Red: \n" + AsPercent(red/all),
if open > close then Color.RED else color.gray, yes);

def redtoday = highestall(if GetDay() == GetLastDay() then red else Double.NaN);
def alltoday = if secondsfromTime(1600)<0 then all else highestall(all);

"Today: " + asprice(getyyyYMMDD()) +
" | Red: " + redtoday +
" | RTH: " + alltoday+
" | %Red: " + AsPercent(redtoday/alltoday),
if secondsfromTime(1600)<0 and open < close then color.gray else Color.RED);``````

This might help with bubbles to track the accumlation of red candles during the day and a label option.
Thank you and will use it .!!

This might help with bubbles to track the accumlation of red candles during the day and a label option.
This code works. But, If I use it on 5D 2Min chart, the 5th day is good, but all other days shows the accumulation of prior days. Example; 3rd day begining has 5th and 4th day's count also. Could you please help? How to use this in watchlist also.

Thank you!!

Code:
``````# This logic is to find out the TOTAL number of RED candles and
# the RED candles DOWN ratio at 0.25, 0.5 and Greater than 0.5% / Candle during market is OPEN.

DECLARE LOWER;

DEF RP1 = 0;
DEF RP2 = 0;
DEF RP3 = 0;

DEF OC_RATIO = ROUND(((OPEN / CLOSE)-1)*100,2);

def red = if !(SecondsFromTime(0930) >= 0 and
SecondsTillTime(1600) > 0)
then 0 ELSE (
IF SecondsFromTime(0930) >= 0 and SecondsTillTime(1600) > 0 and OPEN <= CLOSE AND OC_RATIO <= 0.0 AND OC_RATIO < -0.25
THEN RED[1] + 1 AND RP1[1] + 1  AND RP3[1] AND RP2[1] ELSE
IF SecondsFromTime(0930) >= 0 and SecondsTillTime(1600) > 0 and OPEN <= CLOSE AND OC_RATIO <= -0.25 AND OC_RATIO < -0.5
THEN RED[1] + 1 AND RP2[1] + 1  AND RP3[1] AND RP1[1] ELSE
IF SecondsFromTime(0930) >= 0 and SecondsTillTime(1600) > 0 and OPEN <= CLOSE AND OC_RATIO <= -0.5
THEN RED[1] + 1 AND RP3[1] + 1  AND RP2[1] AND RP1[1] ELSE RED[1] AND RP3[1] AND RP2[1] AND RP1[1]);

ADDLABEL (YES, "TOTAL --> " + RED + "    RED01 --> " + RP1 + "    RED02 --> " + RP2 + "    RED03 --> " + RP3, COLOR.WHITE);``````

Last edited by a moderator:

Code:
``````# This logic is to find out the TOTAL number of RED candles and
# the RED candles DOWN ratio at 0.25, 0.5 and Greater than 0.5% / Candle during market is OPEN.

DECLARE LOWER;

DEF RP1 = 0;
DEF RP2 = 0;
DEF RP3 = 0;

DEF OC_RATIO = ROUND(((OPEN / CLOSE)-1)*100,2);

def red = if !(SecondsFromTime(0930) >= 0 and
SecondsTillTime(1600) > 0)
then 0 ELSE (
IF SecondsFromTime(0930) >= 0 and SecondsTillTime(1600) > 0 and OPEN <= CLOSE AND OC_RATIO <= 0.0 AND OC_RATIO < -0.25
THEN RED[1] + 1 AND RP1[1] + 1  AND RP3[1] AND RP2[1] ELSE
IF SecondsFromTime(0930) >= 0 and SecondsTillTime(1600) > 0 and OPEN <= CLOSE AND OC_RATIO <= -0.25 AND OC_RATIO < -0.5
THEN RED[1] + 1 AND RP2[1] + 1  AND RP3[1] AND RP1[1] ELSE
IF SecondsFromTime(0930) >= 0 and SecondsTillTime(1600) > 0 and OPEN <= CLOSE AND OC_RATIO <= -0.5
THEN RED[1] + 1 AND RP3[1] + 1  AND RP2[1] AND RP1[1] ELSE RED[1] AND RP3[1] AND RP2[1] AND RP1[1]);

ADDLABEL (YES, "TOTAL --> " + RED + "    RED01 --> " + RP1 + "    RED02 --> " + RP2 + "    RED03 --> " + RP3, COLOR.WHITE);``````

Thank you all!! I kind of fixed his with some compromise. Thank you again!!

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