Paint specific candle in different color based on time of day

zeek

Active member
2019 Donor
I am wondering if it´s possible to paint a specific candle in a different color of choice based on the time of day? Let´s say i use i a 2min chart and i want to highlight the 9:52AM candle and then the same candle at the same time next hour so 10:52AM and so forth. Can this be coded somehow into a study where i can set the time & color myself?

See my example pic below

 
Solution
I am wondering if it´s possible to paint a specific candle in a different color of choice based on the time of day? Let´s say i use i a 2min chart and i want to highlight the 9:52AM candle and then the same candle at the same time next hour so 10:52AM and so forth. Can this be coded somehow into a study where i can set the time & color myself?

See my example pic below

This is set to paint a bar yellow every hour from the input begin. You can change the color at the input screen.

Capture.jpg
Ruby:
input begin   = 0952;
def bar       = if SecondsTillTime(begin) == 0 and
                   SecondsFromTime(begin) == 0
                then 0
                else bar[1] + 1;
input minutes = 60;
def barx_min  = bar %...
I am wondering if it´s possible to paint a specific candle in a different color of choice based on the time of day? Let´s say i use i a 2min chart and i want to highlight the 9:52AM candle and then the same candle at the same time next hour so 10:52AM and so forth. Can this be coded somehow into a study where i can set the time & color myself?

See my example pic below

This is set to paint a bar yellow every hour from the input begin. You can change the color at the input screen.

Capture.jpg
Ruby:
input begin   = 0952;
def bar       = if SecondsTillTime(begin) == 0 and
                   SecondsFromTime(begin) == 0
                then 0
                else bar[1] + 1;
input minutes = 60;
def barx_min  = bar % ((minutes) / (GetAggregationPeriod() / 60000)) == 0;
def barxct    = if barx_min then 1 else barxct[1] + 1;
DefineGlobalColor("Time", Color.YELLOW);
AssignPriceColor(if  barx_min then GlobalColor("Time") else Color.CURRENT);
 
Solution

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

This is set to paint a bar yellow every hour from the input begin. You can change the color at the input screen.
Thank you SleepyZ, really appreciate the help (y)

I tried it and it works perfectly but i noticed that on one stock that was halted at some point during the day, the following painted candle after unhalt will be lagging because it´s painting every 60 minutes and if there is a halt, typically 5 or 10 min will disappear on the chart and i am guessing that´s why the candle will be painted later than it is supposed to.

I was thinking instead of looping every 30 or 60 minutes, can you make the time input static for the first candle painted and then i can simply copy this line of code one step down for as many as i like to have?

Or if you have some other solution?
 
Thank you SleepyZ, really appreciate the help (y)

I tried it and it works perfectly but i noticed that on one stock that was halted at some point during the day, the following painted candle after unhalt will be lagging because it´s painting every 60 minutes and if there is a halt, typically 5 or 10 min will disappear on the chart and i am guessing that´s why the candle will be painted later than it is supposed to.

I was thinking instead of looping every 30 or 60 minutes, can you make the time input static for the first candle painted and then i can simply copy this line of code one step down for as many as i like to have?

Or if you have some other solution?

You could make a copy of the above script, rename it, and adjust that script's begin time to the new repeating begin time after the lag. Here is a script for just the first time so you can modify it as you like to add more times.

Ruby:
input begin   = 0952;
def firstbar  = secondsFromTime(begin)==0;
DefineGlobalColor("Time", Color.YELLOW);
AssignPriceColor(if firstbar then GlobalColor("Time") else Color.CURRENT);
 
Taking this script directly above this message what is the script to have it draw an arrow (or other TOS Style) at the bar instead of coloring the bar? Basically like the drop down menu for the UpSignal in the MovAvgExponential indicator. Thank you.
 
Taking this script directly above this message what is the script to have it draw an arrow (or other TOS Style) at the bar instead of coloring the bar? Basically like the drop down menu for the UpSignal in the MovAvgExponential indicator. Thank you.

Capture.jpg
Ruby:
input begin   = 0952;
plot firstbar = secondsFromTime(begin)==0;
DefineGlobalColor("Time", Color.YELLOW);
AssignPriceColor(if firstbar then GlobalColor("Time") else Color.CURRENT);
firstbar.setpaintingStrategy(paintingStrategy.BOOLEAN_ARROW_UP);
firstbar.setlineWeight(5);
 
Wow! Is there a way to draw a price level line at the close of the highlighted candle instead of an arrow?

Sure,

Capture.jpg
Ruby:
input begin     = 0952;
input arrowsize = 5;
plot firstbar   = secondsFromTime(begin)==0;
DefineGlobalColor("Time", Color.YELLOW);
AssignPriceColor(if firstbar then GlobalColor("Time") else Color.CURRENT);
firstbar.setpaintingStrategy(paintingStrategy.BOOLEAN_ARROW_UP);
firstbar.setlineWeight(arrowsize);

input linewidth = 3;
def cline       = if firstbar then close else cline[1];
plot closebar   = cline;
closebar.setpaintingStrategy(paintingStrategy.HORIZONTAL);
closebar.setdefaultColor(globalColor("Time"));
closebar.setlineWeight(linewidth);
 
Love the indicator. I'm trying to get it just show the Boolean arrow for specific times throughout the day. I'm finding my self adding the indicator in about 10 times then changing the time for each with its own values. It would be nice to have it all in one indicator for tidiness. Is it possible to indicate many other times throughout the day and place an arrow with the desired color.
 
Instead of arrows as well it would be great if I could also just add a number value to the top instead. For instance on the 5 minute chart there are 78 bar during Regular Trading hours. I would love the ability have the bar at 10:25 labeled with a 12 above or below and change the color of that value that is posted.
 
Instead of arrows as well it would be great if I could also just add a number value to the top instead. For instance on the 5 minute chart there are 78 bar during Regular Trading hours. I would love the ability have the bar at 10:25 labeled with a 12 above or below and change the color of that value that is posted.

Due to the various plots (line, arrow and value), it is probably easiest to add multiple copies as you are doing.

Here is a revised script without the price color, but with a value above the bar during RTHrs.

Ruby:
input begin     = 1025;
input arrowsize = 5;
plot firstbar   = secondsFromTime(begin)==0;
def count       = if gettime() crosses above regularTradingstart(getyyyYMMDD())
                  then 1
                  else if !firstbar
                  then count[1] + 1
                  else count[1];
                
DefineGlobalColor("Time", Color.YELLOW);
firstbar.setpaintingStrategy(paintingStrategy.BOOLEAN_ARROW_UP);
firstbar.setlineWeight(arrowsize);
firstbar.setdefaultColor(globalColor("Time"));
plot xcount     = if firstbar then count + 1 else double.nan;
xcount.setpaintingStrategy(paintingStrategy.VALUES_ABOVE);
xcount.setdefaultColor(globalColor("Time"));

input linewidth = 3;
def cline       = if firstbar then close else cline[1];
plot closebar   = cline;
closebar.setpaintingStrategy(paintingStrategy.HORIZONTAL);
closebar.setdefaultColor(globalColor("Time"));
closebar.setlineWeight(linewidth);
 
This is what it looks like for me
That is because the code assumed you had extended hours displayed. Since you must not, then this should work

Ruby:
input begin     = 1025;
input arrowsize = 5;
plot firstbar   = secondsFromTime(begin)==0;
def count       = if secondsfromTime(0930)==0
                  then 1
                  else if !firstbar
                  then count[1] + 1
                  else count[1];
                
DefineGlobalColor("Time", Color.YELLOW);
firstbar.setpaintingStrategy(paintingStrategy.BOOLEAN_ARROW_UP);
firstbar.setlineWeight(arrowsize);
firstbar.setdefaultColor(globalColor("Time"));
plot xcount     = if firstbar then count + 1 else double.nan;
xcount.setpaintingStrategy(paintingStrategy.VALUES_ABOVE);
xcount.setdefaultColor(globalColor("Time"));

input linewidth = 3;
def cline       = if firstbar then close else cline[1];
plot closebar   = cline;
closebar.setpaintingStrategy(paintingStrategy.HORIZONTAL);
closebar.setdefaultColor(globalColor("Time"));
closebar.setlineWeight(linewidth);
 
Thank you all for the outstanding work with this indicator. It has really expedited my drawing support and resistance lines. I guess the only way it could be any faster is if there was a way to only highlight candles that close within + or - 2 points of a price that I input.
 
Hey man awesome script. How could you make the horizontal line end at a specific time? Thanks for your time!

Added an input endtime to limit the plot of closebar line.

Capture.jpg
Ruby:
input begin     = 1025;
input arrowsize = 5;
plot firstbar   = secondsFromTime(begin)==0;
def count       = if secondsfromTime(0930)==0
                  then 1
                  else if !firstbar
                  then count[1] + 1
                  else count[1];
                
DefineGlobalColor("Time", Color.YELLOW);
firstbar.setpaintingStrategy(paintingStrategy.BOOLEAN_ARROW_UP);
firstbar.setlineWeight(arrowsize);
firstbar.setdefaultColor(globalColor("Time"));
plot xcount     = if firstbar then count + 1 else double.nan;
xcount.setpaintingStrategy(paintingStrategy.VALUES_ABOVE);
xcount.setdefaultColor(globalColor("Time"));

input linewidth = 3;
input endtime   = 1205;
def cline       = if firstbar then close else cline[1];
plot closebar   = if secondsfromtime(begin) >= 0 and secondsfromtime(endtime) <= 0
                  then cline
                  else double.nan;
closebar.setpaintingStrategy(paintingStrategy.HORIZONTAL);
closebar.setdefaultColor(globalColor("Time"));
closebar.setlineWeight(linewidth);
 
This is exactly what I was looking for. Is there a way to get this to work for futures with extended hours displayed? I'd like to highlight the 6am candles on a 4H chart but this won't do that.
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
247 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

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?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top