2 consecutive 10-bar frames (rectangles)

samhanoh

New member
VIP
I help to create a ThinkScript study that displays 2 consecutive 10-bar frames (rectangles) on the chart:

🔷 Logic:​

  1. The first frame should begin from the bar that contains the most recent highest high on the chart and span 10 bars backward from that point.
  2. The second frame should immediately follow the first one — i.e., it starts right after the end of the first frame and spans the next 10 bars.
  3. Each frame should show:
    • A gray or red background cloud between the highest high and lowest low of that frame
    • Optional top/bottom border lines
  4. Important: Once a new frame is formed (e.g., frame 2 begins), the previous one (frame 1) should be disabled or hidden — only one active frame should show at a time. see photo

The first frame should begin from the bar that contains the most recent highest high of last 15 bar
 

Attachments

  • ScreenHunter 864.jpg
    ScreenHunter 864.jpg
    22.8 KB · Views: 29
Last edited by a moderator:
Solution
I help to create a ThinkScript study that displays 2 consecutive 10-bar frames (rectangles) on the chart:

🔷 Logic:​

  1. The first frame should begin from the bar that contains the most recent highest high on the chart and span 10 bars backward from that point.
  2. The second frame should immediately follow the first one — i.e., it starts right after the end of the first frame and spans the next 10 bars.
  3. Each frame should show:
    • A gray or red background cloud between the highest high and lowest low of that frame
    • Optional top/bottom border lines
  4. Important: Once a new frame is formed (e.g., frame 2 begins), the previous one (frame 1) should be...
I help to create a ThinkScript study that displays 2 consecutive 10-bar frames (rectangles) on the chart:

🔷 Logic:​

  1. The first frame should begin from the bar that contains the most recent highest high on the chart and span 10 bars backward from that point.
  2. The second frame should immediately follow the first one — i.e., it starts right after the end of the first frame and spans the next 10 bars.
  3. Each frame should show:
    • A gray or red background cloud between the highest high and lowest low of that frame
    • Optional top/bottom border lines
  4. Important: Once a new frame is formed (e.g., frame 2 begins), the previous one (frame 1) should be disabled or hidden — only one active frame should show at a time. see photo

The first frame should begin from the bar that contains the most recent highest high of last 15 bar
you have conflicting rules, change them.

these are different. which rule do you want?
the most recent highest high on the chart
the most recent highest high of last 15 bar

get rid of the word frame. it has no meaning. say shaded rectangle
not sure what you are talking about. do you want to see 2 rectangles, but not more?
these say opposite things,
The second frame should immediately follow the first one
Once a new frame is formed (e.g., frame 2 begins), the previous one (frame 1) should be disabled or hidden
 
I help to create a ThinkScript study that displays 2 consecutive 10-bar frames (rectangles) on the chart:

🔷 Logic:​

  1. The first frame should begin from the bar that contains the most recent highest high on the chart and span 10 bars backward from that point.
  2. The second frame should immediately follow the first one — i.e., it starts right after the end of the first frame and spans the next 10 bars.
  3. Each frame should show:
    • A gray or red background cloud between the highest high and lowest low of that frame
    • Optional top/bottom border lines
  4. Important: Once a new frame is formed (e.g., frame 2 begins), the previous one (frame 1) should be disabled or hidden — only one active frame should show at a time. see photo

The first frame should begin from the bar that contains the most recent highest high of last 15 bar

this might be close to what you want
find last peak. looks at 7 bars before and after to find a peak
rectangles are 10 bars wide.
rect1 ends on a peak
rect2 starts on bar after rect1 last bar ( bar after peak)
find highest and lowest during rect1 bars
find highest and lowest of rect2 bars
rect2 lines and cloud may extend past last bar


Code:
#clouds_10bar_frames_peak
#https://usethinkscript.com/threads/2-consecutive-10-bar-frames-rectangles.21032/
#2 consecutive 10-bar frames (rectangles)
#-------------------------

def na = Double.NaN;
def bn = BarNumber();

#def lastBar = HighestAll(if IsNaN(close) then 0 else bn);
def lastbn = HighestAll(if IsNaN(close) then 0 else bn);
def lastbar = bn == lastbn;
#def lastbar = (!isnan(close) and isnan(close[-1]));
def big = 99999;

#https://usethinkscript.com/threads/zigzag-high-low-with-supply-demand-zones-for-thinkorswim.172/#post-7048
#  Robert Payne
# define peaks / valleys
def highx = high;
def lowx = low;
input peak_length = 7;

def offset = Min(peak_length - 1, lastbn - bn);
def peak = highx > Highest(highx[1], peak_length - 1) and highx == GetValue(Highest(highx, peak_length), -offset);
def valley = lowx < Lowest(lowx[1], peak_length - 1) and lowx == GetValue(Lowest(lowx, peak_length), -offset);

input show_peak_arrows = yes;
plot zhi = if show_peak_arrows and peak then high * 1.001 else na;
plot zlo = if show_peak_arrows and valley then low * 0.999 else na;
zlo.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
zlo.SetDefaultColor(Color.RED);
zlo.SetLineWeight(1);
zlo.HideBubble();
zhi.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
zhi.SetDefaultColor(Color.GREEN);
zhi.SetLineWeight(1);
zhi.HideBubble();

def peakbn = if peak then bn else 0;
def valleybn = if valley then bn else 0;

def peaklastbn = highestall(peakbn);
#def valleylastbn = highestall(valleybn);


input rectangle_bars = 10;
#def rect1_first = (rectangle_bars + bn - 1) == peaklast;
#def rect1_firstbn = if bn == 1 then 0
# else if (rectangle_bars + bn - 1) == peaklastbn then bn
# else rect1_firstbn[1];

# rect before peak
def rect1_firstbn = peaklastbn - rectangle_bars + 1;
def rect1_lastbn = peaklastbn;
# rect after peak
def rect2_firstbn = rect1_lastbn + 1;
def rect2_lastbn = rect2_firstbn + rectangle_bars - 1;

def rect1 = (bn >= rect1_firstbn and bn <= rect1_lastbn);
def rect2 = (bn >= rect2_firstbn and bn <= rect2_lastbn);


addchartbubble(0, low*0.97,
 bn + "  BN\n" +
 rect1_firstbn + "-" + rect1_lastbn + "\n" +
 rect2_firstbn + "-" + rect2_lastbn + "\n"
, color.yellow, no);


#addverticalline(rect1_firstbn == bn, "-");

#--------------------
# rect1
def rect1_hi;
def rect1_lo;
if rect1_firstbn == bn then {
 rect1_hi =  GetValue(Highest(high,  rectangle_bars), -(rectangle_bars-1));
 rect1_lo = GetValue(Lowest(low,  rectangle_bars), -(rectangle_bars-1));
} else if rect1 then {
 rect1_hi = rect1_hi[1];
 rect1_lo = rect1_lo[1];
} else {
 rect1_hi = 0;
 rect1_lo = 0;
}

plot z1 = if rect1_hi > 0 then rect1_hi else na;
plot z2 = if rect1_lo > 0 then rect1_lo else na;
z1.SetDefaultColor(Color.cyan);
z1.setlineweight(1);
z1.hidebubble();
z2.SetDefaultColor(Color.cyan);
z2.setlineweight(1);
z2.hidebubble();

def r1top = if rect1_hi > 0 then rect1_hi else na;
def r1bot = if rect1_lo > 0 then rect1_lo else na;

addcloud(r1top,r1bot,color.gray);


#--------------------
# rect2
def rect2_hi;
def rect2_lo;
if rect2_firstbn == bn then {
# doesnt work if peak to last bar is < rectangle_bars
# rect2_hi =  GetValue(Highest(high,  rectangle_bars), -(rectangle_bars-1));
# rect2_lo = GetValue(Lowest(low,  rectangle_bars), -(rectangle_bars-1));

rect2_hi = fold a = 0 to (rectangle_bars-1)
 with b
 while !isnan(getvalue(close,-a))
 do max(b, getvalue(high, -a));

rect2_lo = fold c = 0 to (rectangle_bars-1)
 with d = big
 while !isnan(getvalue(close,-c))
 do min(d, getvalue(low,-c));

} else if rect2 then {
 rect2_hi = rect2_hi[1];
 rect2_lo = rect2_lo[1];
} else {
 rect2_hi = 0;
 rect2_lo = 0;
}

plot z3 = if rect2_hi > 0 then rect2_hi else na;
plot z4 = if rect2_lo > 0 then rect2_lo else na;
z3.SetDefaultColor(Color.magenta);
z3.setlineweight(1);
z3.hidebubble();
z4.SetDefaultColor(Color.magenta);
z4.setlineweight(1);
z4.hidebubble();


def r2top = if rect2_hi > 0 then rect2_hi else na;
def r2bot = if rect2_lo > 0 then rect2_lo else na;

addcloud(r2top,r2bot,color.gray);
#
 

Attachments

  • 00c-img1.JPG
    00c-img1.JPG
    44.4 KB · Views: 14
Solution
  • Thank you very much you did good of the way I want to see it on chart but need correct the location, see again clear expiation and I mark on photo attach rectangle 1 and 2 to avoid confusion, my point is to scan for uptrend stock with pullback correction and it make it easy visualization on the chart."

    Rectangle 1 (Most Recent Segment):
    Starts from the most recent highest high in the last 15 bars (excluding current), and goes backward 10 bars.
    • Rectangle 2:
      Begins follow end of Rectangle 1 start after candle No 10 of Rectangle 1 countering from right to left, spans 10 bars backward.
    • It will plot only if Both:
      • Rectangle 1 contains the recent high from last 15 bars.
      • Rectangle 1 is fully higher than Rectangle 2. Else no need to plot on chart
    • After Rectangle 1 I need see pullback
 

Attachments

  • ScreenHunter 871.jpg
    ScreenHunter 871.jpg
    31.6 KB · Views: 11
  • Thank you very much you did good of the way I want to see it on chart but need correct the location, see again clear expiation and I mark on photo attach rectangle 1 and 2 to avoid confusion, my point is to scan for uptrend stock with pullback correction and it make it easy visualization on the chart."

    Rectangle 1 (Most Recent Segment):
    Starts from the most recent highest high in the last 15 bars (excluding current), and goes backward 10 bars.
    • Rectangle 2:
      Begins follow end of Rectangle 1 start after candle No 10 of Rectangle 1 countering from right to left, spans 10 bars backward.
    • It will plot only if Both:
      • Rectangle 1 contains the recent high from last 15 bars.
      • Rectangle 1 is fully higher than Rectangle 2. Else no need to plot on chart
    • After Rectangle 1 I need see pullback

i went by your words and didn't pay attention to the picture.
your words dont match the picture.
if something is after something on a chart, it is in the future, to the right.

it seems like you want rectangle 2 to appear to the left of rectangle 1, before it.

what does fully higher mean?
 
Last edited:
see photo with explanation showing your scrip and the chnge i need ,i am not looking to the future, if it make it easy for you i can stay with your scrip and just add anther rarctangle backword
 

Attachments

  • ScreenHunter 877.jpg
    ScreenHunter 877.jpg
    41.7 KB · Views: 2

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
388 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

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.

What are the benefits of VIP Membership?
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.
Back
Top