Any idea how to create a scan for round numbers?

LouChez

New member
Hey guys,

Trying to create a scan that will return stocks within X cents of a whole number.
For example: GE trading at $7.20 and I want it to trigger when GE hits $7.05

Any ides on creating something like this?

Thanks!
 
i was looking around the site and found this post. thought someone might find this useful, so i made these.

the rules i followed for these studies.

specify a price multiple: 0.50, 1.00, 2.50,...
find the price multiple closest to the close

specify a price range: 0.05 , 0.25,....
check if the close is within the price range of the price multiple

i didn't test the lower study as a scan

Chart:
i made a chart study first, so i can see what is happening, to verify the code is working.
in this and the others, 2 numbers are entered
input price_multiple = 0.50;
input price_range = 0.05;

a line is drawn for the price multiple level.
a chart bubble is drawn that displays the price difference of the close to the price multiple.
the bubble is colored based on
if close is within the range of the price multiple, then green
if close crosses above the multiple then cyan
if close crosses below the multiple then yellow
else gray

Ruby:
# roundtomultiple_01
# chart

# --------------
# halcyonguy
# 2021-06-19
# find prices within $x of a price multiple

# specify a price multiple:  0.50, 1.00, 2.50,...
#   find the price multiple closest to price
# specify a tolerance price range:  0.05 , 0.25,....
#   check if price is within the rng of price multiple

# https://usethinkscript.com/threads/any-idea-how-to-create-a-scan-for-round-numbers.2160/
# 2020/04  louchez 
#Trying to create a scan that will return stocks within X cents of a whole number.
#For example: GE trading at $7.20 and I want it to trigger when GE hits $7.05


#  multiple can be 0.10 to $10
input price_multiple = 0.50;
input price_range = 0.05;
def cls = close;

# round price by the multiple
def x = cls / price_multiple;
def x2 = floor(x);

#def x3 = cls / price_multiple;

def x4 = round( x, 0);
def rnd_price = x4 * price_multiple;

# test if price is with x% of rounded price
def diff = round(cls - rnd_price,2);
def price_in_rng = absvalue(diff) <= price_range;

def price_cross_below_multiple = ( cls crosses below rnd_price);
def price_cross_above_multiple = ( cls crosses above rnd_price);

addlabel(1, "price multiple " + AsDollars(price_multiple), color.yellow);
addlabel(1, "price range " + AsDollars(price_range) , color.yellow);

addlabel(1, " in range " +  diff,
 ( if price_in_rng then color.green else
   if price_cross_above_multiple then color.cyan else
   if price_cross_below_multiple then color.yellow else
      color.gray) );

# draw ref lines on a chart
plot z = rnd_price;
z.setdefaultcolor(color.yellow);

input show_test_values = yes;
addchartbubble( show_test_values, high, diff,
( if price_in_rng then color.green else
  if price_cross_above_multiple then color.cyan else
  if price_cross_below_multiple then color.yellow else
     color.gray), yes);
#


Column:
copy the chart study and change so it shows the price difference of the close to the price multiple and has a colored background
disable the plots, labels, bubbles

rndmultiple_01
http://tos.mx/f9nkFST

Ruby:
# rndmultiple_01
# column , copy from chart study roundtomultiple_01

# --------------
# halcyonguy
# 2021-06-19
# find prices within $x of a price multiple

# specify a price multiple:  0.50, 1.00, 2.50,...
#   find the price multiple closest to price
# specify a tolerance price range:  0.05 , 0.25,....
#   check if price is within the rng of price multiple

# https://usethinkscript.com/threads/any-idea-how-to-create-a-scan-for-round-numbers.2160/
# 2020/04  louchez 
#Trying to create a scan that will return stocks within X cents of a whole number.
#For example: GE trading at $7.20 and I want it to trigger when GE hits $7.05


input price_multiple = 0.50;
input price_range = 0.05;

def cls = close;

# round price by the multiple
def x = cls / price_multiple;
def x2 = floor(x);

#def x3 = cls / price_multiple;

def x4 = round( x, 0);
def rnd_price = x4 * price_multiple;

# test if price is with x% of rounded price
def diff = round(cls - rnd_price, 2);
def price_in_rng = absvalue(diff) <= price_range;

def price_cross_below_multiple = ( cls crosses below rnd_price);
def price_cross_above_multiple = ( cls crosses above rnd_price);

#addlabel(1, "price multiple " + AsDollars(price_multiple), color.yellow);
#addlabel(1, "price range " + AsDollars(price_range) , color.yellow);

addlabel(1, diff + " $diff", color.black);

assignbackgroundcolor( ( if price_in_rng then color.green else
   if price_cross_above_multiple then color.cyan else
   if price_cross_below_multiple then color.yellow else
      color.gray));



# draw ref lines on a chart
#plot z = rnd_price;
#z.setdefaultcolor(color.yellow);

#input show_test_values = yes;
#addchartbubble( show_test_values, high, diff,
#( if price_in_rng then color.green else
#  if price_cross_above_multiple then color.cyan else
#  if price_cross_below_multiple then color.yellow else
#     color.gray), yes);
#

lower/scan:
check if the close is within the price range of the price multiple
if so, then plot a 1
disable the other plots, labels, bubbles

Ruby:
# rndmultiple_01_lower
# lower / scan , copy from column study rndmultiple_01

# --------------
# halcyonguy
# 2021-06-19
# find prices within $x of a price multiple

# specify a price multiple:  0.50, 1.00, 2.50,...
#   find the price multiple closest to price
# specify a tolerance price range:  0.05 , 0.25,....
#   check if price is within the rng of price multiple

# lower / scan
# plot a 1 if price is within the price range of the price multiple

# https://usethinkscript.com/threads/any-idea-how-to-create-a-scan-for-round-numbers.2160/
# 2020/04  louchez 
#Trying to create a scan that will return stocks within X cents of a whole number.
#For example: GE trading at $7.20 and I want it to trigger when GE hits $7.05

declare lower;

input price_multiple = 0.50;
input price_range = 0.05;

def cls = close;

# round price by the multiple
def x = cls / price_multiple;
def x2 = floor(x);

#def x3 = cls / price_multiple;

def x4 = round( x, 0);
def rnd_price = x4 * price_multiple;

# test if price is with x% of rounded price
def diff = round(cls - rnd_price, 2);
def price_in_rng = absvalue(diff) <= price_range;

plot z = price_in_rng;

#def price_cross_below_multiple = ( cls crosses below rnd_price);
#def price_cross_above_multiple = ( cls crosses above rnd_price);

#addlabel(1, "price multiple " + AsDollars(price_multiple), color.yellow);
#addlabel(1, "price range " + AsDollars(price_range) , color.yellow);

#addlabel(1, diff + " $diff",
# ( if price_in_rng then color.green else
#   if price_cross_above_multiple then color.cyan else
#   if price_cross_below_multiple then color.yellow else
#      color.gray) );

# draw ref lines on a chart
#plot z = rnd_price;
#z.setdefaultcolor(color.yellow);

#input show_test_values = yes;
#addchartbubble( show_test_values, high, diff,
#( if price_in_rng then color.green else
#  if price_cross_above_multiple then color.cyan else
#  if price_cross_below_multiple then color.yellow else
#     color.gray), yes);
#
 
i was looking around the site and found this post. thought someone might find this useful, so i made these.

the rules i followed for these studies.

specify a price multiple: 0.50, 1.00, 2.50,...
find the price multiple closest to the close

specify a price range: 0.05 , 0.25,....
check if the close is within the price range of the price multiple

i didn't test the lower study as a scan

Chart:
i made a chart study first, so i can see what is happening, to verify the code is working.
in this and the others, 2 numbers are entered
input price_multiple = 0.50;
input price_range = 0.05;

a line is drawn for the price multiple level.
a chart bubble is drawn that displays the price difference of the close to the price multiple.
the bubble is colored based on
if close is within the range of the price multiple, then green
if close crosses above the multiple then cyan
if close crosses below the multiple then yellow
else gray

Ruby:
# roundtomultiple_01
# chart

# --------------
# halcyonguy
# 2021-06-19
# find prices within $x of a price multiple

# specify a price multiple:  0.50, 1.00, 2.50,...
#   find the price multiple closest to price
# specify a tolerance price range:  0.05 , 0.25,....
#   check if price is within the rng of price multiple

# https://usethinkscript.com/threads/any-idea-how-to-create-a-scan-for-round-numbers.2160/
# 2020/04  louchez
#Trying to create a scan that will return stocks within X cents of a whole number.
#For example: GE trading at $7.20 and I want it to trigger when GE hits $7.05


#  multiple can be 0.10 to $10
input price_multiple = 0.50;
input price_range = 0.05;
def cls = close;

# round price by the multiple
def x = cls / price_multiple;
def x2 = floor(x);

#def x3 = cls / price_multiple;

def x4 = round( x, 0);
def rnd_price = x4 * price_multiple;

# test if price is with x% of rounded price
def diff = round(cls - rnd_price,2);
def price_in_rng = absvalue(diff) <= price_range;

def price_cross_below_multiple = ( cls crosses below rnd_price);
def price_cross_above_multiple = ( cls crosses above rnd_price);

addlabel(1, "price multiple " + AsDollars(price_multiple), color.yellow);
addlabel(1, "price range " + AsDollars(price_range) , color.yellow);

addlabel(1, " in range " +  diff,
 ( if price_in_rng then color.green else
   if price_cross_above_multiple then color.cyan else
   if price_cross_below_multiple then color.yellow else
      color.gray) );

# draw ref lines on a chart
plot z = rnd_price;
z.setdefaultcolor(color.yellow);

input show_test_values = yes;
addchartbubble( show_test_values, high, diff,
( if price_in_rng then color.green else
  if price_cross_above_multiple then color.cyan else
  if price_cross_below_multiple then color.yellow else
     color.gray), yes);
#


Column:
copy the chart study and change so it shows the price difference of the close to the price multiple and has a colored background
disable the plots, labels, bubbles

rndmultiple_01
http://tos.mx/f9nkFST

Ruby:
# rndmultiple_01
# column , copy from chart study roundtomultiple_01

# --------------
# halcyonguy
# 2021-06-19
# find prices within $x of a price multiple

# specify a price multiple:  0.50, 1.00, 2.50,...
#   find the price multiple closest to price
# specify a tolerance price range:  0.05 , 0.25,....
#   check if price is within the rng of price multiple

# https://usethinkscript.com/threads/any-idea-how-to-create-a-scan-for-round-numbers.2160/
# 2020/04  louchez
#Trying to create a scan that will return stocks within X cents of a whole number.
#For example: GE trading at $7.20 and I want it to trigger when GE hits $7.05


input price_multiple = 0.50;
input price_range = 0.05;

def cls = close;

# round price by the multiple
def x = cls / price_multiple;
def x2 = floor(x);

#def x3 = cls / price_multiple;

def x4 = round( x, 0);
def rnd_price = x4 * price_multiple;

# test if price is with x% of rounded price
def diff = round(cls - rnd_price, 2);
def price_in_rng = absvalue(diff) <= price_range;

def price_cross_below_multiple = ( cls crosses below rnd_price);
def price_cross_above_multiple = ( cls crosses above rnd_price);

#addlabel(1, "price multiple " + AsDollars(price_multiple), color.yellow);
#addlabel(1, "price range " + AsDollars(price_range) , color.yellow);

addlabel(1, diff + " $diff", color.black);

assignbackgroundcolor( ( if price_in_rng then color.green else
   if price_cross_above_multiple then color.cyan else
   if price_cross_below_multiple then color.yellow else
      color.gray));



# draw ref lines on a chart
#plot z = rnd_price;
#z.setdefaultcolor(color.yellow);

#input show_test_values = yes;
#addchartbubble( show_test_values, high, diff,
#( if price_in_rng then color.green else
#  if price_cross_above_multiple then color.cyan else
#  if price_cross_below_multiple then color.yellow else
#     color.gray), yes);
#

lower/scan:
check if the close is within the price range of the price multiple
if so, then plot a 1
disable the other plots, labels, bubbles

Ruby:
# rndmultiple_01_lower
# lower / scan , copy from column study rndmultiple_01

# --------------
# halcyonguy
# 2021-06-19
# find prices within $x of a price multiple

# specify a price multiple:  0.50, 1.00, 2.50,...
#   find the price multiple closest to price
# specify a tolerance price range:  0.05 , 0.25,....
#   check if price is within the rng of price multiple

# lower / scan
# plot a 1 if price is within the price range of the price multiple

# https://usethinkscript.com/threads/any-idea-how-to-create-a-scan-for-round-numbers.2160/
# 2020/04  louchez
#Trying to create a scan that will return stocks within X cents of a whole number.
#For example: GE trading at $7.20 and I want it to trigger when GE hits $7.05

declare lower;

input price_multiple = 0.50;
input price_range = 0.05;

def cls = close;

# round price by the multiple
def x = cls / price_multiple;
def x2 = floor(x);

#def x3 = cls / price_multiple;

def x4 = round( x, 0);
def rnd_price = x4 * price_multiple;

# test if price is with x% of rounded price
def diff = round(cls - rnd_price, 2);
def price_in_rng = absvalue(diff) <= price_range;

plot z = price_in_rng;

#def price_cross_below_multiple = ( cls crosses below rnd_price);
#def price_cross_above_multiple = ( cls crosses above rnd_price);

#addlabel(1, "price multiple " + AsDollars(price_multiple), color.yellow);
#addlabel(1, "price range " + AsDollars(price_range) , color.yellow);

#addlabel(1, diff + " $diff",
# ( if price_in_rng then color.green else
#   if price_cross_above_multiple then color.cyan else
#   if price_cross_below_multiple then color.yellow else
#      color.gray) );

# draw ref lines on a chart
#plot z = rnd_price;
#z.setdefaultcolor(color.yellow);

#input show_test_values = yes;
#addchartbubble( show_test_values, high, diff,
#( if price_in_rng then color.green else
#  if price_cross_above_multiple then color.cyan else
#  if price_cross_below_multiple then color.yellow else
#     color.gray), yes);
#
@halcyonguy this is pretty cool but I'm having trouble isolating the scan code for just those that cross above or below the given interval say 5 or 10 for example. Any help would be much appreciated! Thanks!
 

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
295 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