Can someone please write a script for a condition where n variable offset's high crosses above Bollinger Band's upperband and all bars' highs and lows afterwards have stayed inside the range of n offset's high and low. To reiterate, I want a stock whose high has crossed above BB upperband in the past and the price never dropped below that particular bar's low and never crossed above high of the same bar that crossed above BB upperband.
Can someone please write a script for a condition where n variable offset's high crosses above Bollinger Band's upperband and all bars' highs and lows afterwards have stayed inside the range of n offset's high and low. To reiterate, I want a stock whose high has crossed above BB upperband in the past and the price never dropped below that particular bar's low and never crossed above high of the same bar that crossed above BB upperband.
Can someone please write a script for a condition where n variable offset's high crosses above Bollinger Band's upperband and all bars' highs and lows afterwards have stayed inside the range of n offset's high and low. To reiterate, I want a stock whose high has crossed above BB upperband in the past and the price never dropped below that particular bar's low and never crossed above high of the same bar that crossed above BB upperband.
Can someone please write a script for a condition where n variable offset's high crosses above Bollinger Band's upperband and all bars' highs and lows afterwards have stayed inside the range of n offset's high and low. To reiterate, I want a stock whose high has crossed above BB upperband in the past and the price never dropped below that particular bar's low and never crossed above high of the same bar that crossed above BB upperband.
Can you help me out with scan codes for two conditions:
1) n off bar's low hit year low and all bars afterwards are inside bars,
2) n off bar's high hit 20-bar high and all bars afterwards did not move above n off bar's high and did not move below 20-bar low before n off bar.
@halcyonguy
This modified code is not giving me anything, can you see what I missed in the script to satisfy the second condition I mentioned above?
Code:
def bn = BarNumber();
def na = Double.NaN;
def o = open;
def h = high;
def l = low;
def c = close;
def up = close > open;
def dwn = close < open;
DefineGlobalColor("c1", Color.YELLOW);
# GlobalColor("c1")
#----------------------------
input length=20;
def periodhigh = high==highest(high,length);
def periodlow=lowest(low,length);
#----------------------------
#inside_bars
input minimum_inside_bars = 2;
input show_inside_count_bubbles = yes;
input show_inside_count_values_above = no;
input draw_a_box_around_inside_bar = yes;
input show_horizontal_lines = yes;
input show_inside_bars_within_larger_range = yes;
input candle_levels = {default "wick" , "body" };
def highx;
def lowx;
switch (candle_levels) {
case "wick":
highx = h;
lowx = l;
case "body":
highx = Max(o, c);
lowx = Min(o, c);
}
def loop1 = 100;
# count how many future bars are smaller than the current bar
def incnt1 = fold k = 1 to loop1
with p
while (highx >= GetValue(highx, -k) and periodlow <= GetValue(lowx, -k))
do p + 1;
def incnt2 = if incnt1 >= minimum_inside_bars then incnt1 else 0;
# count down the bars in the inside range , cnt+1 to 1
def incountdown = if bn == 1 then 0
else if incountdown[1] <= 1 and incnt2 > 0 then incnt2 + 1
else if incountdown[1] > 0 then (incountdown[1] - 1)
else 0;
def inside_periodhighandperiodlow = (periodhigh and incnt2 > 0 and up);
plot scan = inside_periodhighandperiodlow;
Thank you for your awesome code.
How would you modify it when a bar crosses down BB lowerband instead and inside bars thereafter?
I appreciate all your work. You're the best.
Can you help me out with scan codes for two conditions:
1) n off bar's low hit year low and all bars afterwards are inside bars,
2) n off bar's high hit 20-bar high and all bars afterwards did not move above n off bar's high and did not move below 20-bar low before n off bar.
@halcyonguy
This modified code is not giving me anything, can you see what I missed in the script to satisfy the second condition I mentioned above?
Code:
def bn = BarNumber();
def na = Double.NaN;
def o = open;
def h = high;
def l = low;
def c = close;
def up = close > open;
def dwn = close < open;
DefineGlobalColor("c1", Color.YELLOW);
# GlobalColor("c1")
#----------------------------
input length=20;
def periodhigh = high==highest(high,length);
def periodlow=lowest(low,length);
#----------------------------
#inside_bars
input minimum_inside_bars = 2;
input show_inside_count_bubbles = yes;
input show_inside_count_values_above = no;
input draw_a_box_around_inside_bar = yes;
input show_horizontal_lines = yes;
input show_inside_bars_within_larger_range = yes;
input candle_levels = {default "wick" , "body" };
def highx;
def lowx;
switch (candle_levels) {
case "wick":
highx = h;
lowx = l;
case "body":
highx = Max(o, c);
lowx = Min(o, c);
}
def loop1 = 100;
# count how many future bars are smaller than the current bar
def incnt1 = fold k = 1 to loop1
with p
while (highx >= GetValue(highx, -k) and periodlow <= GetValue(lowx, -k))
do p + 1;
def incnt2 = if incnt1 >= minimum_inside_bars then incnt1 else 0;
# count down the bars in the inside range , cnt+1 to 1
def incountdown = if bn == 1 then 0
else if incountdown[1] <= 1 and incnt2 > 0 then incnt2 + 1
else if incountdown[1] > 0 then (incountdown[1] - 1)
else 0;
def inside_periodhighandperiodlow = (periodhigh and incnt2 > 0 and up);
plot scan = inside_periodhighandperiodlow;
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.