ATR-Based Dynamic Trailing Take-Profit Three-Bar Reversal Quantitative Trading Strategy
FMZQuant

FMZQuant @fmzquant

Joined:
Apr 25, 2024

ATR-Based Dynamic Trailing Take-Profit Three-Bar Reversal Quantitative Trading Strategy

Publish Date: Jun 18
2 1

Image description

Image description

Overview
The ATR-Based Dynamic Trailing Take-Profit Three-Bar Reversal Quantitative Trading Strategy is a sophisticated trading system designed to identify short-term market exhaustion signals. The core concept involves capturing reversal signals that occur after three consecutive candles in the same direction, while employing a dynamic trailing take-profit mechanism based on Average True Range (ATR) to protect profits. This strategy is particularly suitable for medium-short timeframes such as 15-minute, 1-hour, and 4-hour charts, automatically adapting to the volatility characteristics of different market environments without requiring fixed stop-loss levels, instead relying on a dynamic profit-taking mechanism to control risk.

Strategy Principles
The entry logic of this strategy is based on clear price pattern recognition:

Three consecutive same-direction candles form directional confirmation:

  • Long signal: Three consecutive bearish candles followed by one bullish reversal candle
  • Short signal: Three consecutive bullish candles followed by one bearish reversal candle

The reversal candle must have a sufficiently large body, set in the code as at least 3% body size, ensuring the reversal signal is strong enough

Entry occurs at the close of the reversal candle

The exit logic employs an ATR-based dynamic trailing take-profit mechanism:

  1. Calculates the 14-period ATR value to measure market volatility
  2. When price moves in a favorable direction by at least 1.5 times ATR, the trailing take-profit mechanism is activated
  3. If price retraces 1.0 times ATR from the most favorable position, an exit signal is triggered

Analysis of the code reveals that this strategy does not set a fixed stop-loss, but relies on a protection mechanism after profitability to manage risk. The strategy allows a maximum of 5 pyramid entries, uses 50% of account equity for each trade, and accounts for a 0.05% trading commission.

Strategy Advantages

  1. Precise reversal identification mechanism: The combination pattern of three consecutive same-direction candles plus a reversal candle improves the accuracy of identifying true reversals, reducing the occurrence of false signals.

  2. Dynamic adaptation to market volatility: Using ATR as a volatility indicator allows the strategy to automatically adapt to the volatility characteristics of different markets and periods without manual parameter adjustment.

  3. Intelligent capital protection mechanism: The protection mechanism is only activated after a trade achieves a certain profit, avoiding premature exits due to minor market fluctuations while securing profits when there's a retracement.

  4. Flexible position management: Supports pyramid-style position building, allowing for increased positions after trend confirmation, enhancing profit potential.

  5. Wide applicability: The strategy design is particularly effective in oscillating markets and trend reversal points, suitable for highly volatile markets such as cryptocurrencies, gold, and forex.

  6. Simple and adjustable parameters: Only requires setting minimum body percentage, ATR period length, and trailing take-profit parameters, making it easy to optimize and adapt to different market environments.

Strategy Risks

  1. No fixed stop-loss risk: The strategy does not set a traditional stop-loss point. Before the trailing take-profit is activated, continued adverse market movement could lead to significant losses. To address this risk, traders should consider adding an emergency stop-loss mechanism based on time or maximum loss percentage.

  2. Overtrading risk: Due to relatively loose entry conditions (only requiring 3 same-direction candles plus 1 reversal candle), too many trading signals may be generated in oscillating markets. This can be mitigated by adding additional filtering conditions, such as combining trend indicators or support/resistance levels to reduce unnecessary trades.

  3. Pyramid entry risk: The strategy supports up to 5 additional entries, which could lead to accumulated substantial losses if the market suddenly reverses. It is recommended to appropriately reduce the number of additional entries or set stricter conditions for adding positions based on personal risk tolerance.

  4. Market condition dependency: The strategy performs best in obvious oscillating markets or at the end of trends, but may frequently trigger false signals in strong trending markets. Consider adding trend filters to apply this strategy only in suitable market environments.

  5. Parameter sensitivity: Small changes in ATR multiplier parameters can significantly affect strategy performance, requiring comprehensive parameter optimization and backtesting for different markets and time frames.

Strategy Optimization Directions
Add trend filtering mechanism: Combine moving averages or ADX indicators to enter only when the trend direction is consistent with the reversal signal, improving win rate. This can be implemented by adding logic such as:

// Trend filter example
ema200 = ta.ema(close, 200)
adx = ta.adx(14)
inUptrend = close > ema200 and adx > 25
inDowntrend = close < ema200 and adx > 25
Enter fullscreen mode Exit fullscreen mode

Intelligent stop-loss mechanism: Add an initial stop-loss based on ATR to provide protection before the trailing take-profit is activated. For example:

// Initial stop-loss example
initialStopLoss = strategy.position_size > 0 ? longEntry - 2 * atr : 
                 strategy.position_size < 0 ? shortEntry + 2 * atr : na
Enter fullscreen mode Exit fullscreen mode

Add trading session filter: Volatility in certain markets may be excessive or insufficient during specific sessions, affecting strategy performance. A trading session filter can be added to trade only during optimal sessions.

Optimize reversal confirmation conditions: Consider combining volume or momentum indicators to strengthen the reliability of reversal signals. Ideally, reversal signals should be accompanied by increased volume or divergence in momentum indicators.

Dynamic parameter adjustment: Design a mechanism to automatically adjust ATR multiplier parameters based on market conditions to adapt to different market phases. For example, increase trailing distance during high volatility periods and decrease it during low volatility periods.

Add profit targets: In addition to trailing take-profits, set partial profit-taking points based on support/resistance levels or Fibonacci retracement levels to secure partial profits at important price levels.

Risk management optimization: Limit single trade risk to a fixed percentage of the account rather than consistently using 50% equity. This can be implemented as follows:

// Dynamic position size calculation
riskPerTrade = 1 // Risk 1% of account
posSize = (strategy.equity * riskPerTrade / 100) / (atr * 2)
Enter fullscreen mode Exit fullscreen mode

Summary
The ATR-Based Dynamic Trailing Take-Profit Three-Bar Reversal Quantitative Trading Strategy is an elegantly designed short-term reversal trading system that captures market turning points by identifying reversal patterns after three consecutive same-direction candles. Its most distinctive feature is the use of an ATR-based dynamic trailing take-profit mechanism, enabling the strategy to self-adapt to volatility characteristics under different market conditions, securing realized profits in a timely manner while retaining sufficient profit space.

This strategy is particularly suitable for application in oscillating markets and highly volatile market environments, such as cryptocurrency, gold, and forex markets. By incorporating the optimization suggestions proposed in this article, such as trend filtering, intelligent stop-loss, and dynamic parameter adjustment, traders can further enhance the stability and profitability of the strategy.

It should be noted that although this strategy has the ability to automatically adapt to market changes, traders still need to optimize and adjust parameters based on specific market characteristics and personal risk preferences. Before live implementation, it is recommended to conduct thorough historical backtesting and simulated trading to verify the strategy's performance under different market conditions.

Strategy source code

/*backtest
start: 2024-05-19 00:00:00
end: 2025-04-11 00:00:00
period: 5d
basePeriod: 5d
exchanges: [{"eid":"Futures_Binance","currency":"ETH_USDC"}]
*/

//@version=5
// ========================================================================
// 📌 CMA Technologies – 3-Bar Reversal Detection Bot (ATR Trailing TP)
// 🌐 Developed by CMA Technologies | Visit: cmatech.co
// 🔄 Short-term reversal entry with dynamic ATR-based trailing TP
// 🔍 Strategy by @CMATechnologies
// ========================================================================

strategy("CMA Technologies – 3-Bar Reversal Detection Bot", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=1, pyramiding=5, commission_type=strategy.commission.percent, commission_value=0.05)

// === INPUTS ===
minBodyPct     = input.float(3, title="Minimum Body Size (%)")
atrLen         = input.int(14, title="ATR Length")
trailStartATR  = input.float(1.5, title="Start Trailing After (x ATR)")
trailOffsetATR = input.float(1.0, title="Trailing Offset (x ATR)")

// === ATR ===
atr = ta.atr(atrLen)

// === FUNCTION ===
isBearish(closeVal, openVal) =>
    closeVal < openVal

isBullish(closeVal, openVal) =>
    closeVal > openVal

bodyPct(closeVal, openVal) =>
    math.abs(closeVal - openVal) / openVal * 100

// === CONDITIONS ===
bullishReversal = isBearish(close[3], open[3]) and isBearish(close[2], open[2]) and isBearish(close[1], open[1]) and isBullish(close, open) and bodyPct(close, open) > minBodyPct

bearishReversal = isBullish(close[3], open[3]) and isBullish(close[2], open[2]) and isBullish(close[1], open[1]) and isBearish(close, open) and bodyPct(close, open) > minBodyPct

// === ENTRY ===
if (bullishReversal)// and strategy.position_size == 0)
    strategy.entry("3Bar Long", strategy.long)

if (bearishReversal)// and strategy.position_size == 0)
    strategy.entry("3Bar Short", strategy.short)

// === ATR-BASED TRAILING TP ===
longEntry  = strategy.opentrades.entry_price(0)
shortEntry = strategy.opentrades.entry_price(0)

maxHigh = ta.highest(close, 20)
minLow  = ta.lowest(close, 20)

startTrailLong  = longEntry + trailStartATR * atr
startTrailShort = shortEntry - trailStartATR * atr

longTrailExit   = close < (maxHigh - trailOffsetATR * atr) and close > startTrailLong
shortTrailExit  = close > (minLow + trailOffsetATR * atr) and close < startTrailShort

if (strategy.position_size > 0 and longTrailExit)
    strategy.close("3Bar Long", comment="ATR Trailing TP Hit")

if (strategy.position_size < 0 and shortTrailExit)
    strategy.close("3Bar Short", comment="ATR Trailing TP Hit")

// === PLOTS ===
plotshape(bullishReversal, title="3-Bar Bull Reversal", location=location.belowbar, color=color.green, style=shape.triangleup, size=size.tiny)
plotshape(bearishReversal, title="3-Bar Bear Reversal", location=location.abovebar, color=color.red, style=shape.triangledown, size=size.tiny)
Enter fullscreen mode Exit fullscreen mode

Strategy parameters

Image description

The original address: ATR-Based Dynamic Trailing Take-Profit Three-Bar Reversal Quantitative Trading Strategy

Comments 1 total

  • Rebecca Chow
    Rebecca ChowJun 19, 2025

    This is a solid strategy combining ATR for dynamic exits and three-bar reversal for entries—great for trend-following with built-in risk control. I like how it adapts to volatility, but backtesting across different markets would be useful to confirm robustness. The trailing take-profit logic is clever, though slippage in fast markets could be a concern. Well-explained overall!

Add comment