0bps

Strategy vault / Trend following

Optimized ATR Based Trend Strategy v6 Fixed Trend Capture

This is an Average True Range (ATR)-based trend-following strategy designed to capture high-probability trades by combining multiple technical indicators. The strategy integrates ATR filtering, Supertrend indicator…

Author
ianzeng123
Complexity
Intermediate · 97 lines
Parameters
0
Backtest bar
1d · swing
Tested on
ETH/USDT · futures

IMG IMG

Overview

This is an Average True Range (ATR)-based trend-following strategy designed to capture high-probability trades by combining multiple technical indicators. The strategy integrates ATR filtering, Supertrend indicator, Exponential Moving Average (EMA) and Simple Moving Average (SMMA) trend bands, Relative Strength Index (RSI) confirmation, and a dynamic stop-loss system, aiming to provide a comprehensive and flexible trading approach.

Strategy Principles

The core principle is based on the synergistic action of multiple technical indicators:

  1. Trend Identification: Using Supertrend indicator (parameters: factor 2, length 5) and 50-day EMA with 8-day SMMA trend bands to define market trend direction. Trends are color-coded:

    • Green: Bullish trend
    • Red: Bearish trend
    • Gray: Neutral phase
  2. ATR Smart Filtering: Detecting volatility expansion through 14-period ATR and 50-period Simple Moving Average, trading only when ATR is rising or above 101% of its SMA, ensuring entries only in strong trends.

  3. Entry Conditions:

    • Long Entry: Price above 50-day EMA, Supertrend bullish, RSI > 45, ATR confirms trend strength
    • Short Entry: Price below 50-day EMA, Supertrend bearish, RSI < 45, ATR confirms trend strength
  4. Dynamic Stop-Loss and Take-Profit:

    • Take-Profit: Adaptive based on 5x ATR
    • Stop-Loss: Trailing stop-loss at 3.5x ATR
    • Break-Even Stop: Activated after price moves 2x ATR
    • Fixed Stop-Loss: Risk management using 0.8x ATR multiplier

Strategy Advantages

  1. Effectively filter volatile markets, avoiding trading in low volatility zones
  2. Prevent over-trading through take-profit lock mechanism
  3. Capture strong trends, allowing profits to run with trailing stop-loss
  4. Reduce drawdowns with ATR-based stop-loss
  5. Adjustable parameters for fine-tuning across different markets

Strategy Risks

  1. Over-reliance on technical indicators may lead to false signals
  2. Potential poor performance in ranging markets
  3. Improper parameter settings may increase trading costs
  4. RSI confirmation might miss rapid trend changes

Strategy Optimization Directions

  1. Integrate machine learning algorithms for dynamic parameter adjustment
  2. Add additional filters like volume confirmation
  3. Explore optimal parameter combinations across different markets and timeframes
  4. Develop multi-timeframe verification mechanisms

Conclusion

This is an advanced trend-following strategy that provides traders with a flexible and powerful trading tool through multi-indicator synergy and dynamic risk management. Continuous backtesting and optimization are key to successful application.

Source Pine Script

/*backtest
start: 2024-03-31 00:00:00
end: 2025-03-29 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"ETH_USDT"}]
*/

//@version=6
strategy("Optimized ATR-Based Trend Strategy v6 (Fixed Trend Capture)", overlay=true)

// ? Input parameters
lengthSMMA = input(8, title="SMMA Length")
lengthEMA = input(50, title="EMA Length")
supertrendFactor = input(2.0, title="Supertrend Factor")
supertrendLength = input(5, title="Supertrend Length")
atrLength = input(14, title="ATR Length")  
atrSmoothing = input(50, title="ATR Moving Average Length")  
atrMultiplierTP = input.float(5.0, title="ATR Multiplier for Take-Profit", minval=1.0, step=0.5)  
atrMultiplierTSL = input.float(3.5, title="ATR Multiplier for Trailing Stop-Loss", minval=1.0, step=0.5)  // ? Increased to ride trends
atrStopMultiplier = input.float(0.8, title="ATR Stop Multiplier", minval=0.5, step=0.1)  
breakEvenMultiplier = input.float(2.0, title="Break-Even Trigger ATR Multiplier", minval=1.0, step=0.1)
rsiLength = input(14, title="RSI Length")  

// ? Indicator calculations
smma8 = ta.sma(ta.sma(close, lengthSMMA), lengthSMMA)  
ema50 = ta.ema(close, lengthEMA)  

// ? Supertrend Calculation
[superTrend, _] = ta.supertrend(supertrendFactor, supertrendLength)

// ? Supertrend Conditions
isBullishSupertrend = close > superTrend
isBearishSupertrend = close < superTrend

// ? ATR Calculation for Smarter Filtering
atrValue = ta.atr(atrLength)
atrMA = ta.sma(atrValue, atrSmoothing)
atrRising = ta.rising(atrValue, 3)  // ? More sensitive ATR detection
isTrending = atrValue > atrMA * 1.01 or atrRising  // ? Loosened ATR filter

// ? RSI Calculation
rsi = ta.rsi(close, rsiLength)

// ? RSI Conditions (More Flexible)
isRSIBullish = rsi > 45  // ? Lowered to capture early trends
isRSIBearish = rsi < 45  

// ? TP Lock Mechanism
var bool tpHit = false  
if strategy.position_size == 0 and strategy.closedtrades > 0
    tpHit := true  

// ? Supertrend Flip Detection (Resumes Trading After Trend Change)
trendFlip = (isBullishSupertrend and not isBullishSupertrend[1]) or (isBearishSupertrend and not isBearishSupertrend[1])
if trendFlip
    tpHit := false  

// ? Entry Conditions
bullishEntry = close > ema50 and isBullishSupertrend and isRSIBullish and isTrending and not tpHit
bearishEntry = close < ema50 and isBearishSupertrend and isRSIBearish and isTrending and not tpHit

// ? Dynamic Take-Profit, Stop-Loss, and Break-Even Stop
longTakeProfit = close + (atrValue * atrMultiplierTP)  
shortTakeProfit = close - (atrValue * atrMultiplierTP)  
longTrailStop = atrValue * atrMultiplierTSL  
shortTrailStop = atrValue * atrMultiplierTSL  

// ✅ Adjusted SL to Reduce Drawdown
longStopLoss = close - (atrValue * atrMultiplierTSL * atrStopMultiplier)
shortStopLoss = close + (atrValue * atrMultiplierTSL * atrStopMultiplier)

// ✅ Break-Even Stop Trigger (More Room for Trends)
longBreakEven = strategy.position_avg_price + (atrValue * breakEvenMultiplier)
shortBreakEven = strategy.position_avg_price - (atrValue * breakEvenMultiplier)

// ? Strategy Execution (Fixed Take-Profit & Stop-Loss)
if (bullishEntry)
    strategy.entry("Buy", strategy.long)
    strategy.exit("TSL/TP", from_entry="Buy", stop=longStopLoss, trail_offset=longTrailStop, limit=longTakeProfit)
    strategy.exit("BreakEven", from_entry="Buy", stop=longBreakEven)

if (bearishEntry)
    strategy.entry("Sell", strategy.short)
    strategy.exit("TSL/TP", from_entry="Sell", stop=shortStopLoss, trail_offset=shortTrailStop, limit=shortTakeProfit)
    strategy.exit("BreakEven", from_entry="Sell", stop=shortBreakEven)

// ? Trend Band
trendColor = isBullishSupertrend and smma8 > ema50 and close > ema50 ? color.green :
             isBearishSupertrend and smma8 < ema50 and close < ema50 ? color.red : color.gray
fill(plot(smma8, color=color.new(trendColor, 60), title="8 SMMA Band"),
     plot(ema50, color=color.new(trendColor, 60), title="50 EMA Band"),
     color=color.new(trendColor, 80), title="Trend Band")

// ? Supertrend Line
plot(superTrend, color=color.gray, title="Supertrend", style=plot.style_line)

Published by ianzeng123 on the FMZ strategy square · last modified 2025-03-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.

in Claude Code, Cursor, Codex & 4 more
/agenkit build a production-grade trading bot with a backtest engine, risk controls and paper trading by default from strategies/Optimized-ATR-Based-Trend-Strategy-v6-Fixed-Trend-Capture.md
  1. npx agenkit install engineering-kit in your project
  2. Paste the command into your agent and approve each phase
  3. 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

esc

Try , , or .

↑↓ move↵ open