
La estrategia es un sistema de seguimiento de tendencias basado en el indicador QQE (Quick Quiet Exponent), combinado con un mecanismo dinámico de gestión de riesgos. El núcleo de la estrategia es capturar las tendencias del mercado a través de la intersección de la línea rápida y la línea lenta de QQE, y utilizar ATR (rango verdadero promedio) para ajustar dinámicamente las posiciones de stop loss y take profit para lograr una configuración óptima de riesgo-retorno. La estrategia también incluye funciones de gestión de riesgos de cuenta y control de posiciones, que pueden ajustar automáticamente el número de posiciones abiertas en función del capital de la cuenta.
La estrategia incluye principalmente tres módulos principales: generación de señales, gestión de riesgos y control de posición. El módulo de generación de señales se basa en el indicador QQE. Calcula la media móvil exponencial (EMA) del RSI para obtener la línea rápida (QQEF) y calcula la línea lenta (QQES) en combinación con ATRRSI. Cuando QQEF cruza QQES hacia arriba, se genera una señal larga, y cuando cruza hacia abajo, se genera una señal corta. El módulo de gestión de riesgos utiliza ATR para calcular dinámicamente las posiciones de stop loss y take profit, y aplica un mecanismo de trailing stop loss para proteger las ganancias. El módulo de control de posiciones calcula el número de posiciones abiertas en función del porcentaje de riesgo preestablecido y del capital actual de la cuenta.
Esta estrategia realiza la combinación orgánica de seguimiento de tendencias y gestión de riesgos al transformar el indicador QQE en un sistema comercial completo. La estrategia está diseñada razonablemente y tiene gran viabilidad y escalabilidad. Mediante una optimización razonable de parámetros y un control de riesgos, la estrategia puede mantener un rendimiento estable en diversos entornos de mercado. Se recomienda que los traders realicen pruebas retrospectivas suficientes y optimicen los parámetros cuando lo utilicen en operaciones reales.
/*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")