Momentum Indicator Driven Trend Following Trading Strategy
This strategy builds trading signals based on momentum indicator RSI and price's Exponential Moving Average (EMA) and Simple Moving Average (SMA). It belongs to the trend following type of strategies.

Overview
This strategy builds trading signals based on momentum indicator RSI and price's Exponential Moving Average (EMA) and Simple Moving Average (SMA). It belongs to the trend following type of strategies.
Strategy Principle
The strategy uses 3 conditions to generate trading signals:
- RSI > 45: RSI value greater than 45 is considered a good buy signal
- EMA(RSI) > SMA(RSI): EMA line greater than SMA line indicates RSI is accelerating upwards, which is a good momentum signal
- EMA(close) > SMA(close): EMA line greater than SMA line indicates the price trend is accelerating upwards
Meeting any 2 of the above 3 conditions generates a buy signal; if none is met, a sell signal is generated.
The strategy also provides an "always buy" mode for testing the system's performance relative to the broad market.
Advantage Analysis
- Using momentum indicator RSI to judge market conditions can reduce positions during market fluctuations
- Combining EMA and SMA to determine trend direction can timely capture price change trends
- Simple and clear conditional rules, easy to understand and optimize
- Provides "always buy" mode to test system advantages
Risk Analysis
- Relies on parameter settings, improper parameters will lead to frequent trading or miss good trading opportunities
- Major news in the broad market can cause huge volatility in the short term, which will lead to stop loss
- The strategy itself cannot judge when a trend is about to reverse, other indicators need to be used to determine
Optimization Directions
- Optimize parameters of RSI, EMA and SMA to find best parameter combination
- Increase other technical indicators like Volume, MACD etc. to enrich rule conditions
- Increase trend reversal indicators to reduce probability of losses
Conclusion
In summary, this strategy belongs to a medium-frequency trading strategy that aims to capture mid-term price trends while avoiding short-term market fluctuations. Its advantages and risk points are quite obvious. Further enhancing stability through parameter optimization and enriching rules makes it a worthwhile high-efficiency quantitative trading strategy to research and optimize.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_string_1 | Unitrend | Trading Mode |
| v_input_bool_1 | false | compoundingMode |
| v_input_float_1 | true | leverage |
| v_input_float_2 | true | Risk Capital per Trade unleveraged (%) |
| v_input_float_3 | 2 | TPFactor |
Source Pine Script
/*backtest
start: 2022-12-05 00:00:00
end: 2023-12-11 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("I11L Unitrend",overlay=false, initial_capital=1000000,default_qty_value=1000000,default_qty_type=strategy.cash,commission_type=strategy.commission.percent,commission_value=0.00)
tradingMode = input.string("Unitrend", "Trading Mode", ["Unitrend", "Always Buy"], tooltip="Choose the Trading Mode by trying Both in your Backtesting. I use it if one is far better then the other one.")
compoundingMode = input.bool(false)
leverage = input.float(1.0,step=0.1)
SL_Factor = 1 - input.float(1,"Risk Capital per Trade unleveraged (%)", minval=0.1, maxval=100, step=0.1) / 100
TPFactor = input.float(2, step=0.1)
var disableAdditionalBuysThisDay = false
var lastTrade = time
if(time > lastTrade + 1000 * 60 * 60 * 8 or tradingMode == "Always Buy")
disableAdditionalBuysThisDay := false
if(strategy.position_size != strategy.position_size[1])
lastTrade := time
disableAdditionalBuysThisDay := true
//Trade Logic
SCORE = 0
//rsi momentum
RSIFast = ta.ema(ta.rsi(close,50),24)
RSISlow = ta.sma(ta.rsi(close,50),24)
RSIMomentum = RSIFast / RSISlow
goodRSIMomentum = RSIMomentum > 1
SCORE := goodRSIMomentum ? SCORE + 1 : SCORE
//rsi trend
RSITrend = RSISlow / 45
goodRSI = RSITrend > 1
SCORE := goodRSI ? SCORE + 1 : SCORE
//price trend
normalTrend = ta.ema(close,50) / ta.sma(close,50)
goodTrend = normalTrend > 1
SCORE := goodTrend ? SCORE + 1 : SCORE
isBuy = SCORE > 1 or tradingMode == "Always Buy"
isSell = false //SCORE == 0
//plot(SCORE, color=isBuy ? color.green : #ffffff88)
//reduced some of the values just for illustrative purposes, you can buy after the signal if the trendlines seem to grow
plot(1, color=isBuy ? #77ff7733 : SCORE == 2 ? #ffff0033 : SCORE == 1 ? #ff888833 : #ff000033,linewidth=10)
plot(1 - (1 - RSIMomentum) * 6,color=#00F569)
plot(1 - (1 - RSITrend) * 0.25,color=#00DB9B)
plot(1 - (1 - normalTrend) * 20,color=#00F5EE)
strategy.initial_capital = 50000
if(isBuy and not(disableAdditionalBuysThisDay))
if(compoundingMode)
strategy.entry("Long", strategy.long, (strategy.equity / close) * leverage)
else
strategy.entry("Long", strategy.long, (strategy.initial_capital / close) * leverage)
if(strategy.position_size != 0)
strategy.exit("TP/SL Long", "Long", stop=strategy.position_avg_price * (1 - (1 - SL_Factor)), limit=strategy.position_avg_price * (1 + (1 - SL_Factor) * TPFactor))
Published by ChaoZhang on the FMZ strategy square · last modified 2023-12-12. 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.
/agenkit build a production-grade trading bot with a backtest engine, risk controls and paper trading by default from strategies/Momentum-Indicator-Driven-Trend-Following-Trading-Strategy.md- npx agenkit install engineering-kit in your project
- Paste the command into your agent and approve each phase
- 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
- KST EMA Momentum Trend Following StrategyPine Script · Momentum · 1d
- MACD Momentum Indicator Backtest StrategyPine Script · Momentum · 1h
- MoonFlag MACD Momentum StochRSI Trading StrategyPine Script · Momentum · 1d
- Multi Indicator Trend Momentum Trading Strategy with Dynamic Risk Management SystemPine Script · Momentum · 1h
- Multi factor Adaptive Momentum Tracking StrategyPine Script · Momentum · 3m
- Dual Momentum Oscillator Smart Timing Trading StrategyPine Script · Momentum · 1h