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!
 

halcyonguy

Active member
VIP
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);
#
 

Similar threads

Top