Calculate the range as the difference between the high and low prices.
The maxRange input to specify the maximum allowable range that defines a sideways market.
The background color is set to blue during sideways market conditions, and it's transparent to some extent (transp=90). When the market is not sideways, the background color is not changed.
The indicator marks the start and end of the session with red triangles.
When the price range (high - low) is within the specified threshold, the indicator will indicate a sideways market with a blue background.
In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in publications is governed by House rules. You can favorite it to use it on a chart.
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.