# Nearest Price Level to the Open

#### rlohmeyer

##### Active member
Hi,

Just looking for coding to define the closest price level to the days open that is an integer divisible by 5.

Is this possible?

Thanks for any help.

Bob

Ruby:
``````# +------------------------------------------------------------+
# |              Example: Round to the nearest X               |
# |                        Robert Payne                        |
# |               https://funwiththinkscript.com               |
# +------------------------------------------------------------+
input nearest_x = 5;
def daily_open = open(period = AggregationPeriod.DAY);
def round_to_nearest_x = Round(daily_open / nearest_x, 0) * nearest_x;
plot data = round_to_nearest_x;
data.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);``````

Last edited:
@OBW Thank you so much. I will use this on a Auto Significant Grid Indicator.

Last edited:
i like post above is any chance you can adjust to see the line showing only for 1 day , THANKS

i like post above is any chance you can adjust to see the line showing only for 1 day , THANKS

this can choose to show a line,
only on current day
or every day

Code:
``````# price_near_day_open_01

# Nearest Price Level to the Open

#+------------------------------------------------------------+
# |              Example: Round to the nearest X               |
# |                        Robert Payne                        |
# |               https://funwiththinkscript.com               |
# +------------------------------------------------------------+
def na = double.nan;
input nearest_x = 5;
def daily_open = open(period = AggregationPeriod.DAY);
def round_to_nearest_x = Round(daily_open / nearest_x, 0) * nearest_x;

# is last day the current day
def istoday = if GetLastDay() == GetDay() then 1 else 0;
input show_only_today = yes;
def days_enable = if show_only_today then istoday else 1;

plot data = if days_enable then round_to_nearest_x else na;
data.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
data.SetDefaultColor(Color.yellow);
#``````

That's beautiful , that's what I want. THANK YOU VERY MUCH FOR YOUR HELP!!!!!

I need help to add (addchartbubble) on program with name"Nearest" below: Thank you

Code:
``````# price_near_day_open_01

# Nearest Price Level to the Open

#+------------------------------------------------------------+
# |              Example: Round to the nearest X               |
# |                        Robert Payne                        |
# |               [URL]https://funwiththinkscript.com[/URL]               |
# +------------------------------------------------------------+
def na = double.nan;
input nearest_x = 5;
def daily_open = open(period = AggregationPeriod.DAY);
def round_to_nearest_x = Round(daily_open / nearest_x, 0) * nearest_x;

# is last day the current day
def istoday = if GetLastDay() == GetDay() then 1 else 0;
input show_only_today = yes;
def days_enable = if show_only_today then istoday else 1;

plot data = if days_enable then round_to_nearest_x else na;
data.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
data.SetDefaultColor(Color.white);
#end``````

Last edited by a moderator:
I need help to add (addchartbubble) on program with name"Nearest" below: Thank you

# price_near_day_open_01

# Nearest Price Level to the Open

#+------------------------------------------------------------+
# | Example: Round to the nearest X |
# | Robert Payne |
# | https://funwiththinkscript.com |
# +------------------------------------------------------------+
def na = double.nan;
input nearest_x = 5;
def daily_open = open(period = AggregationPeriod.DAY);
def round_to_nearest_x = Round(daily_open / nearest_x, 0) * nearest_x;

# is last day the current day
def istoday = if GetLastDay() == GetDay() then 1 else 0;
input show_only_today = yes;
def days_enable = if show_only_today then istoday else 1;

plot data = if days_enable then round_to_nearest_x else na;
data.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
data.SetDefaultColor(Color.white);
#end

Add this to bottom of the script

Code:
``````input showbubble  = yes;
input bubblemover = 2;#Moves bubbles sideways by # of bars input
def b  = bubblemover;
def b1 = b + 1;
data[b],
"Nearest\n " + AsDollars(data[b]),
Color.WHITE);
#``````

I sorry to bother you again. Is that possible you can help me "addcharbubble" to the left hand side view, It's much easier for me to see (current is on right view). I got some other addchartbubble block it in front view.
Thank you so much again.

I sorry to bother you again. Is that possible you can help me "addcharbubble" to the left hand side view, It's much easier for me to see (current is on right view). I got some other addchartbubble block it in front view.
Thank you so much again.

There is not a left hand side area like the right hand side expansion area.

You can enter a negative number in the bubblemover input though to position the bubble to where you want it.

You may have to change the bubblemover as you change charts when using positioning to the left of the expansion area.

Thank you

Ruby:
``````# +------------------------------------------------------------+
# |              Example: Round to the nearest X               |
# |                        Robert Payne                        |
# |               https://funwiththinkscript.com               |
# +------------------------------------------------------------+
input nearest_x = 5;
def daily_open = open(period = AggregationPeriod.DAY);
def round_to_nearest_x = Round(daily_open / nearest_x, 0) * nearest_x;
plot data = round_to_nearest_x;
data.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);``````

View attachment 9657
This is what I've been looking for (minus the line). Not sure why I didn't thk of this myself. Thank you!

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