0bps

Strategy vault / Trend following

Dynamic Stop Loss and Take Profit System Based on EMA Crossover with RSI ADX and Volume Confirmation

This strategy is a comprehensive trend following trading system that combines multiple technical indicators to confirm market trends and trading signals. The strategy uses EMA crossover as the primary trend…

Author
ChaoZhang
Complexity
Starter · 58 lines
Parameters
0
Backtest bar
3h · intraday
Tested on
BTC/USDT · futures

IMG

Overview

This strategy is a comprehensive trend following trading system that combines multiple technical indicators to confirm market trends and trading signals. The strategy uses EMA crossover as the primary trend identification tool, while integrating RSI, ADX, and volume indicators to filter trading signals, along with dynamic stop-loss and take-profit levels for risk management. This multi-faceted analysis approach can effectively improve trading accuracy and profitability.

Strategy Principles

The core logic of the strategy is based on the following key elements:

  1. Using 9-period and 21-period Exponential Moving Average (EMA) crossovers to determine trend direction
  2. Using 14-period Relative Strength Index (RSI) to measure market momentum
  3. Utilizing Average Directional Index (ADX) to confirm trend strength
  4. Incorporating 20-period volume moving average to verify price movements
  5. Employing a dynamic stop-loss (3%) and take-profit (5%) system based on entry price

Buy conditions require: EMA9 crosses above EMA21, RSI above 50, volume above average, ADX above 25 Sell conditions require any of: EMA9 crosses below EMA21, RSI below 50, volume below average (with ADX above 25)

Strategy Advantages

  1. Integration of multiple technical indicators provides more reliable trading signals
  2. Dynamic stop-loss and take-profit settings help automate risk management
  3. Inclusion of ADX ensures trading only in strong trends
  4. Volume confirmation increases signal reliability
  5. Strategy has good adaptability to different market environments

Strategy Risks

  1. Multiple indicators may cause missed trading opportunities
  2. False signals may occur in ranging markets
  3. Fixed percentage stop-loss and take-profit may not suit all market conditions
  4. Requires precise timing of trades Risk management recommendations:
  • Dynamically adjust stop-loss and take-profit percentages based on market volatility
  • Add minimum trend strength duration requirements
  • Consider adding volatility filters

Strategy Optimization Directions

  1. Introduce adaptive stop-loss and take-profit mechanisms based on market volatility
  2. Add trend persistence time requirements to avoid false breakouts
  3. Integrate market volatility indicators (like ATR) for position management
  4. Consider validating signals across different timeframes
  5. Add position sizing system based on signal strength

Summary

This is a well-designed trend following strategy that uses multiple technical indicators to improve trading reliability. The strategy's strengths lie in its comprehensive signal confirmation mechanism and risk management system, but attention must be paid to proper parameter optimization based on market conditions during practical application. Through the suggested optimization directions, both the strategy's stability and profitability can be further enhanced.

Source Pine Script

/*backtest
start: 2025-01-10 00:00:00
end: 2025-02-09 00:00:00
period: 3h
basePeriod: 3h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5
strategy("Estrategia Avançada - EMA, RSI, ADX e Volume", overlay=true)

// Parâmetros das EMAs
ema9 = ta.ema(close, 9)
ema21 = ta.ema(close, 21)

// RSI
rsi14 = ta.rsi(close, 14)

// Cálculo do ADX usando ta.dmi
[plusDI, minusDI, adx] = ta.dmi(14, 14)


// Volume com média
volume_ma = ta.sma(volume, 20)

// Critérios de Compra (Bullish)
buy_signal = ta.crossover(ema9, ema21) and rsi14 > 50 and volume > volume_ma and adx > 25

// Critérios de Venda (Bearish)
sell_signal = ta.crossunder(ema9, ema21) or rsi14 < 50 or volume < volume_ma and adx > 25

// Plotando indicadores no gráfico
plot(ema9, color=color.blue, linewidth=2, title="EMA 9")
plot(ema21, color=color.red, linewidth=2, title="EMA 21")
hline(50, "RSI 50", color=color.gray)

// Stop Loss e Take Profit dinâmicos
long_sl = strategy.position_avg_price * 0.97  // Stop Loss de 3%
long_tp = strategy.position_avg_price * 1.05  // Take Profit de 5%
short_sl = strategy.position_avg_price * 1.03 // Stop Loss de 3% para vendas
short_tp = strategy.position_avg_price * 0.95 // Take Profit de 5% para vendas

// Executando compra
if buy_signal
    strategy.close("Venda")  // Fecha posição de venda se existir
    strategy.entry("Compra", strategy.long)
    strategy.exit("TakeProfit", from_entry="Compra", limit=long_tp, stop=long_sl)

// Executando venda
if sell_signal
    strategy.close("Compra")  // Fecha posição de compra se existir
    strategy.entry("Venda", strategy.short)
    strategy.exit("TakeProfit", from_entry="Venda", limit=short_tp, stop=short_sl)

// Alertas configurados
alertcondition(buy_signal, title="Sinal de Compra", message="Hora de comprar!")
alertcondition(sell_signal, title="Sinal de Venda", message="Hora de vender!")

Published by ChaoZhang on the FMZ strategy square · last modified 2025-02-10. 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.

in Claude Code, Cursor, Codex & 4 more
/agenkit build a production-grade trading bot with a backtest engine, risk controls and paper trading by default from strategies/Dynamic-Stop-Loss-and-Take-Profit-System-Based-on-EMA-Crossover-with-RSI-ADX-and-Volume-Confirmation.md
  1. npx agenkit install engineering-kit in your project
  2. Paste the command into your agent and approve each phase
  3. 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

esc

Try , , or .

↑↓ move↵ open