when asking questions to strangers, assume they don't know what you are talking about, and describe the issue thoroughly.
some people can look at the code, and make some guesses, but they shouldn't have to.
you wrote 6 words describing it, which leaves us guessing at what you really want.
. plot top and bottom 25% range,
plot what? lines? , arrows?
plot where ?
25% range of what ?
-----------------------
when an agg time is used in a formula, it over rules individual bar data.
this RPR formula uses the price value only from the first bar of each day, and draws a horizontal line for each day.
it doesn't use price from each bar.
def RPR = (Round((price – low(period = AggregationPeriod.DAY)) / (high(period = AggregationPeriod.DAY) – low(period = AggregationPeriod.DAY)) * 100))/4;
sometimes this works, sometimes it doesn't.
separate the agg values , then reference their variables in another formula, it will read price from each bar.
input price = close;
def lo = low(period = AggregationPeriod.DAY);
def hi = high(period = AggregationPeriod.DAY);
def RPR = (Round((price – lo) / (hi – lo) * 100))/4;
i ended up writing fold loops to find the highest and lowest for each day.
-----------------------
my guess at something you want
this draws lines at the % levels , 25 and 75.
if close is higher than highest or lower than lowest, then it draws a dot
Code:
#topbot25_dayrng
#https://usethinkscript.com/threads/plot-top-and-bottom-25-range.18049/
#Plot Top and Bottom 25% Range
#PAYtience 2/24
#I want to plot top and bottom 25% range, if someone can help me with the code.
def na = double.nan;
def d = getday();
def n = 800;
def big = 99999;
# run a loop on 1st bar of day, to find highest and lowest
def hi;
def lo;
if d != d[1] then {
hi = fold e1 = 0 to n
with p1 = 0
while d == getvalue(d, -e1)
do max(p1, getvalue(high, -e1));
lo = fold e2 = 0 to n
with p2 = big
while d == getvalue(d, -e2)
do min(p2, getvalue(low, -e2));
} else {
hi = hi[1];
lo = lo[1];
}
input show_daily_high_low_lines = no;
plot zhi = if show_daily_high_low_lines then hi else na;
plot zlo = if show_daily_high_low_lines then lo else na;
zhi.setdefaultcolor(color.light_gray);
zlo.setdefaultcolor(color.light_gray);
zhi.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zlo.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
input range_percent = 25.0;
def hiperlevel = (hi - (range_percent/100 * (hi-lo)));
def loperlevel = (lo + (range_percent/100 * (hi-lo)));
input show_percent_lines = yes;
plot phi = if show_percent_lines then hiperlevel else na;
plot plo = if show_percent_lines then loperlevel else na;
phi.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
plo.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
phi.setdefaultcolor(color.white);
plo.setdefaultcolor(color.white);
phi.SetStyle(Curve.short_DASH);
plo.SetStyle(Curve.short_DASH);
input price = close;
def hix = if price >= hiperlevel then hi else 0;
plot zhix = if hix > 0 then hix else na;
zhix.SetPaintingStrategy(PaintingStrategy.POINTS);
zhix.SetDefaultColor(Color.green);
zhix.setlineweight(4);
zhix.hidebubble();
plot lox = if price <= loperlevel then lo else na;
lox.SetPaintingStrategy(PaintingStrategy.POINTS);
lox.SetDefaultColor(Color.red);
lox.setlineweight(4);
lox.hidebubble();
#-------------------------------
input test2_bub = no;
addchartbubble(test2_bub, low,
price + "\n" +
#hi + " hi\n" +
hiperlevel + "\n" +
loperlevel + "\n" +
#lo + " lo\n" +
#(hi – lo) + " diff\n" +
#((price – lo)/(hi – lo)*100) + " %\n" +
#rpr + " RPR\n"
hix + "\n" +
zhix + "\n" +
lox + "\n" +
(price >= hiperlevel)
, color.yellow, no);
#
dashed lines , at % levels , 25 and 75.
dots when close goes beyond a line
CVX 30min
when asking questions to strangers, assume they don't know what you are talking about, and describe the issue thoroughly.
some people can look at the code, and make some guesses, but they shouldn't have to.
you wrote 6 words describing it, which leaves us guessing at what you really want.
. plot top and bottom 25% range,
plot what? lines? , arrows?
plot where ?
25% range of what ?
-----------------------
when an agg time is used in a formula, it over rules individual bar data.
this RPR formula uses the price value only from the first bar of each day, and draws a horizontal line for each day.
it doesn't use price from each bar.
def RPR = (Round((price – low(period = AggregationPeriod.DAY)) / (high(period = AggregationPeriod.DAY) – low(period = AggregationPeriod.DAY)) * 100))/4;
sometimes this works, sometimes it doesn't.
separate the agg values , then reference their variables in another formula, it will read price from each bar.
input price = close;
def lo = low(period = AggregationPeriod.DAY);
def hi = high(period = AggregationPeriod.DAY);
def RPR = (Round((price – lo) / (hi – lo) * 100))/4;
i ended up writing fold loops to find the highest and lowest for each day.
-----------------------
my guess at something you want
this draws lines at the % levels , 25 and 75.
if close is higher than highest or lower than lowest, then it draws a dot
Code:
#topbot25_dayrng
#https://usethinkscript.com/threads/plot-top-and-bottom-25-range.18049/
#Plot Top and Bottom 25% Range
#PAYtience 2/24
#I want to plot top and bottom 25% range, if someone can help me with the code.
def na = double.nan;
def d = getday();
def n = 800;
def big = 99999;
# run a loop on 1st bar of day, to find highest and lowest
def hi;
def lo;
if d != d[1] then {
hi = fold e1 = 0 to n
with p1 = 0
while d == getvalue(d, -e1)
do max(p1, getvalue(high, -e1));
lo = fold e2 = 0 to n
with p2 = big
while d == getvalue(d, -e2)
do min(p2, getvalue(low, -e2));
} else {
hi = hi[1];
lo = lo[1];
}
input show_daily_high_low_lines = no;
plot zhi = if show_daily_high_low_lines then hi else na;
plot zlo = if show_daily_high_low_lines then lo else na;
zhi.setdefaultcolor(color.light_gray);
zlo.setdefaultcolor(color.light_gray);
zhi.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zlo.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
input range_percent = 25.0;
def hiperlevel = (hi - (range_percent/100 * (hi-lo)));
def loperlevel = (lo + (range_percent/100 * (hi-lo)));
input show_percent_lines = yes;
plot phi = if show_percent_lines then hiperlevel else na;
plot plo = if show_percent_lines then loperlevel else na;
phi.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
plo.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
phi.setdefaultcolor(color.white);
plo.setdefaultcolor(color.white);
phi.SetStyle(Curve.short_DASH);
plo.SetStyle(Curve.short_DASH);
input price = close;
def hix = if price >= hiperlevel then hi else 0;
plot zhix = if hix > 0 then hix else na;
zhix.SetPaintingStrategy(PaintingStrategy.POINTS);
zhix.SetDefaultColor(Color.green);
zhix.setlineweight(4);
zhix.hidebubble();
plot lox = if price <= loperlevel then lo else na;
lox.SetPaintingStrategy(PaintingStrategy.POINTS);
lox.SetDefaultColor(Color.red);
lox.setlineweight(4);
lox.hidebubble();
#-------------------------------
input test2_bub = no;
addchartbubble(test2_bub, low,
price + "\n" +
#hi + " hi\n" +
hiperlevel + "\n" +
loperlevel + "\n" +
#lo + " lo\n" +
#(hi – lo) + " diff\n" +
#((price – lo)/(hi – lo)*100) + " %\n" +
#rpr + " RPR\n"
hix + "\n" +
zhix + "\n" +
lox + "\n" +
(price >= hiperlevel)
, color.yellow, no);
#
dashed lines , at % levels , 25 and 75.
dots when close goes beyond a line
CVX 30min
I could not get the above script to plot the last day's range. So I found another fold script version of yours that seems to do it.
Trying to learn from you, especially on how to use fold. At 75, who knows if I have enough time! You do excellent work and help!
Code:
#topbot25_dayrng
#https://usethinkscript.com/threads/plot-top-and-bottom-25-range.18049/
#Plot Top and Bottom 25% Range
#PAYtience 2/24
#I want to plot top and bottom 25% range, if someone can help me with the code.
#Added a modification to fold to include today's range
def na = Double.NaN;
def bn = BarNumber();
input st1 = 1900;
def last1 = SecondsTillTime(st1)[1] < 0 and SecondsFromTime(st1) >= 0;
def day_last = last1;
def prev_cls = if day_last then close else prev_cls[1];
def n = 1000;
def big = 99999;
def hi;
def lo;
if bn == 1
then {
hi = na;
lo = na;
} else if day_last
then {
hi = fold e = 1 to n
with p
while !GetValue(last1, -e)
do Max(p, GetValue(high, -e));
lo = fold f = 1 to n
with q = big
while !GetValue(last1, -f)
do Min(q, GetValue(low, -f));
} else {
hi = hi[1];
lo = lo[1];
}
input show_daily_high_low_lines = yes;
plot zhi = if show_daily_high_low_lines then hi else na;
plot zlo = if show_daily_high_low_lines then lo else na;
zhi.setdefaultcolor(color.light_gray);
zlo.setdefaultcolor(color.light_gray);
zhi.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zlo.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
input range_percent = 25.0;
def hiperlevel = (hi - (range_percent/100 * (hi-lo)));
def loperlevel = (lo + (range_percent/100 * (hi-lo)));
input show_percent_lines = yes;
plot phi = if show_percent_lines then hiperlevel else na;
plot plo = if show_percent_lines then loperlevel else na;
phi.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
plo.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
phi.setdefaultcolor(color.white);
plo.setdefaultcolor(color.white);
phi.SetStyle(Curve.short_DASH);
plo.SetStyle(Curve.short_DASH);
input price = close;
def hix = if price >= hiperlevel then hi else 0;
plot zhix = if hix > 0 then hix else na;
zhix.SetPaintingStrategy(PaintingStrategy.POINTS);
zhix.SetDefaultColor(Color.green);
zhix.setlineweight(4);
zhix.hidebubble();
plot lox = if price <= loperlevel then lo else na;
lox.SetPaintingStrategy(PaintingStrategy.POINTS);
lox.SetDefaultColor(Color.red);
lox.setlineweight(4);
lox.hidebubble();
#-------------------------------
input test2_bub = no;
addchartbubble(test2_bub, low,
price + "\n" +
#hi + " hi\n" +
hiperlevel + "\n" +
loperlevel + "\n" +
#lo + " lo\n" +
#(hi – lo) + " diff\n" +
#((price – lo)/(hi – lo)*100) + " %\n" +
#rpr + " RPR\n"
hix + "\n" +
zhix + "\n" +
lox + "\n" +
(price >= hiperlevel)
, color.yellow, no);
#
I could not get the above script to plot the last day's range. So I found another fold script version of yours that seems to do it.
Trying to learn from you, especially on how to use fold. At 75, who knows if I have enough time! You do excellent work and help!
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.
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.