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);

X6t5wTP.png
 
Last edited:
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

# https://usethinkscript.com/threads/nearest-price-level-to-the-open.5757/
# 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);
#
 
I need help to add (addchartbubble) on program with name"Nearest" below: Thank you

Code:
# price_near_day_open_01

# [URL]https://usethinkscript.com/threads/nearest-price-level-to-the-open.5757/[/URL]
# 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

# https://usethinkscript.com/threads/nearest-price-level-to-the-open.5757/
# 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;
AddChartBubble(showbubble and IsNaN(close[b]) and !IsNaN(close[b1]),
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.
 
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!
 

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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