0bps

Strategy vault / Momentum

Dynamic Trend Momentum Trading Strategy

This strategy combines multiple indicators such as EMA, MACD, VWAP, and RSI to capture high-probability trading opportunities. It uses EMA to determine the trend direction, MACD for momentum, VWAP for volume, and RSI…

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

IMG

Overview

This strategy combines multiple indicators such as EMA, MACD, VWAP, and RSI to capture high-probability trading opportunities. It uses EMA to determine the trend direction, MACD for momentum, VWAP for volume, and RSI for overbought and oversold conditions. The strategy generates buy and sell signals based on a combination of these indicators while using a trailing stop loss to protect profits.

Strategy Principles

  1. EMA is used to determine the trend direction. When the price is above the EMA, it is considered an uptrend, and when below, it is considered a downtrend.
  2. MACD is used to gauge momentum. When the MACD fast line crosses above the slow line, momentum is considered to be turning bullish, and when it crosses below, momentum is considered to be turning bearish.
  3. VWAP is used to assess volume. When the price is above VWAP, buying pressure is considered to be stronger than selling pressure, and when below, selling pressure is considered to be stronger.
  4. RSI is used to determine overbought and oversold conditions. When RSI is above 70, it is considered overbought, and when below 30, it is considered oversold.
  5. A buy signal is generated when the price is above the EMA, the MACD fast line crosses above the slow line, the price is above VWAP, and RSI is below the overbought level.
  6. A sell signal is generated when the price is below the EMA, the MACD fast line crosses below the slow line, the price is below VWAP, and RSI is above the oversold level.
  7. Position size is calculated based on account equity and risk percentage.
  8. A trailing stop loss is used to protect profits, with the stop loss price moving along with the price.

Strategy Advantages

  1. The combination of multiple indicators provides a more comprehensive assessment of market conditions, improving the accuracy of trading signals.
  2. The use of a trailing stop loss helps protect profits during trend continuation and reduces drawdowns.
  3. Calculating position size based on account equity and risk percentage allows for control over the risk of each trade.
  4. Parameters can be adjusted according to user preferences, enhancing the flexibility of the strategy.

Strategy Risks

  1. In choppy markets, frequent trading signals may lead to overtrading and commission losses.
  2. During trend reversals, the trailing stop loss may not exit positions quickly enough, leading to larger drawdowns.
  3. Parameter selection needs to be optimized for different markets and instruments, and inappropriate parameters may lead to poor strategy performance.

Strategy Optimization Directions

  1. Consider adding more filtering conditions, such as volume and volatility, to further improve signal accuracy.
  2. Consider using more dynamic stop loss methods, such as ATR stop loss, to better adapt to different market conditions.
  3. Consider optimizing parameters using methods like genetic algorithms to find the optimal parameter combination.
  4. Consider incorporating position sizing and money management strategies to better control risk and enhance returns.

Summary

This strategy combines multiple indicators to assess market conditions and generate trading signals while using a trailing stop loss to protect profits. Strategy parameters can be adjusted according to user preferences, enhancing the flexibility of the strategy. However, the strategy may perform poorly in choppy markets and face larger drawdowns during trend reversals, so it needs to be optimized and improved for different markets and instruments. Future optimizations can consider adding more filtering conditions, dynamic stop loss methods, parameter optimization, and position sizing to improve the stability and profitability of the strategy.

Source Pine Script

/*backtest
start: 2024-04-01 00:00:00
end: 2024-04-30 23:59:59
period: 4h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5
strategy("Intraday Strategy", overlay=true)

// Input parameters
emaLength = input.int(50, title="EMA Length")
macdShort = input.int(12, title="MACD Short Period")
macdLong = input.int(26, title="MACD Long Period")
macdSignal = input.int(9, title="MACD Signal Period")
rsiLength = input.int(14, title="RSI Length")
rsiOverbought = input.int(70, title="RSI Overbought Level")
rsiOversold = input.int(30, title="RSI Oversold Level")
risk = input.float(1, title="Risk Percentage", minval=0.1, step=0.1)
trailOffset = input.float(0.5, title="Trailing Stop Offset", minval=0.1, step=0.1)

// Calculating indicators
ema = ta.ema(close, emaLength)
[macdLine, signalLine, _] = ta.macd(close, macdShort, macdLong, macdSignal)
rsi = ta.rsi(close, rsiLength)
vwap = ta.vwap(close)

// Entry conditions
longCondition = ta.crossover(macdLine, signalLine) and close > ema and rsi < rsiOverbought and close > vwap
shortCondition = ta.crossunder(macdLine, signalLine) and close < ema and rsi > rsiOversold and close < vwap

// Exit conditions
longExitCondition = ta.crossunder(macdLine, signalLine) or close < ema
shortExitCondition = ta.crossover(macdLine, signalLine) or close > ema

// Position sizing based on risk percentage
capital = strategy.equity
positionSize = (capital * (risk / 100)) / close

// Executing trades
if (longCondition)
    strategy.entry("Long", strategy.long, qty=1)
if (shortCondition)
    strategy.entry("Short", strategy.short, qty=1)

if (longExitCondition)
    strategy.close("Long")
if (shortExitCondition)
    strategy.close("Short")

// Trailing stop loss
if (strategy.position_size > 0)
    strategy.exit("Trailing Stop Long", from_entry="Long", trail_price=close, trail_offset=trailOffset)
if (strategy.position_size < 0)
    strategy.exit("Trailing Stop Short", from_entry="Short", trail_price=close, trail_offset=trailOffset)

// Plotting indicators
plot(ema, title="EMA", color=color.blue)
hline(rsiOverbought, "Overbought", color=color.red)
hline(rsiOversold, "Oversold", color=color.green)
plot(rsi, title="RSI", color=color.purple)
plot(vwap, title="VWAP", color=color.orange)

Published by ChaoZhang on the FMZ strategy square · last modified 2024-05-23. 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-Trend-Momentum-Trading-Strategy.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