资源加载中... loading...

Dynamic QQE Trend Following with Risk Management Quantitative Trading Strategy

Author: ChaoZhang, Date: 2025-01-17 14:43:11
Tags: RSIQQEATRWWMAEMAATRRSIQQEFQQES

 Dynamic QQE Trend Following with Risk Management Quantitative Trading Strategy

Overview

This strategy is a trend following system based on the QQE (Quick Quiet Exponent) indicator, combined with dynamic risk management mechanisms. The core of the strategy captures market trends through crossovers of QQE fast and slow lines, while using ATR (Average True Range) to dynamically adjust stop-loss and take-profit levels for optimized risk-reward configuration. The strategy also includes account risk management and position control features that automatically adjust position sizes based on account equity.

Strategy Principles

The strategy consists of three core modules: signal generation, risk management, and position control. The signal generation module is based on the QQE indicator, calculating the fast line (QQEF) through the exponential moving average (EMA) of RSI, and combining ATRRSI to calculate the slow line (QQES). Long signals are generated when QQEF crosses above QQES, and short signals when it crosses below. The risk management module uses ATR to dynamically calculate stop-loss and take-profit levels, applying trailing stops to protect profits. The position control module calculates position sizes based on preset risk percentages and current account equity.

Strategy Advantages

  1. Stable and reliable signal system: QQE indicator combines the advantages of RSI and EMA, effectively filtering market noise
  2. Comprehensive risk management: Dynamically adjusts stop-loss and take-profit levels through ATR, adapting to market volatility changes
  3. Scientific capital management: Automatically adjusts positions based on account size, preventing excessive losses
  4. Trailing stop mechanism: Ensures profit locking when trends reverse
  5. Visual support: Strategy provides trend area filling and other visual effects for analysis

Strategy Risks

  1. Choppy market risk: May generate frequent false breakout signals in sideways markets
  2. Slippage risk: May face significant slippage during high market volatility
  3. Parameter sensitivity: Strategy performance is sensitive to various parameter settings
  4. Systematic risk: May face significant drawdowns during extreme market volatility

Strategy Optimization Directions

  1. Add market environment filtering: Can add volatility indicators to judge current market conditions
  2. Optimize signal confirmation mechanism: Enhance signal reliability by combining other technical indicators
  3. Improve stop-loss mechanism: Consider adding time-based and volatility-based stops
  4. Increase position management flexibility: Dynamically adjust risk coefficients based on different market states

Summary

This strategy transforms the QQE indicator into a complete trading system, achieving an organic combination of trend following and risk management. The strategy design is reasonable, with strong practicality and scalability. Through proper parameter optimization and risk control, this strategy can maintain stable performance in various market environments. Traders are recommended to conduct thorough backtesting and parameter optimization before live trading.


/*backtest
start: 2024-12-17 00:00:00
end: 2025-01-16 00:00:00
period: 3h
basePeriod: 3h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT","balance":49999}]
*/

// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © seckinduran
//@version=5
strategy("QQE Strategy with Risk Management", overlay=true)

// Girdi Parametreleri
src = input(close, title="Source")
length = input.int(14, title="RSI Length", minval=1)
SSF = input.int(5, title="SF RSI Smoothing Factor", minval=1)
riskPercentage = input.float(1.0, title="Risk Percentage per Trade", minval=0.1, maxval=10.0)

// Trailing Stop ve Stop Loss Parametreleri
stopLossMultiplier = input.float(title="Stop Loss Katsayısı", defval=1.5)
takeProfitMultiplier = input.float(title="Take Profit Katsayısı", defval=3)
trailStopMultiplier = input.float(title="Trailing Stop Katsayısı", defval=1.5)

// QQE Hesaplamaları
RSII = ta.ema(ta.rsi(src, length), SSF)
TR = math.abs(RSII - RSII[1])
wwalpha = 1 / length
WWMA = ta.ema(TR, length)
ATRRSI = ta.ema(WWMA, length)

QQEF = ta.ema(ta.rsi(src, length), SSF)
QUP = QQEF + ATRRSI * 4.236
QDN = QQEF - ATRRSI * 4.236

QQES = 0.0
QQES := QUP < nz(QQES[1]) ? QUP : QQEF > nz(QQES[1]) and QQEF[1] < nz(QQES[1]) ? QDN : QDN > nz(QQES[1]) ? QDN : QQEF < nz(QQES[1]) and QQEF[1] > nz(QQES[1]) ? QUP : nz(QQES[1])

// Çizgileri Görselleştirme
plot(QQEF, "FAST", color=color.maroon, linewidth=2)
plot(QQES, "SLOW", color=color.blue, linewidth=1)

// Alım ve Satım Koşulları
longCondition = ta.crossover(QQEF, QQES)  // Hızlı çizgi yavaş çizgiyi yukarı keserse
shortCondition = ta.crossunder(QQEF, QQES)  // Hızlı çizgi yavaş çizgiyi aşağı keserse

// ATR Hesaplaması
atrValue = ta.atr(14)  // ATR hesaplaması burada

// Pozisyon Büyüklüğü Hesaplama
tradeSize = strategy.equity / close
riskSize = (strategy.equity * riskPercentage / 100) / close
leverageSize = math.max(1, riskSize)  // Negatif değerleri engellemek için doğrulama

// Pozisyon Açma
if (longCondition)
    strategy.entry("Buy", strategy.long, qty=leverageSize, stop=close - (atrValue * stopLossMultiplier), limit=close + (atrValue * takeProfitMultiplier), comment="Long Entry")

if (shortCondition)
    strategy.entry("Sell", strategy.short, qty=leverageSize, stop=close + (atrValue * stopLossMultiplier), limit=close - (atrValue * takeProfitMultiplier), comment="Short Entry")

// Çıkış Koşulları: Trailing Stop
if (strategy.position_size > 0)
    strategy.exit("Trail Exit Long", from_entry="Buy", trail_price=close - atrValue * trailStopMultiplier, trail_offset=atrValue * stopLossMultiplier, limit=close + atrValue * takeProfitMultiplier)
if (strategy.position_size < 0)
    strategy.exit("Trail Exit Short", from_entry="Sell", trail_price=close + atrValue * trailStopMultiplier, trail_offset=atrValue * stopLossMultiplier, limit=close - atrValue * takeProfitMultiplier)

// Pozisyon Kapatma Koşulları
if (ta.crossunder(close, QQES))
    strategy.close("Buy")  // Long pozisyonu kapat
if (ta.crossover(close, QQEF))
    strategy.close("Sell")  // Short pozisyonu kapat

// Ekstra Görselleştirme (Trend Renkleri)
longFillColor = QQEF > QQES ? color.new(color.green, 80) : na
shortFillColor = QQEF < QQES ? color.new(color.red, 80) : na

fill(plot1=plot(QQEF, display=display.none), plot2=plot(QQES, display=display.none), color=longFillColor, title="Uptrend Fill")
fill(plot1=plot(QQEF, display=display.none), plot2=plot(QQES, display=display.none), color=shortFillColor, title="Downtrend Fill")

Related

More