Market range is a situation in the market where there isn't any definite movement and market is just making a zigzag movement hitting support and resistance levels over and over again, to detect this sort of thing is very easy because you will have to do other stuffs like detect a break of structure depending on where we currently are in the market.
And then draw a horizontal line at the top and bottom where the price bounce off and then be placing your trades at each high and low, hence making money at every swing and also beware of a breakout because it can happen at any time, so be quick to exit if it does and position for the new trend.
A new range might also not be tradeable and be made of tiny candles you can't make sense of, in that case pay attention to a breakout and also classify them in a box.