# Dot at close of every Xth candle

#### Tsw85

##### New member
Good Day!

I use a ten minute chart and would like to paint a black dot at the close of every hour. Is anyone able to create a simple thinkscript that can paint a dot every 6th candle?

Solution
You could do something along these lines:
Code:
``````declare upper;
def time = GetTime();
plot data = if time % 3600000 == 0 then close else double.nan;
data.SetPaintingStrategy(PaintingStrategy.POINTS);
data.SetLineWeight(5);``````

What we do is use the getTime function, which returns milliseconds since a point in time during 1970 I think. Then we take that modulo (EDIT: ToS calls this "remainder") 3,600,000 which is the number of milliseconds in an hour (1 x 60 x 60 x 1000). If that is 0, then we know the current time is exactly the top of the hour, so we assign the CLOSE price to our series and if it isn't zero, we put a NaN in the series. That way it works on whatever timeframe you want, too. Finally we set the paintingStrategy to points so...
You could do something along these lines:
Code:
``````declare upper;
def time = GetTime();
plot data = if time % 3600000 == 0 then close else double.nan;
data.SetPaintingStrategy(PaintingStrategy.POINTS);
data.SetLineWeight(5);``````

What we do is use the getTime function, which returns milliseconds since a point in time during 1970 I think. Then we take that modulo (EDIT: ToS calls this "remainder") 3,600,000 which is the number of milliseconds in an hour (1 x 60 x 60 x 1000). If that is 0, then we know the current time is exactly the top of the hour, so we assign the CLOSE price to our series and if it isn't zero, we put a NaN in the series. That way it works on whatever timeframe you want, too. Finally we set the paintingStrategy to points so you get a dot, and then set the lineweight to 5 (maximum value) to make the dot big enough to see.

Hope that helps,
mashume

EDIT 2:
if you really want to do something with a dot every n bars, you'd do it this way:
Code:
``````declare upper;
input n = 6;
def b = barnumber();
plot data = if b % n == 0 then close else double.nan;
data.SetPaintingStrategy(PaintingStrategy.POINTS);
data.SetLineWeight(5);``````

Last edited:
You could do something along these lines:
Code:
``````declare upper;
def time = GetTime();
plot data = if time % 3600000 == 0 then close else double.nan;
data.SetPaintingStrategy(PaintingStrategy.POINTS);
data.SetLineWeight(5);``````

What we do is use the getTime function, which returns milliseconds since a point in time during 1970 I think. Then we take that modulo (EDIT: ToS calls this "remainder") 3,600,000 which is the number of milliseconds in an hour (1 x 60 x 60 x 1000). If that is 0, then we know the current time is exactly the top of the hour, so we assign the CLOSE price to our series and if it isn't zero, we put a NaN in the series. That way it works on whatever timeframe you want, too. Finally we set the paintingStrategy to points so you get a dot, and then set the lineweight to 5 (maximum value) to make the dot big enough to see.

Hope that helps,
mashume

EDIT 2:
if you really want to do something with a dot every n bars, you'd do it this way:
Code:
``````declare upper;
input n = 6;
def b = barnumber();
plot data = if b % n == 0 then close else double.nan;
data.SetPaintingStrategy(PaintingStrategy.POINTS);
data.SetLineWeight(5);``````

@mashume This is brilliant, thank you. However, both scripts are painting the dot on the hourly open candle. How can I displace this one candle earlier? Thanks for your time!

@mashume This is brilliant, thank you. However, both scripts are painting the dot on the hourly open candle. How can I displace this one candle earlier? Thanks for your time!

@mashume I changed the 0 to 3000000 and this aligned it to the hourly close on a 10 min chart. Thank you for your brilliant thinkscript.

perhaps, though I haven't tested it, you might replace time with time[-1] thusly:
Code:
``plot data = if time[-1] % 3600000 == 0 then close else double.nan;``
That references the next candle. Might work.

mashume

perhaps, though I haven't tested it, you might replace time with time[-1] thusly:
Code:
``plot data = if time[-1] % 3600000 == 0 then close else double.nan;``
That references the next candle. Might work.

mashume
@mashume is there anyway to plot a line across the whole chart after the close of x bars. so plot a line at the close of lets say every 30 mins or 70 mins, what im trying to do is see the close on different time frames across the whole chart. and i want to use ireggular times like 3 mins and 6 inutes and so on.. thank you so much in advance

you can try using this function:
Code:
``data.EnableApproximation();``
and see if that does the trick for you. Not sure it will thoughj

-mashume

you can try using this function:
Code:
``data.EnableApproximation();``
and see if that does the trick for you. Not sure it will thoughj

-mashume
Thank you mashume. I have bot tried it yet but you are always really responsive, I appreciate that. I have some ideas I want to share with you. Look for me on Twitter German brito. Lets chat

German brito
Tried to find you on twitter. Funny how common that one seems to be. You can find me as @mashume on Twitter or Trade__Genius (double underline) on reddit or even mashume#5047 on Discord.

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