# 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);
#
# 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);
#
# 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);
#
Join useThinkScript to post your question to a community of 21,000+ developers and traders.
@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!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); #
Thread starter | Similar threads | Forum | Replies | Date |
---|---|---|---|---|
Repaints Idea for Momentum Indicator (ASMA) | Questions | 8 | ||
Any Idea how to programmatically simplify this down? | Questions | 2 | ||
S | A general scan for success Idea | Questions | 3 | |
O | vix tool (idea) | Questions | 13 | |
M | Count number of active RSI chart bubbles and create alert | Questions | 6 |
Start a new thread and receive assistance from our community.
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.
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.