# bigrange_same_candle_01
# https://usethinkscript.com/threads/largest-price-range-in-set-number-of-days.6789/
input look_back_bars = 30;
input show_arrows = yes;
input show_big_range_values = yes;
def na = double.nan;
#def bn = barnumber();
def rng = (high - low);
def bigrng = highest(rng, look_back_bars);
addlabel(1, "recent big range " + round(bigrng,2), color.yellow);
plot z = if show_arrows then (bigrng == rng) else na;
z.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
z.AssignValueColor(color.yellow);
plot w = if (show_big_range_values and bigrng == rng) then rng else na;
w.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
w.AssignValueColor(color.yellow);
w.hidebubble();
I have been looking for a script that will do this so thank you for posting. Do you know why I would be getting an error message that says "Addlable is not allowed in this context"?subtract the low from the high, then use highest() to find the biggest value.
this study looks back at x bars, and find the 1 candle with the biggest difference between the high and low.
Code:# bigrange_same_candle_01 # https://usethinkscript.com/threads/largest-price-range-in-set-number-of-days.6789/ input look_back_bars = 30; input show_arrows = yes; input show_big_range_values = yes; def na = double.nan; #def bn = barnumber(); def rng = (high - low); def bigrng = highest(rng, look_back_bars); addlabel(1, "recent big range " + round(bigrng,2), color.yellow); plot z = if show_arrows then (bigrng == rng) else na; z.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP); z.AssignValueColor(color.yellow); plot w = if (show_big_range_values and bigrng == rng) then rng else na; w.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE); w.AssignValueColor(color.yellow); w.hidebubble();
I have been looking for a script that will do this so thank you for posting. Do you know why I would be getting an error message that says "Addlable is not allowed in this context"?
I am looking for an indicator that will show the largest price range for a set period on a stock. It would show a label on the screen. So if the largest price range for the last 30 is $10.00 it would show that value. Any ideas?
# bigrange_same_candle_02
def na = double.nan;
def bn = barnumber();
input look_type = { default back, forward, both };
input look_back_bars = 20;
input look_forward_bars = 20;
input show_big_range_arrows = yes;
input show_big_range_values = yes;
def rng = (high - low);
def bigrng_back = highest(rng, look_back_bars);
def lastBar = HighestAll(if IsNaN(close) then 0 else bn);
def offset = Min(look_forward_bars - 1, lastBar - bn);
def bigrng_forward = GetValue(highest(rng, look_forward_bars), -offset);
def bigrng;
def rtype;
switch (look_type) {
case back:
bigrng = bigrng_back;
rtype = -1;
case forward:
bigrng = bigrng_forward;
rtype = 1;
case both:
bigrng = if bigrng_back > bigrng_forward then bigrng_back else bigrng_forward;
rtype = 0;
}
def bigrng2 = if bn == 1 then 0 else if (bigrng == rng) then bigrng else bigrng2[1];
plot z = if show_big_range_arrows then (bigrng == rng) else na;
z.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
z.AssignValueColor(color.yellow);
plot w = if (show_big_range_values and bigrng == rng) then rng else na;
w.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
w.AssignValueColor(color.yellow);
w.hidebubble();
#--------------------------------------
addlabel( (rtype <> 1), "back bars " + look_back_bars , color.yellow);
addlabel( (rtype <> -1), "forward bars " + look_forward_bars , color.yellow);
addlabel(1, "recent big range " + round(bigrng2,2), color.yellow);
#--------------------------------------
# ref code
# https://usethinkscript.com/threads/zigzag-high-low-with-supply-demand-zones-for-thinkorswim.172/#post-7048
# post#10 robert
#def lastBar = HighestAll(if IsNaN(close) then 0 else bn);
#def offset = Min(length - 1, lastBar - bn);
#def swingLow = low < Lowest(low[1], length - 1) and low == GetValue(Lowest(low, length), -offset);
#
Hi to all!
I use on a daily chart a version of highest/lowest prices study taken from the initial "VWAP Anchored_v02" study and need your help with a few questions, please:
1
Input barnumber value is 30 in my case (less values do more noise), which works ok on the far left part of the chart, but not good within the latest 30 days. Fe on the screensave 2 grey boxes show values missed.
Do you have adjustment to fix it?
# peaks4_01
input n = 30;
input ticks = 2.0;
def bnOK = barNumber() > n;
def isHigher = fold i = 1 to n + 1
with p = 1
while p and !isnan(GetValue(high, -i))
do high > GetValue(high, -i);
def HH = if bnOK and isHigher
and high == Highest(high, n)
then high else Double.NaN;
addchartbubble(0, low*0.998,
ishigher + "\n" +
hh
, color.yellow, no);
def isLower = fold j = 1 to n + 1
with q = 1
while q and !isnan(GetValue(high, -j))
do low < GetValue(low, -j);
def LL = if bnOK and isLower
and low == Lowest(low, n)
then low else Double.NaN;
def PivH = if HH > 0 then HH else Double.NaN;
def PivL = if LL > 0 then LL else Double.NaN;
plot Up = !isNaN(PivL);
AddChartBubble(Up, low, low, Color.light_gray, no);
plot Dn = !isNaN(PivH);
AddChartBubble(Dn, high, high, Color.light_gray, yes);
#
this version will find peaks near the last bar.
your version 'missed' them because when the fold loop ran over bars after the last bar , it caused an error in ishigher.
i added a check to see if the folded bar was valid , to the while code lines
i don't know what you are asking for in question 2,
Hi halcyonguy,
Thanks a lot for the corrections, that is what i need.
Last question is less important, just thought if there was a chance to use figures only instead of figures in bubbles, but this is nothing. )
# ------------------------------
def na = double.nan;
plot upnum = if !isNaN(PivL) then low else na;
upnum.SetPaintingStrategy(PaintingStrategy.VALUES_below);
upnum.setdefaultcolor(color.white);
plot dnnum = if !isNaN(Pivh) then high else na;
dnnum.SetPaintingStrategy(PaintingStrategy.VALUES_above);
dnnum.setdefaultcolor(color.white);
Thank you so much for your reply. I went back in and copied it and it worked. I didn't create the new study correctly. It works great!!sorry, i don't know why. i just loaded the original on my screen and it works.
i copied the code above and pasted it into a new study, and it worked.
try coping the code again.
trying to think of what might cause it...
are you using a huge number for look back bars?
are you looking at a stock that just had an ipo?
are you looking at a chart with a big time fram, month, quarter...?
Hi Halcyonguy,aah, i get it.
you can use these plot parameters to put a number above or below a candle (but not text)
add this to end of my study
then comment out the bubble lines, by putting a # in front of them
Code:# ------------------------------ def na = double.nan; plot upnum = if !isNaN(PivL) then low else na; upnum.SetPaintingStrategy(PaintingStrategy.VALUES_below); upnum.setdefaultcolor(color.white); plot dnnum = if !isNaN(Pivh) then high else na; dnnum.SetPaintingStrategy(PaintingStrategy.VALUES_above); dnnum.setdefaultcolor(color.white);
input ArrDist = 0.2;
input LookBack = 20;
def BodyMax = Max(open, close);
def BodyMin = Min(open, close);
def RangeMax = high;
def RangeMin = low;
def Range = high - low;
def LRB = Highest(Range, LookBack);
def LRBHigh = GetValue(high, LRB, 0);
def LRBLow = GetValue(low, LRB, 0);
def Cover =
if Cover[1] == 0 then
if RangeMax >= LRBHigh then 1
else 0
else
if RangeMax <= GetValue(LRBHigh, Cover[1] + 1, 0)
then Cover[1] + 1
else 0;
def plotHigh = High + Range * ArrDist;
plot CoverSignal = if RangeMax >= LRBHigh then plotHigh else double.NaN;
CoverSignal.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
CoverSignal.SetDefaultColor(GetColor(5));
CoverSignal.SetLineWeight(2);
Hi Halcyonguy,
Thank for posting on the largest range bar (LRB)
I'm also looking into something related to that in that is today high higher than the LRB high?
This is my code but working sometimes only...
Code:input ArrDist = 0.2; input LookBack = 20; def BodyMax = Max(open, close); def BodyMin = Min(open, close); def RangeMax = high; def RangeMin = low; def Range = high - low; def LRB = Highest(Range, LookBack); def LRBHigh = GetValue(high, LRB, 0); def LRBLow = GetValue(low, LRB, 0); def Cover = if Cover[1] == 0 then if RangeMax >= LRBHigh then 1 else 0 else if RangeMax <= GetValue(LRBHigh, Cover[1] + 1, 0) then Cover[1] + 1 else 0; def plotHigh = High + Range * ArrDist; plot CoverSignal = if RangeMax >= LRBHigh then plotHigh else double.NaN; CoverSignal.SetPaintingStrategy(PaintingStrategy.TRIANGLES); CoverSignal.SetDefaultColor(GetColor(5)); CoverSignal.SetLineWeight(2);
Appreciate any feedback.
Thanks
Hi Halcyonguy,
Thanks for the speedy respond...
Was typing to u when I was up all night so yeah... forgot the link and the my question seem kind of incomplete...
The link is from this
https://usethinkscript.com/threads/largest-price-range-in-set-number-of-days.6789/#post-89459...
What I trying to do is
1. Find the largest range bar (LRB) 10 period back
2. Get the high of the largest range bar
3. Check if current high is higher than the largest range bar high
4. If yes, signal it either by an arrow or point...
5. I would like to use this to filter out stock that fit this condition...
Hope that clarify my question...
U know how it is... sometimes u go in a loop and keep digging in the wrong direction and making it complicated while actually there is a much simpler way...
I think maybe I'm on this route...
Appreciate all help to point me in the right direction...
Again, thanks a million for helping...
#1. Find the largest range bar (LRB) 10 period back
input len = 10;
def hi_rng_off = GetMaxValueOffset(( high - low), len);
#2. Get the high of the largest range bar
def hi_rng_hi = getvalue( high, hi_rng_off);
#3. Check if current high is higher than the largest range bar high
def ishi_higher = if ( high > hi_rng_hi) then 1 else 0;
#4. If yes, signal it either by an arrow or point...
plot z = if ishi_higher then low else double.nan;
z.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
z.SetDefaultColor(Color.green);
z.SetLineWeight(2);
#5. I would like to use this to filter out stock that fit this condition...
if this is to be used as a scan, delete the step #4 plot and use this.
plot z2 = ishi_higher;
Hi Halcyonguy,
I was trying to improve this code to auto the Lookback period in that when there is less than 20 bar available, Lookback period==5, else Lookback period==10 ...
I try both codes but doesn't seem to work ...
Def LookBack = if BarNumber() <20 then 5 else 10 ;
Def LookBack = if BarNumber() <=20 then LookBack==5 else LookBack==10 ;
Appreciates if anyone could shed some light on this ...
Thanks
Hi Halcyonguy,sorry about not replying to other post.
i'm bad about following up sometimes.
take a look at this .
look at offset = formula and how he uses it
https://usethinkscript.com/threads/...y-demand-zones-for-thinkorswim.172/#post-7048
Hi Halcyonguy,
No problem at all ... You have help in more way then u know, to me and to all the other here ...
And thank for taking the time to post some help for this ... really appreciates it...
input length = 10;
def LRB;
if barnumber() < 20 then {
LRB = Highest(Range, (length / 2));
} else {
LRB = Highest(Range, length );
}
Join useThinkScript to post your question to a community of 21,000+ developers and traders.
Thread starter | Similar threads | Forum | Replies | Date |
---|---|---|---|---|
B | largest gain/range since uptrend | Questions | 18 | |
price label | Questions | 2 | ||
N | Horizontal Line - Price as Text not Bubbles - Will BUBBLEMOVER work? | Questions | 0 | |
S | Help on Price crosses above prev day high study | Questions | 9 | |
E | Stock price on an options chart. | Questions | 2 |
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.