0bps

Strategy vault / Trend following

RSI MA Trend Following Strategy

This strategy is named "RSI-MA Trend Following Strategy". The idea is to use both the RSI indicator and MA lines to judge price trends and generate trading signals. Trading signals are generated when the RSI…

Author
ChaoZhang
Complexity
Starter · 46 lines
Parameters
5
Backtest bar
1h · intraday
Tested on
BTC/USDT · futures

IMG

Overview

This strategy is named "RSI-MA Trend Following Strategy". The idea is to use both the RSI indicator and MA lines to judge price trends and generate trading signals. Trading signals are generated when the RSI indicator exceeds the pre-set upper and lower thresholds, while the MA lines are used to filter out false signals, only issuing signals when prices continue to rise or fall. This allows maintaining decent profit potential while effectively filtering out range-bound price movements.

Strategy Logic

The core components of this strategy are the RSI indicator and MA lines. The RSI is used to identify overbought and oversold levels, while the MA is used to determine trend directionality. The specific logic is:

  1. Calculate the RSI indicator value, and set the upper threshold at 90 and lower threshold at 10. An RSI reading above 90 signifies an overbought signal, while a reading below 10 signifies an oversold signal.

  2. Calculate the MA line of a certain period (e.g. 4 days). When prices are continuously rising, the MA line tilts upwards. When prices are falling continuously, the MA line tilts downwards.

  3. When the RSI exceeds 90 and the MA line tilts upwards, go short. When the RSI drops below 10 and the MA line tilts downwards, go long.

  4. Set stop loss at a fixed number of points per contract, and take profit at a fixed percentage per contract.

Advantage Analysis

This strategy combines the dual filters of RSI indicator and MA lines, which can effectively filter out false signals under range-bound price moves. Meanwhile, the RSI settings avoid delayed signals and maintain decent profit potential. Using the MA to determine trend directionality prevents trading against the trend. In addition, the strategy has simple parameters that are easy to comprehend and optimize.

Risk Analysis

Main risks of this strategy include:

  1. Sudden events that cause sharp price spikes may not be reflected timely in RSI and MA readings, leading to larger losses.

  2. Under range-bound markets, RSI and MA may frequently issue signals, resulting in overly frequent trading that increases transaction costs and slippage.

  3. Improper parameter settings can also impact strategy performance. For example, RSI upper/lower thresholds set too wide lead to signal delays, while thresholds set too narrow lead to too frequent signals.

Optimization Directions

Areas for further optimization include:

  1. Backtest and optimize parameters over different products and timeframes to find the optimal parameter combinations.

  2. Incorporate other indicators alongside RSI/MA, such as KDJ, BOLL etc, to set more stringent signal filters and reduce false signals.

  3. Build adaptive stop loss/take profit mechanisms based on volatility and ATR to dynamically adjust price levels.

  4. Add machine learning algorithms to auto-adjust parameters based on changing market conditions, realizing dynamic parameter optimization.

Conclusion

Overall this RSI-MA strategy is fairly simple and practical, combining elements of trend following and overbought/oversold analysis. It can achieve decent profits given favorable market conditions, but also carries risks of false signals that need to be reduced via further optimizations to improve robustness.

Parameters

NameDefaultWhat it controls
v_input_14Length
v_input_25rsin
v_input_315TP
v_input_423SL
v_input_5falseTS

Source Pine Script

/*backtest
start: 2023-11-10 00:00:00
end: 2023-12-10 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=2
//This strategy is best used with the Chrome Extension AutoView for automating TradingView alerts.
//You can get the AutoView extension for FREE using the following link
//https://chrome.google.com/webstore/detail/autoview/okdhadoplaoehmeldlpakhpekjcpljmb?utm_source=chrome-app-launcher-info-dialog
strategy("4All", shorttitle="Strategy", overlay=false)

src = close
len = input(4, minval=1, title="Length")

up = rma(max(change(src), 0), len)
down = rma(-min(change(src), 0), len)
rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))
plot(rsi, color=purple)
band1 = hline(90)
band0 = hline(10)
fill(band1, band0, color=purple, transp=90)

rsin = input(5)
sn = 100 - rsin
ln = 0 + rsin

short = crossover(rsi, sn)
long = crossunder(rsi, ln)

strategy.entry("long", strategy.long, when=long)
strategy.entry("short", strategy.short, when=short)

TP = input(15) * 10
SL = input(23) * 10
TS = input(0) * 10
CQ = 100

TPP = (TP > 0) ? TP : na
SLP = (SL > 0) ? SL : na
TSP = (TS > 0) ? TS : na

strategy.exit("Close Long", "long", qty_percent=CQ, profit=TPP, loss=SLP, trail_points=TSP)
strategy.exit("Close Short", "short", qty_percent=CQ, profit=TPP, loss=SLP, trail_points=TSP)

Published by ChaoZhang on the FMZ strategy square · last modified 2023-12-11. 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/RSI-MA-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