How to detect ranging market using MQL

Hi all I am developing EA. I am having difficulty in pragmatically identifying ranging market.

Please help in this regards.

up=higher high’s + higher low’s.

down=lower low’s + lower high’s.

So what would ranging be ?

Pull the highest, and lowest value over your lookback period.

As long as they stay the same, and there is no breakout, price will be ranging between these two levels.

The answer is exactly what @wshapter1w said.

The problem is that we only know if a market is ranging or trending after it has already began… the problem is that after that happens, it could keep going that way for some time or change right after.

Calculate the slope (e.g. line of best fit, linear regression of prices with an appropriate lookback period. If the slope is close to zero, the market is ranging during that period.

Of course the problem is that you can only calculate using past values. This will tell you when the market “was” ranging; it doesn’t predict if the market will continue ranging.