How to draw rectangle box to Identify sideway before Breakout

Dear AB Expert,
I want to make an afl to draw a rectangle (sideway box) as well as to explore stock (as shown in the image attached) with the conditions:

  1. Minimum days sideway box = 50 days
  2. Sideway box height depends on high and low candles in 50 days and maximum height 25%

Does anyone have any pointers on where to start?
Please help me

Thanks in advance


Darva Box might give you a start...

@dangin.gen and another possible starting point for your idea.

You will need to define what constitutes sideways action and code it. Try that first and run some explores to see if your code is finding sideway action.