ATR Trailing Stop Strategy Long Only
This strategy uses two ATR stops with different parameters to set dynamic stop loss levels - one fast stop and one slow stop. It establishes long positions based on price breakouts of the different stop levels and…

Overview
This strategy uses two ATR stops with different parameters to set dynamic stop loss levels - one fast stop and one slow stop. It establishes long positions based on price breakouts of the different stop levels and exits positions using the trailing stops. The goal is to use ATR stops to set reasonable stop loss levels while maximizing the trend following ability.
Strategy Logic
The strategy uses ATR indicator to calculate two stop loss levels. The fast stop uses 5-period ATR multiplied by 0.5 as the stop distance. The slow stop uses 10-period ATR multiplied by 3 as the stop distance. When price breaks above the fast stop level, a long position is established. When price continues to break above the slow stop level, the stop is adjusted to the slow stop level. If price turns down, the stop level is adjusted based on the crossover relationships.
The logic is:
Calculate fast stop Trail1: 5-period ATR * 0.5
Calculate slow stop Trail2: 10-period ATR * 3
When price breaks above Trail1, establish long position
When price continues to break above Trail2, adjust stop to Trail2
If price turns down breaking Trail1, adjust stop back to Trail1
If price continues down breaking Trail2, adjust stop to Trail2
Finally, if price hits the stop level, exit the position with stop loss
This way, the strategy can maximize the profit during uptrends with the trailing stops while quickly stopping out losses when the trend reverses. The two stops also balance between capturing trends and limiting losses.
Advantages
ATR stops set dynamic stop loss levels based on market volatility
Dual stop mechanism balances between stopping losses and trailing trends
Long direction aligns with overall uptrend, higher profitability
Simple and clear logic, easy to understand and implement
Strict stop loss rules limit losses effectively
Risks
Improper ATR parameters may cause stops being too wide or too tight
Long direction has directional bias, prone to stops at market tops
Dual stop rules are complex, may fail if not set properly
No filters such as EMA crossovers, may cause bad trades
No position or risk management, risks of overtrading
These risks can be reduced by optimizing ATR parameters, adding filters, and enforcing risk management.
Improvement Areas
Optimize ATR parameter combinations for best results
Add filters like EMA to qualify entry signals
Incorporate indicators like Stoch RSI for additional edge
Add re-entry logic to optimize position management
Optimize risk management rules to limit per trade stop loss
Incorporate market-level analytics to avoid directional mistakes
Consider faster timeframe strategies like hourly
Expand to multi-market universal strategy
Deploy high performance trading engine
With these improvements, the strategy can be more robust, stable and profitable.
Summary
The strategy uses clear ATR trailing stops for long entries and exits. The advantages lie in its strict stop loss rules to limit losses while trailing trends. It has directional bias risks that can be reduced through optimizations like better parameters, adding filters and enhancing risk management. With further testing and improvements, this can become a reliable trend following strategy.
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 period |
| v_input_5 | 3 | Slow ATR multiplier |
Source Pine Script
/*backtest
start: 2023-10-25 00:00:00
end: 2023-11-01 00:00:00
period: 1m
basePeriod: 1m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=4
strategy("ATR Trailing Stop Strategy (Long Position Only)", overlay=true)
SC = input(close, "Source", input.source)
// Fast Trail
AP1 = input(5, "Fast ATR period", input.integer)
AF1 = input(0.5, "Fast ATR multiplier", input.float)
SL1 = AF1 * atr(AP1)
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), SC + SL1, na))
// Slow Trail
AP2 = input(10, "Slow ATR period", input.integer)
AF2 = input(3, "Slow ATR multiplier", input.float)
SL2 = AF2 * atr(AP2)
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), SC + SL2, na))
Green = Trail1 > Trail2 and close > Trail2 and low > Trail2
Buy = crossover(Trail1, Trail2)
plotshape(Buy, style=shape.triangleup, location=location.belowbar, color=color.green, size=size.small)
strategy.entry("Buy", strategy.long, when = Buy)
var float trailingStopPrice = na
if (Trail2 > trailingStopPrice)
trailingStopPrice := Trail2
if (crossover(Trail1, Trail2))
trailingStopPrice := Trail2
strategy.exit("Exit", from_entry = "Buy", stop=trailingStopPrice)
Published by ChaoZhang on the FMZ strategy square · last modified 2023-11-02. 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-Trailing-Stop-Strategy-Long-Only.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
- Momentum Breakout Intraday Trading StrategyPine Script · Breakout · 5m
- Multi Indicator Trend Following and Volatility Breakout StrategyPine Script · Breakout · 2h
- Bull Market Tracking SystemPine Script · Breakout · 1h
- Dual MA Momentum Breakout StrategyPine Script · Breakout · 1h
- Dynamic Stop Loss Strategy Adaptive to ATR FluctuationsPine Script · Breakout · 1h
- EMA and Bollinger Bands Breakout StrategyPine Script · Breakout · 1h