How to draw rectangle box to Identify sideway before Breakout

BO SW
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

Dangin

Darva Box might give you a start...

https://www.amibroker.com/members/library/detail.php?id=1101

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

http://www.amibroker.com/members/traders/08-2018.html

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.