0bps

Strategy vault / Trend following

Dual Moving Average Crossover Combined with RSI Indicator Quantitative Trading Strategy

This strategy combines dual moving average crossover and RSI indicator to identify trend direction and overbought/oversold situations. It goes long when the buying conditions are met and closes positions when the…

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

IMG

Overview

This strategy combines dual moving average crossover and RSI indicator to identify trend direction and overbought/oversold situations. It goes long when the buying conditions are met and closes positions when the selling conditions are triggered. The goal is to use moving average crossover to determine trend direction while utilizing RSI indicator to avoid wrongly buying at tops and selling at bottoms, thus generating better profits.

Strategy Logic

When the fast 9-period moving average crosses above the slow 50-period moving average, it signals an uptrend in shorter timeframe overlapping with an uptrend in longer timeframe, which is a typical bullish signal. Meanwhile, if RSI is greater than the previous period by 5 points and less than 70, it means the asset is approaching but not yet in the overbought territory, making it a good timing to go long.

When the fast 9-period moving average crosses below the slow 50-period moving average, it signals the beginning of a bearish market and existing long positions should be closed.

Advantage Analysis

  • Dual moving averages help determine overall market direction and avoid false breakout
  • RSI indicator prevents wrong moves at turning points
  • Flexibility in adjusting moving average periods to suit different symbols and timeframes
  • Controllable stop loss strategy

Risk Analysis

  • Crossover signal may lag and cause some losses
  • Improper RSI parameter setting may miss best entry timing
  • Need to watch trading volume to see if it supports price move
  • Black swan events require manual intervention

Optimization Directions

  • Optimize RSI parameters for best results
  • Incorporate trading volume to avoid false signals
  • Test optimal moving average periods based on symbol and timeframe
  • Loosen stop loss to avoid being stopped out early

Summary

This strategy utilizes dual moving average crossover to determine direction and RSI to avoid chasing tops and bottoms. It can effectively ride medium- to long-term trends for steady profits. But the lagging nature of crossover signals and tuning of RSI parameters should be watched out for. Also need to correlate price with volume. With continuous testing and optimization, this strategy shows promise for even better results.

Parameters

NameDefaultWhat it controls
v_input_1trueShow Date Range
v_input_214length

Source Pine Script

/*backtest
start: 2022-11-14 00:00:00
end: 2023-11-20 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © joshuajcoop01

//@version=5
strategy("Bitpanda Coinrule Template",
         overlay=true,
         initial_capital=1000,
         process_orders_on_close=true,
         default_qty_type=strategy.percent_of_equity,
         default_qty_value=30,
         commission_type=strategy.commission.percent,
         commission_value=0.1)

showDate = input(defval=true, title='Show Date Range')
timePeriod = time >= timestamp(syminfo.timezone, 2020, 1, 1, 0, 0)
notInTrade = strategy.position_size <= 0


// RSI
length = input(14)
vrsi = ta.rsi(close, length)

// Moving  Averages for Buy Condition
buyFastEMA = ta.ema(close, 9)
buySlowEMA = ta.ema(close, 50)
buyCondition1 = ta.crossover(buyFastEMA, buySlowEMA)


increase = 5
if ((vrsi > vrsi[1]+increase) and buyCondition1 and vrsi < 70 and timePeriod)
    strategy.entry("Long", strategy.long)


// Moving  Averages for Sell Condition
sellFastEMA = ta.ema(close, 9)
sellSlowEMA = ta.ema(close, 50)
plot(request.security(syminfo.tickerid, "60", sellFastEMA), color = color.blue)
plot(request.security(syminfo.tickerid, "60", sellSlowEMA), color = color.green)


condition = ta.crossover(sellSlowEMA, sellFastEMA)
//sellCondition1 = request.security(syminfo.tickerid, "60", condition)

strategy.close('Long', when = condition and timePeriod)



Published by ChaoZhang on the FMZ strategy square · last modified 2023-11-21. 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/Dual-Moving-Average-Crossover-Combined-with-RSI-Indicator-Quantitative-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