Range trading strategy: rules for a sideways market
By Oalgo · Last reviewed
A range trading strategy is for a market that moves sideways between a floor and a ceiling. It enters near the floor, exits near the ceiling, and gets out if price breaks through. A range is something you see in past candles, so the rule has to put it into numbers.
How do you put a range into numbers?
#- Floor and ceiling: the lowest low and the highest high of the last 20 candles. The lower and upper lines of the Donchian Channels are exactly these, and the middle line is halfway between them.
- Position in the range: Stochastic %K is 0 when the close is at the lowest low of the last 14 candles and 100 when it is at the highest high.
- A sideways check: ADX below 20 says there is little trend. It describes the past candles and does not say that the range will hold.
What are the rules of a range trading strategy?
#- Entry: ADX (14) is below 20, %K (14) is below 20, and the close is above the floor as it stood one candle earlier.
- Exit: %K rises above 80. A shorter version exits at the Donchian middle line.
- Stop: a Stop Loss as a percentage, for the day the range breaks.
What does a worked example look like?
#Say the lowest low of the last 14 candles is 100 and the highest high is 110. Then %K = 100 × (close − 100) ÷ 10.
| Close | %K | Where it sits | What the rule does |
|---|---|---|---|
| 101 | 10 | Near the floor | %K is below 20: entry |
| 103 | 30 | Lower half | In the trade |
| 105 | 50 | Middle | In the trade |
| 107.5 | 75 | Upper half | In the trade |
| 109 | 90 | Near the ceiling | %K is above 80: exit |
Why look at the floor from one candle earlier?
#The floor includes the current candle. If a candle breaks below it and closes at its low, say 99.5, that low becomes the new lowest low and %K reads 0, which looks like the best entry of all. It is the range breaking. So the rule compares the close with the floor as it stood one candle earlier, 100, and the close of 99.5 fails that test.
How do you write this strategy in Oalgo?
#In Oalgo you can tell Oalgo AI your range rule in your own words, check the rule it builds, and test it. After testing, if you choose, you Go Live with your own Live Strategy on your own Venue Account at a Supported Venue.
For example, you could tell Oalgo AI: "Enter when ADX (14) is below 20, Stochastic %K (14) is below 20, and the close is above the 20-candle Donchian lower line from one candle ago. Exit when %K rises above 80. Use a 1.5% Stop Loss and a 3% exit target." These numbers are examples to change. In the builder, the Lookback condition with Bars Ago set to 1 reads the Donchian lower line from one candle earlier, and AND blocks join the three conditions. A Live Strategy needs a stop on each side it can enter, and an exit target is optional. The example names both.
How do you test this strategy honestly?
#- Run a backtest on a sideways stretch and on a trending one. This rule is made for the first.
- Look at the trades that ended at the Stop Loss. They are the ranges that broke. If most of them sit in one stretch, the rule met a trend there.
- Move the levels (%K 15, 20 and 25, ADX 20 and 25). If the report changes a lot, the first result may be fitted to one period.
- Run a forward test on new prices, with simulated funds.
What can a range trading strategy not tell you?
#A range is a description of the past. Price can leave it on any candle, and a rule that enters near the floor is next to the exit when it does. A low ADX says that the past was quiet, not that the next candle will be. Many ranges only look like ranges in hindsight, as small pauses inside a trend. The rule has six numbers (ADX 14 and 20, %K 14, 20 and 80, Donchian 20), so it has room to be fitted to one period.
Read next
- Mean reversion strategy: rules, example and limitsA mean reversion strategy enters when price is far below its average and exits as it comes back. See an example rule, when it fails, and how to test it.
- Donchian Channels explained: how to read and use themDonchian Channels mark the highest high and the lowest low of the last N candles. Learn how they are calculated, how a breakout reads, and how to test rules.