Strategy vault / Mean reversion
Reversal Trading Strategy Based on Moving Average Range
This strategy is named "Moving Average Range Reversal". It identifies market reversal opportunities by calculating crossovers between moving averages of different timeframes and takes appropriate long/short positions.

Overview
This strategy is named "Moving Average Range Reversal". It identifies market reversal opportunities by calculating crossovers between moving averages of different timeframes and takes appropriate long/short positions.
Strategy Logic
The strategy computes 3 moving averages simultaneously:
- Fast MA (flenght): Reflecting latest price changes
- Slow MA (llenght): Reflecting mid-term price trends
- Slowest MA (sslenght): Reflecting long-term price tendencies
When fast MA crosses above slow MA, it signals a short-term trend reversal to bullish. When fast MA crosses below slow MA, it signals a short-term reversal to bearish.
To avoid false signals, a 4th MA is introduced as the long-term filter (tlenght). Only above this filter long signals are considered. Only below this filter short signals are considered.
The specific trading rules are:
When fast MA crosses above slow MA, and slow MA also crosses above slowest MA (short-term bullish), while price is above the long-term filter, go long. When fast MA crosses below slow MA, close long position.
When fast MA crosses below slow MA, and slow MA also crosses below slowest MA (short-term bearish), while price is below the long-term filter, go short. When fast MA crosses above slow MA, close short position.
Advantage Analysis
The advantages of this strategy include:
- Utilizing multiple timeframes to identify trend changes more precisely and reduce false signals.
- Long-term filter avoids mispositioned trades before major trend reversal.
- Simple and clear rules, easy to understand and automate.
- Reversal strategies benefit from positive bias in returns and profits.
- Good backtest results in simulated live trading regarding returns and profit factor.
Risk Analysis
The risks of the strategy include:
- MA strategies are sensitive to parameters. Different parameters lead to different results.
- False breakout of reversal signals may cause losses.
- Prolonged sideways may nullify profits from repeated reversals.
- Price may reverse and accelerate with strength, failing timely stop loss.
Solutions:
- Optimize parameters to find best combination.
- Increase signal confirmation time to avoid false signals.
- Expand stop loss range to control loss amount.
Optimization Directions
The strategy can be improved in the following aspects:
- Test more parameter sets to find optimum values.
- Add volume filter to avoid false signals in low volume conditions.
- Incorporate other indicators to confirm entry signals.
- Implement dynamic adjustment of stop loss for better exit control.
- Optimize risk management for tighter risk control.
Conclusion
This strategy trades market reversals identified by MA crossovers, with direction guidance from the long-term filter. It effectively captures opportunities at turning points. The positive backtest results show good profitability for live application. Further optimizations on parameters, signal filtering, stop loss etc. can make the strategy more robust for practical use.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_int_1 | 3 | Fast MA Period |
| v_input_int_2 | 5 | Slower MA Period |
| v_input_int_3 | 8 | Slowest MA Period |
| v_input_int_4 | 200 | Trend Filter MA Period |
Source Pine Script
/*backtest
start: 2023-12-01 00:00:00
end: 2023-12-31 23:59:59
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Moving Average Trap", overlay=true)
flenght = input.int(title="Fast MA Period", minval=1, maxval=2000, defval=3)
llenght = input.int(title="Slower MA Period", minval=1, maxval=2000, defval=5)
sslenght = input.int(title="Slowest MA Period", minval=1, maxval=2000, defval=8)
tlenght = input.int(title="Trend Filter MA Period", minval=1, maxval=2000, defval=200)
ssma = ta.sma(close, sslenght)
fma = ta.sma(close, flenght)
sma = ta.sma(close, llenght)
tma = ta.sma(close, tlenght)
plot(fma, color=color.red)
plot(sma, color=color.white)
plot(ssma, color=color.green)
plot(tma, color=color.maroon, linewidth=2)
short = (fma > sma and sma > ssma) and close < tma
long = (fma < sma and sma < ssma) and close > tma
closeshort = fma < sma and sma < ssma
closelong = fma > sma and sma > ssma
if long
strategy.entry("long", strategy.long)
if closelong
strategy.close("long")
if short
strategy.entry("short", strategy.short)
if closeshort
strategy.close("short")
//plot(strategy.equity, title="equity", color=color.red, linewidth=2, style=plot.style_areabr)Published by ChaoZhang on the FMZ strategy square · last modified 2024-01-25. Collected in the Quant Trading Vault. Unvalidated research: re-test with your own data and costs before trusting it.
Build this with AgenKit
A spec is not a trading system. Paste this into your coding agent and AgenKit runs a specialist team — architecture, test-first build, risk gates, review — with paper trading on by default.
/agenkit build a production-grade trading bot with a backtest engine, risk controls and paper trading by default from strategies/Reversal-Trading-Strategy-Based-on-Moving-Average-Range.md- npx agenkit install engineering-kit in your project
- Paste the command into your agent and approve each phase
- Get tests, backtest, risk controls and a paper-trading switch
Understand it first
Before you run this, read the lesson behind the idea and how to backtest it honestly. Specs like this one are the survivors of an unknown number of trials; deflate their results accordingly.
Related specs
- Adaptive Mean Reversion Trading Strategy Based on Chande Momentum OscillatorPine Script · Mean reversion · 1d
- Advanced Momentum EMA Trend Following with RSI Overbought Oversold Trading StrategyPine Script · Mean reversion · 1d
- Advanced Strategy with Volume and Price Pullback Multiple Take ProfitPine Script · Mean reversion · 1h
- Dynamic Adaptive Multi Timeframe Trend Following and Range Reversal Hybrid StrategyPine Script · Mean reversion · 2d
- Fast RSI Reversal Trading StrategyPine Script · Mean reversion · 1h
- Multi Indicator Reversal Point Capture Trading StrategyPine Script · Mean reversion · 1d