0bps

Strategy vault / Momentum

Multi Period Moving Average and RSI Momentum Cross Trend Following Strategy

This strategy is a comprehensive trading system that combines multiple-period moving averages, RSI overbought/oversold signals, and price pattern recognition. The strategy primarily generates trading signals by…

Author
ChaoZhang
Complexity
Starter · 55 lines
Parameters
0
Backtest bar
1d · swing
Tested on
BTC/USDT · futures

IMG

Overview

This strategy is a comprehensive trading system that combines multiple-period moving averages, RSI overbought/oversold signals, and price pattern recognition. The strategy primarily generates trading signals by identifying market trend turning points through the intersection of fast and slow moving averages, RSI indicator's overbought/oversold zones, and bullish/bearish engulfing patterns. The strategy employs percentage-based position management, using 10% of account equity by default for each trade, which helps achieve better risk control.

Strategy Principles

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

  1. Moving Average System: Uses 9-period and 21-period Simple Moving Averages (SMA) as fast and slow lines to determine trend direction through crossovers.
  2. RSI Momentum Indicator: Employs 14-period RSI with 70 as overbought and 30 as oversold levels to confirm price momentum.
  3. Price Pattern Recognition: Programmatically identifies bullish and bearish engulfing patterns as auxiliary trading signals.
  4. Signal Integration: Buy signals require fast MA crossing above slow MA with RSI in oversold zone or bullish engulfing pattern; sell signals require fast MA crossing below slow MA with RSI in overbought zone or bearish engulfing pattern.

Strategy Advantages

  1. Multi-dimensional Signal Confirmation: Combines technical indicators and price patterns to improve signal reliability.
  2. Comprehensive Risk Control: Uses account percentage position sizing to effectively control risk per trade.
  3. Trend Following Capability: Effectively captures medium to long-term trends through the moving average system.
  4. Signal Visualization: Provides clear graphical interface including moving averages, RSI indicator, and trade signal markers.
  5. Flexible Parameter Settings: Allows adjustment of MA periods, RSI parameters, etc., to adapt to different market conditions.

Strategy Risks

  1. Choppy Market Risk: May generate frequent false breakout signals in sideways markets.
  2. Lag Risk: Moving averages are inherently lagging indicators, potentially missing optimal entry points.
  3. Parameter Sensitivity: Optimal parameters may vary significantly across different market environments.
  4. Pattern Recognition Accuracy: Programmatically identified patterns may deviate from actual market patterns.

Strategy Optimization Directions

  1. Introduce Volatility Filtering: Recommend adding ATR indicator to filter trading signals in low volatility environments.
  2. Optimize Stop Loss Mechanism: Can implement dynamic stop losses based on ATR for more flexible risk control.
  3. Add Market Environment Analysis: Introduce trend strength indicators to use different parameter combinations in different market conditions.
  4. Improve Position Management: Can dynamically adjust position size based on signal strength and market volatility.
  5. Add Time Filtering: Consider market time characteristics to avoid trading during specific time periods.

Summary

This is a well-designed, logically sound comprehensive technical analysis trading strategy. By combining multiple technical indicators and price patterns, the strategy achieves reliable signal generation while maintaining good risk control. Although it has some inherent limitations, the strategy's overall performance can be further improved through the suggested optimization directions. Users need to pay attention to parameter optimization and market environment adaptation in practical applications to achieve optimal trading results.

Source Pine Script

/*backtest
start: 2019-12-23 08:00:00
end: 2024-12-04 00:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5
strategy("Comprehensive Trading Strategy", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=10)

// Input parameters for moving averages
fastLength = input.int(9, title="Fast MA Length")
slowLength = input.int(21, title="Slow MA Length")
rsiLength = input.int(14, title="RSI Length")
rsiOverbought = input.int(70, title="RSI Overbought Level")
rsiOversold = input.int(30, title="RSI Oversold Level")

// Calculate moving averages
fastMA = ta.sma(close, fastLength)
slowMA = ta.sma(close, slowLength)

// Calculate RSI
rsi = ta.rsi(close, rsiLength)

// Detect price action patterns (e.g., engulfing patterns)
isBullishEngulfing = close > open and close[1] < open[1] and open < close[1] and close > open[1]
isBearishEngulfing = close < open and close[1] > open[1] and open > close[1] and close < open[1]

// Define conditions for buying and selling
buyCondition = ta.crossover(fastMA, slowMA) and rsi < rsiOversold or isBullishEngulfing
sellCondition = ta.crossunder(fastMA, slowMA) and rsi > rsiOverbought or isBearishEngulfing

// Execute buy and sell orders
if (buyCondition)
    strategy.entry("Buy", strategy.long)

if (sellCondition)
    strategy.entry("Sell", strategy.short)

// Plotting
plot(fastMA, color=color.blue, linewidth=2, title="Fast MA")
plot(slowMA, color=color.orange, linewidth=2, title="Slow MA")
hline(rsiOverbought, "RSI Overbought", color=color.red)
hline(rsiOversold, "RSI Oversold", color=color.green)
plot(rsi, color=color.purple, linewidth=1, title="RSI")

// Alert conditions
alertcondition(buyCondition, title="Buy Signal", message="Price meets buy criteria")
alertcondition(sellCondition, title="Sell Signal", message="Price meets sell criteria")

// Plot signals on chart
plotshape(series=buyCondition ? low : na, location=location.belowbar, color=color.green, style=shape.triangleup, size=size.small, title="Buy Signal")
plotshape(series=sellCondition ? high : na, location=location.abovebar, color=color.red, style=shape.triangledown, size=size.small, title="Sell Signal")

Published by ChaoZhang on the FMZ strategy square · last modified 2024-12-05. 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/Multi-Period-Moving-Average-and-RSI-Momentum-Cross-Trend-Following-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