Strategy vault / Trend following
ATR Volatility and Moving Average Based Adaptive Trend Following Exit Strategy
This is a trend following strategy based on ATR (Average True Range) bands and moving averages. The strategy utilizes the ATR indicator to dynamically adjust profit-taking and stop-loss positions, while using moving…

Overview
This is a trend following strategy based on ATR (Average True Range) bands and moving averages. The strategy utilizes the ATR indicator to dynamically adjust profit-taking and stop-loss positions, while using moving averages to determine market trend direction, achieving trend capture and risk control. The core of the strategy lies in using ATR bands as a dynamic exit mechanism, allowing the strategy to adaptively adjust position exit points based on market volatility changes.
Strategy Principles
The strategy consists of three core components:
- ATR Band Calculation: Uses 14-period ATR indicator, constructing upper and lower volatility bands by adding and subtracting 2 times the ATR value from the current closing price.
- Moving Average System: Employs a 50-period Simple Moving Average (SMA) as the basis for trend judgment.
- Trade Signal Generation:
- Entry Signal: Initiates a long position when price crosses above the moving average.
- Exit Signal: Closes positions when price touches either the upper or lower ATR band.
The strategy combines trend following with volatility management, enabling both market trend capture and dynamic risk exposure adjustment based on market volatility changes.
Strategy Advantages
- Strong Adaptability: ATR indicator automatically adjusts profit-taking and stop-loss positions based on market volatility changes, providing good market adaptability.
- Reasonable Risk Control: Effectively controls risk exposure for each trade through ATR multiplier settings.
- Robust Trend Capture: Effectively identifies market trend direction by incorporating moving averages.
- Flexible Parameter Settings: Can adapt to different market environments by adjusting ATR period, multiplier, and moving average period.
- Clear Execution Logic: Precise entry and exit conditions avoid interference from subjective judgment.
Strategy Risks
- Choppy Market Risk: May generate frequent false signals in sideways markets, leading to excessive trading costs.
- Slippage Risk: Actual execution prices may significantly deviate from theoretical prices during intense market volatility.
- Trend Reversal Risk: May not stop losses timely when market trends suddenly reverse.
- Parameter Optimization Risk: Optimal parameters may vary significantly across different market environments.
Strategy Optimization Directions
Incorporate Trend Strength Filtering:
- Add trend strength indicators like ADX or DMI to filter trading signals in weak trend environments.
- Adjust ATR multiplier in strong trend environments to capture larger profit potential.
Enhance Position Management:
- Dynamically adjust position size based on ATR values.
- Implement staged position building and reduction mechanisms.
Add Market Environment Recognition:
- Introduce volatility cycle analysis.
- Add market pattern recognition module.
Optimize Exit Mechanism:
- Implement dynamic profit protection.
- Add time-based stop-loss mechanism.
Summary
This strategy constructs an adaptive and risk-controlled trend following system by combining ATR bands and moving averages. The core advantage lies in its ability to dynamically adjust risk control positions based on market volatility changes while capturing market trend direction through moving averages. Although inherent risks exist, the proposed optimization directions can further enhance strategy stability and profitability. This is a practically valuable strategy framework suitable for in-depth research and application in live trading.
Source Pine Script
/*backtest
start: 2024-10-01 00:00:00
end: 2024-10-31 23:59:59
period: 1h
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("ATR Band Exit Strategy", overlay=true)
// Define input parameters
atrLength = input(14, title="ATR Length")
atrMultiplier = input(2.0, title="ATR Multiplier")
maLength = input(50, title="Moving Average Length")
// Calculate ATR and moving average
atrValue = ta.atr(atrLength)
maValue = ta.sma(close, maLength)
// Calculate upper and lower ATR bands
upperBand = close + atrMultiplier * atrValue
lowerBand = close - atrMultiplier * atrValue
// Plot ATR bands
plot(upperBand, title="Upper ATR Band", color=color.red, linewidth=2)
plot(lowerBand, title="Lower ATR Band", color=color.green, linewidth=2)
// Entry condition (for demonstration: long if price above moving average)
longCondition = ta.crossover(close, maValue)
if (longCondition)
strategy.entry("Long", strategy.long)
// Exit conditions (exit if price crosses the upper or lower ATR bands)
if (close >= upperBand)
strategy.close("Long", comment="Exit on Upper ATR Band")
if (close <= lowerBand)
strategy.close("Long", comment="Exit on Lower ATR Band")
// Optional: Plot the moving average for reference
plot(maValue, title="Moving Average", color=color.blue)
Published by ChaoZhang on the FMZ strategy square · last modified 2024-11-27. 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/ATR-Volatility-and-Moving-Average-Based-Adaptive-Trend-Following-Exit-Strategy.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 Risk Management Strategy Based on Dynamic ATR and Moving Average CrossoverPine Script · Trend following · 2h
- Multi Dimensional Short Term Trend Predictor Technical Analysis and Volatility Adaptive Trading StrategyPine Script · Trend following · 1h
- Multi Factor Trend Price Action Strategy with Dynamic Risk Management SystemPine Script · Trend following · 2h
- Multi Indicator Dynamic Trend Following Strategy Based on EMA and SMAPine Script · Trend following · 1d
- Multi Indicator Trend Following with Oscillator Alert StrategyPine Script · Trend following · 2h
- Trend Tracking and Short term Trading Strategy Based on ADX IndicatorPine Script · Trend following · 1d