Strategy vault / Trend following
Dual ATR Trailing Stop Strategy
The Dual ATR Trailing Stop strategy is a short-term trading strategy based on the Average True Range (ATR) indicator. The strategy sets two stop loss lines, fast ATR line and slow ATR line, at the same time, and…

Overview
The Dual ATR Trailing Stop strategy is a short-term trading strategy based on the Average True Range (ATR) indicator. The strategy sets two stop loss lines, fast ATR line and slow ATR line, at the same time, and determines entry and exit based on the crossover of the two lines. The strategy is simple, responsive, and suitable for high volatility markets.
Strategy Principle
The core of this strategy is using two ATR stop loss lines. One is the fast ATR line with short period and small multiplier for fast reaction. The other is the slow ATR line with longer period and bigger multiplier for filtration. When fast ATR line crosses above slow ATR line, it generates buy signal. When fast ATR line crosses below slow ATR line, it generates sell signal. So the strategy uses the crossover of two ATR lines to determine entry and exit, which can effectively control the stop loss.
The specific logic is: calculate fast ATR line and slow ATR line. When price is above slow line, use fast line to trail stop loss. Otherwise, use slow line to trail stop loss. The color of Kline represents current stop loss line. Green and blue means using fast line. Red and yellow means using slow line. Exit when market price touches the stop loss lines.
Advantage Analysis
The advantages of this strategy are:
- Simple and clear logic, easy to understand and implement.
- Fast response to market change, suitable for high volatility market.
- Dual ATR stop loss controls risk effectively.
- ATR indicator is parametric for adjusting stop loss range.
- Visual Kline color indicates stop loss situation clearly.
Risk Analysis
There are also some risks:
- Prone to over-trading.
- ATR has poor curve fitting, may amplify losses.
- Cannot effectively filter sideways and trending markets.
We can reduce risks by optimizing ATR period, adjusting ATR multiplier, combining other indicators for filtration etc.
Optimization Direction
The optimization directions are:
- Optimize ATR parameters for better stop loss range.
- Add filter indicators to avoid invalid trades, like MA.
- Add open conditions to avoid mistrades. For example, add volume indicators.
- Add exits for holding period to avoid over-trading.
Conclusion
The Dual ATR Trailing Stop Strategy is easy to understand and implement, especially suitable for high volatility scenarios, and can effectively control risks. There is also large room for optimization. It is a recommended short-term strategy worth trying.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_1_close | 0 | Source: close | high | low | open | hl2 | hlc3 | hlcc4 | ohlc4 |
| v_input_2 | 5 | Fast ATR period |
| v_input_3 | 0.5 | Fast ATR multiplier |
| v_input_4 | 10 | Slow ATR perod |
| v_input_5 | 2 | Slow ATR multiplier |
| v_input_6 | true | Paint color on chart |
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"}]
*/
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © ceyhun
//@version=4
strategy("ATR Trailing Stop Strategy by ceyhun", overlay=true)
/////////notes////////////////////////////////////////
// This is based on the ATR trailing stop indicator //
// width addition of two levels of stops and //
// different interpretation. //
// This is a fast-reacting system and is better //
// suited for higher volatility markets //
//////////////////////////////////////////////////////
SC = input(close, "Source", input.source)
// Fast Trail //
AP1 = input(5, "Fast ATR period", input.integer) // ATR Period
AF1 = input(0.5, "Fast ATR multiplier", input.float) // ATR Factor
SL1 = AF1 * atr(AP1) // Stop Loss
Trail1 = 0.0
Trail1 := iff(SC > nz(Trail1[1], 0) and SC[1] > nz(Trail1[1], 0), max(nz(Trail1[1], 0), SC - SL1), iff(SC < nz(Trail1[1], 0) and SC[1] < nz(Trail1[1], 0), min(nz(Trail1[1], 0), SC + SL1), iff(SC > nz(Trail1[1], 0), SC - SL1, SC + SL1)))
// Slow Trail //
AP2 = input(10, "Slow ATR perod", input.integer) // ATR Period
AF2 = input(2, "Slow ATR multiplier", input.float) // ATR Factor
SL2 = AF2 * atr(AP2) // Stop Loss
Trail2 = 0.0
Trail2 := iff(SC > nz(Trail2[1], 0) and SC[1] > nz(Trail2[1], 0), max(nz(Trail2[1], 0), SC - SL2), iff(SC < nz(Trail2[1], 0) and SC[1] < nz(Trail2[1], 0), min(nz(Trail2[1], 0), SC + SL2), iff(SC > nz(Trail2[1], 0), SC - SL2, SC + SL2)))
// Bar color for trade signal //
Green = Trail1 > Trail2 and close > Trail2 and low > Trail2
Blue = Trail1 > Trail2 and close > Trail2 and low < Trail2
Red = Trail2 > Trail1 and close < Trail2 and high < Trail2
Yellow = Trail2 > Trail1 and close < Trail2 and high > Trail2
// Signals //
Bull = barssince(Green) < barssince(Red)
Bear = barssince(Red) < barssince(Green)
Buy = crossover(Trail1, Trail2)
Sell = crossunder(Trail1, Trail2)
TS1 = plot(Trail1, "Fast Trail", style=plot.style_line,color=Trail1 > Trail2 ? color.blue : color.yellow, linewidth=2)
TS2 = plot(Trail2, "Slow Trail", style=plot.style_line,color=Trail1 > Trail2 ? color.green : color.red, linewidth=2)
fill(TS1, TS2, Bull ? color.green : color.red, transp=90)
plotcolor = input(true, "Paint color on chart", input.bool)
bcl = iff(plotcolor == 1, Blue ? color.blue : Green ? color.lime : Yellow ? color.yellow : Red ? color.red : color.white, na)
barcolor(bcl)
if Buy
strategy.entry("Buy", strategy.long, comment="Buy")
if Sell
strategy.entry("Sell", strategy.short, comment="Sell")
Published by ChaoZhang on the FMZ strategy square · last modified 2024-01-31. 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/Dual-ATR-Trailing-Stop-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
- ATR Dynamic Profit Target and Stop Loss StrategyPine Script · Trend following · 1d
- ATR Dynamic Trend Following and EMA Crossover Trading StrategyPine Script · Trend following · 1d
- ATR and Moving Average Crossover Hybrid StrategyPine Script · Trend following · 1h
- ATR and T3 Moving Average StrategyPine Script · Trend following · 5m
- Adaptive ATR and RSI Trend Following Strategy with Trailing Stop LossPine Script · Trend following · 1h
- Adaptive Risk Management Strategy Based on Dynamic ATR and Moving Average CrossoverPine Script · Trend following · 2h