Dual-Period Volatility-Adjusted Breakout Trading System with Dynamic Position Sizing and Pyramiding Strategy
FMZQuant

FMZQuant @fmzquant

Joined:
Apr 25, 2024

Dual-Period Volatility-Adjusted Breakout Trading System with Dynamic Position Sizing and Pyramiding Strategy

Publish Date: Jun 19
2 1

Image description

Image description

Overview
The Dual-Period Volatility-Adjusted Breakout Trading System is a quantitative strategy based on the famous Turtle Trading rules, utilizing two different time periods (20-day and 55-day) to capture market breakouts while incorporating volatility indicators for dynamic position management. This system integrates trend following, breakout trading, volatility-adjusted position sizing, and pyramiding techniques to effectively capture medium to long-term market trends. The core logic involves entering the market when prices break through previous highs or lows, calculating reasonable position sizes using volatility (ATR), implementing pyramiding for adding to winning positions, and finally exiting through short-period reverse breakouts. This strategy is particularly suitable for asset classes with pronounced trend characteristics, such as gold.

Strategy Principles
Analyzing the code reveals that the core principles of this strategy include:

  1. Dual-Period Breakout Entry: The strategy employs two entry systems - System 1 uses 20-day high/low breakouts as the primary entry signal; System 2 is activated after a losing trade, using 55-day high/low breakouts as entry signals. This design automatically adjusts entry sensitivity according to market conditions.

  2. Volatility Measurement and Position Management: The strategy uses 20-day Average True Range (ATR) as a measure of market volatility, calculating appropriate position size through the formula: Unit Size = Risk Amount / (N * Point Value). The risk amount equals account equity multiplied by the set risk percentage (default 1%). This method ensures consistent risk exposure across different volatility environments.

  3. Pyramiding Mechanism: When the price of an existing profitable position continues to move in a favorable direction (by at least 0.5N distance), the strategy allows adding new units of the same size. This pyramiding approach can expand profit potential in strong trending markets.

  4. Short-Period Reverse Breakout Exit: The strategy uses 10-day lows/highs as exit signals for long/short positions. When the price breaks below the 10-day low, all long positions are closed; when the price breaks above the 10-day high, all short positions are closed.

  5. System Switching Mechanism: The strategy automatically adjusts the entry system based on trading results. If a trade in a particular direction results in a loss, the next trade in the same direction will use System 2 (55-day period); after a profitable trade, it reverts to using System 1 (20-day period).

Through the combined application of these principles, the strategy can enter trends early, add positions with the trend, and exit at the beginning of trend reversals, effectively capturing medium to long-term market trends.

Strategy Advantages
Through in-depth analysis of the code, we can summarize the following main advantages of this strategy:

  1. Mechanical Trading Decisions: The strategy executes trades based entirely on quantitative rules, eliminating emotional interference and ensuring strict execution of trading discipline. The code clearly defines entry, pyramiding, and exit conditions without requiring subjective judgment.

  2. Dynamic Risk Management: By limiting each trade's risk to a fixed percentage of account equity (default 1%) and adjusting position size with ATR, the strategy maintains consistent risk exposure across different volatility environments. This method automatically reduces position size in high-volatility markets and appropriately increases it in low-volatility markets.

  3. Adaptive Market Conditions: The dual-period design allows the strategy to automatically adjust to market conditions. It uses a shorter period (20-day) in trending markets with consecutive profits to maintain sensitivity; after experiencing losses, it switches to a longer period (55-day) to reduce false signals.

  4. Compounding Growth Mechanism: The strategy calculates position size based on current account equity, automatically increasing positions as the account grows, achieving a compounding effect; meanwhile, the pyramiding mechanism expands profit potential in strong trends.

  5. Multi-Market Adaptability: The strategy design is applicable to multiple asset classes, performing particularly well in markets with obvious trend characteristics such as gold. Parameters can be adjusted to optimize for different market characteristics.

  6. Clear Risk Control: Using 10-day reverse breakouts as exit signals provides clear stop-loss points for each trade, effectively controlling individual trade risk; simultaneously, setting a maximum risk percentage controls systemic risk.

Strategy Risks
Despite its many advantages, this strategy still has the following potential risks:

  1. False Breakout Risk: In oscillating markets, prices may frequently break through highs/lows but quickly retreat, leading to consecutive losses. The code lacks mechanisms to filter false breakouts, potentially generating many ineffective signals in non-trending markets.

  2. Pyramiding Risk Amplification: The pyramiding mechanism is very effective when trends continue, but if trends suddenly reverse, multiple unit positions may result in significant losses. Although the strategy sets exit conditions, it may still suffer substantial losses during dramatic reversals.

  3. Parameter Sensitivity: Strategy performance is highly dependent on various parameter settings (entry period, exit period, ATR period, pyramiding spacing, etc.). Different market environments may require different parameter combinations, and fixed parameters may lead to unstable performance.

  4. Liquidity Risk: In markets with poor liquidity, extensive pyramiding may increase slippage or make it difficult to execute at expected prices, affecting actual implementation. The code lacks mechanisms to address liquidity issues.

  5. Systemic Risk Exposure: As a pure trend-following strategy, it may exhibit high correlation with other trend strategies during general market declines or periods of dramatic volatility, making it difficult to provide diversification protection.

  6. Calculation Precision Issues: The code uses the math.floor function to round down position calculations, which may result in positions being too small or unable to trade in small accounts. Additionally, improper point value settings may lead to position calculation errors.

To address these risks, consider adding trend filters, setting maximum position limits, optimizing pyramiding rules, and incorporating volatility adjustment mechanisms for risk control.

Optimization Directions
Based on code analysis, this strategy has several potential optimization directions:

  1. Add Trend Filters: The current strategy trades purely based on price breakouts, making it susceptible to false breakouts. Adding trend indicators (such as moving averages, ADX, etc.) as filtering conditions to execute trades only when trend direction is consistent would reduce losing trades in oscillating markets.

  2. Optimize Pyramiding Rules: The existing pyramiding mechanism is relatively simple. Consider introducing decreasing pyramiding ratios (gradually reducing subsequent unit sizes) or setting maximum pyramiding limits to balance expanding returns with risk control.

  3. Dynamic Parameter Adjustment: Parameters for entry/exit periods and pyramiding spacing could be dynamically adjusted based on market volatility or trend strength. For example, extending entry periods in high-volatility markets and shortening exit periods in low-volatility markets would make the strategy more adaptive.

  4. Add Time Filters: Incorporate trading time filter conditions to avoid major economic data releases or periods of poor liquidity, reducing risks from abnormal volatility.

  5. Multi-Timeframe Confirmation: Combine longer timeframe trend directions as trading filter conditions, such as executing trades only when daily and 4-hour trends align, to improve signal quality.

  6. Optimize Money Management: Introduce more complex money management models, such as the Kelly formula or optimal f-value method, to dynamically adjust risk percentages based on expected win rates and profit/loss ratios, further optimizing the equity growth curve.

  7. Add Profit-Taking Mechanisms: The current strategy only has exit mechanisms based on reverse breakouts. Consider adding partial profit locking mechanisms, such as closing part of a position when specific profit targets are reached, to balance trend capturing with profit protection.

These optimization directions can effectively enhance the strategy's stability and profitability, particularly its adaptability across different market environments.

Summary
The Dual-Period Volatility-Adjusted Breakout Trading System is a complete quantitative trading strategy based on Turtle Trading rules, integrating breakout entries, volatility position management, pyramiding, and adaptive periods. The strategy captures trends through price breakouts, controls risk exposure using volatility, and maximizes trend returns through pyramiding.

The core value of this strategy lies in its comprehensive system design, covering entry, exit, position management, and risk control aspects to form a self-consistent trading system. Particularly noteworthy are its volatility-adjusted position mechanism and dual-period adaptive design, allowing the strategy to maintain relatively stable performance across different market environments.

However, as a trend-following strategy, its performance may be poor in oscillating markets, requiring improvement through trend filters, optimized pyramiding rules, and dynamic parameter adjustments. Additionally, this strategy is best used as part of an investment portfolio, combined with other types of strategies (such as mean-reversion strategies) to achieve a smoother return curve.

Overall, this is a well-designed, logically clear quantitative trading strategy with a solid theoretical foundation and practical value. With appropriate parameter optimization and supplementary mechanisms, this strategy has the potential to generate stable returns across various market environments.

Strategy source code

/*backtest
start: 2024-06-16 00:00:00
end: 2025-06-15 00:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"DOGE_USDT"}]
*/

//@version=5
strategy("Turtle Trading System (Full Version)", overlay=true, pyramiding=1, default_qty_type=strategy.cash, default_qty_value=1)

// === User Inputs ===
riskPercent = input.float(1.0, title="Risk % of Equity per Trade", minval=0.1, maxval=5.0, step=0.1)
pointValue = input.float(1.0, title="Point Value ($/point)")
entryPeriod1 = input.int(20, title="System 1 Entry Period")
entryPeriod2 = input.int(55, title="System 2 Entry Period (after loss)")
exitPeriod = input.int(10, title="Exit Period")
nPeriod = input.int(20, title="N Period (ATR)")
pyramidSpacing = input.float(0.5, title="Add Units Every N x ...", step=0.1)

// === Volatility Measure (N) ===
N = ta.atr(nPeriod)

// === Donchian Channels ===
entryHigh1 = ta.highest(high, entryPeriod1)
entryLow1 = ta.lowest(low, entryPeriod1)
entryHigh2 = ta.highest(high, entryPeriod2)
entryLow2 = ta.lowest(low, entryPeriod2)

exitLong = ta.lowest(low, exitPeriod)
exitShort = ta.highest(high, exitPeriod)

// === Account & Sizing ===
equity = strategy.equity
riskDollars = equity * (riskPercent / 100)
unitSize = riskDollars / (N * pointValue)
positionSize = math.floor(unitSize)

// === Trade Management Flags ===
var bool lastLongLoss = false
var bool lastShortLoss = false

// === Entry Conditions ===
useSystem1Long = close > entryHigh1[1]
useSystem2Long = lastLongLoss and close > entryHigh2[1]

useSystem1Short = close < entryLow1[1]
useSystem2Short = lastShortLoss and close < entryLow2[1]

// === Exit Conditions ===
longExit = close < exitLong
shortExit = close > exitShort

// === Pyramiding Entries ===
var float lastLongEntryPrice = na
var float lastShortEntryPrice = na
canAddLong = strategy.opentrades > 0 and strategy.position_size > 0 and close >= lastLongEntryPrice + (pyramidSpacing * N)
canAddShort = strategy.opentrades > 0 and strategy.position_size < 0 and close <= lastShortEntryPrice - (pyramidSpacing * N)
// === Execute Entries ===
if (useSystem1Long or useSystem2Long)
    strategy.entry("Long", strategy.long, qty=positionSize)
    lastLongEntryPrice := close
    lastLongLoss := false

if (useSystem1Short or useSystem2Short)
    strategy.entry("Short", strategy.short, qty=positionSize)
    lastShortEntryPrice := close
    lastShortLoss := false

if (canAddLong)
    strategy.entry("Long Add", strategy.long, qty=positionSize)
    lastLongEntryPrice := close

if (canAddShort)
    strategy.entry("Short Add", strategy.short, qty=positionSize)
    lastShortEntryPrice := close

// === Exits ===
if (longExit)
    strategy.close("Long")
    strategy.close("Long Add")
    lastLongLoss := close < lastLongEntryPrice

if (shortExit)
    strategy.close("Short")
    strategy.close("Short Add")
    lastShortLoss := close > lastShortEntryPrice

// === Plotting ===
plot(entryHigh1, title="20-Day High", color=color.green)
plot(entryLow1, title="20-Day Low", color=color.red)
plot(entryHigh2, title="55-Day High", color=color.lime, linewidth=1)
plot(entryLow2, title="55-Day Low", color=color.maroon, linewidth=1)
plot(exitLong, title="10-Day Low (Exit Long)", color=color.orange)
plot(exitShort, title="10-Day High (Exit Short)", color=color.blue)

Enter fullscreen mode Exit fullscreen mode

Strategy parameters

Image description

The original address: Dual-Period Volatility-Adjusted Breakout Trading System with Dynamic Position Sizing and Pyramiding Strategy

Comments 1 total

  • Rebecca Chow
    Rebecca ChowJun 19, 2025

    Volatility-adjusted breakouts and dynamic position sizing? Somebody’s out here playing 4D chess with the markets! 🎲 Love the idea of pyramiding in—because why make money linearly when you can do it exponentially (or blow up gloriously)? Just wondering: does this system come with a built-in stress ball for those 'false breakout' moments? Solid logic, but my emotions demand a 'rage quit' override button. 😂 Seriously though, great mix of aggression and risk control—would backtest before YOLO-ing!

Add comment