3 Ways to Identify a Ranging Market with Your Algo

When an instrument’s price is not moving in an uptrend or a downtrend, but instead is moving sideways, we say the instrument is range bound. This is simple to visually identify, but when we are relying on an algorithm to identify a range bound market, we need to be able to define this using technical tools and rules. This article will discuss 3 ways to programmatically identify a ranging market.

1. Average Directional Index Under 25

The Average Directional Index, or ADX, is a technical tool that tells us if an instrument is moving in a clear direction (either up or down) or is moving sideways. Open source calculations (in Python) of this indicator can be found on this open source GitHub which makes it easy to add to your trading algo. High ADX values (around 30 or higher) can be interpreted as an instrument whose price is predominantly moving up or down. Low ADX values (around 25 or lower) can be interpreted as an instrument whose price is predominantly moving sideways. Adding ADX to an algorithm and only allowing it to trade when ADX is below 25 will filter out trending markets and mainly focus on ranging markets.

2. Average True Range Below 20-Period Moving Average

The Average True Range, or ATR, is a technical tool that displays the average difference between the most recent candles’ highs and lows. Because ATR values are not normalized like some indicators, it’s important to compare the current ATR value to historical ATR values for the same instrument. This is where the 20-Period Moving Average of the ATR becomes useful. Adding ATR with a 20-Period Moving Average of the ATR and only allowing it to trade when ATR is below the Moving Average will filter out big bull and big bear runs and hone in more on ranges. This is a fairly straight forward indicator to add to your code from scratch, but here is an example of the calculations in Python.

3. RSI Between 40 and 60

The Relative Strength Index, or RSI, is a technical tool that displays how strongly price is moving up or down. Here is an example of how to calculate RSI programmatically in Python. Traditionally, traders look at RSI values above 70 to define strong bullish moves and RSI values below 30 to define strong bearish moves. But for a range trading strategy, we can identify a higher likelihood of range bound action when RSI rests between 40 and 60. Only trading while RSI is between 40 and 60 will filter out many of the strong trends.

Risk Warning: The FXCM Group does not guarantee accuracy and will not accept liability for any loss or damage which arise directly or indirectly from use of or reliance on information contained within the webinars. The FXCM Group may provide general commentary which is not intended as investment advice and must not be construed as such. FX/CFD trading carries a risk of losses in excess of your deposited funds and may not be suitable for all investors. Please ensure that you fully understand the risks involved.