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?

Thanks for your time!
 
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:
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 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!
 
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
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
 

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

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
407 Online
Create Post

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