Strategy vault / Trend following
Dynamic QQE Trend Following with Risk Management Quantitative Trading Strategy
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…

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
- Stable and reliable signal system: QQE indicator combines the advantages of RSI and EMA, effectively filtering market noise
- Comprehensive risk management: Dynamically adjusts stop-loss and take-profit levels through ATR, adapting to market volatility changes
- Scientific capital management: Automatically adjusts positions based on account size, preventing excessive losses
- Trailing stop mechanism: Ensures profit locking when trends reverse
- Visual support: Strategy provides trend area filling and other visual effects for analysis
Strategy Risks
- Choppy market risk: May generate frequent false breakout signals in sideways markets
- Slippage risk: May face significant slippage during high market volatility
- Parameter sensitivity: Strategy performance is sensitive to various parameter settings
- Systematic risk: May face significant drawdowns during extreme market volatility
Strategy Optimization Directions
- Add market environment filtering: Can add volatility indicators to judge current market conditions
- Optimize signal confirmation mechanism: Enhance signal reliability by combining other technical indicators
- Improve stop-loss mechanism: Consider adding time-based and volatility-based stops
- 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.
Source Pine Script
/*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")Published by ChaoZhang on the FMZ strategy square · last modified 2025-01-17. 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/Dynamic-QQE-Trend-Following-with-Risk-Management-Quantitative-Trading-Strategy.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
- Adaptive ATR and RSI Trend Following Strategy with Trailing Stop LossPine Script · Trend following · 1h
- Bollinger Bands and RSI Trend Following StrategyPine Script · Trend following · 1h
- Dual ATR Channel Trend Following StrategyPine Script · Trend following · 15m
- Dual Mode Adaptive Trend Trading Strategy EMA Crossover with ATR Volatility Based Risk Management SystemPine Script · Trend following · 1d
- Dynamic Dual EMA Crossover Strategy with Adaptive Profit Loss ControlPine Script · Trend following · 1d
- Dynamic Multi Timeframe ATR Crossover Strategy Optimizing Trend Following and Risk Management with Flexible ParametersPine Script · Trend following · 1h