Strategy vault / Machine learning
SMA and RSI Combination Trading Strategy
This strategy is based on Simple Moving Average (SMA) and Relative Strength Index (RSI) indicators. It goes short when RSI crosses above a defined entry level and closing price is below SMA, with trailing stop loss…
Overview
This strategy is based on Simple Moving Average (SMA) and Relative Strength Index (RSI) indicators. It goes short when RSI crosses above a defined entry level and closing price is below SMA, with trailing stop loss or RSI triggered stop loss. The strategy combines trend following and overbought/oversold indicators, aiming to capture reversal opportunities in medium-term timeframe.
Strategy Logic
Use SMA (200 periods) to determine the overall trend direction. Look for shorting opportunity when price is below SMA.
Use RSI (14 periods) to identify overbought/oversold conditions. RSI crossing above 51 signals increasing selling momentum, allowing entry for short.
After opening short position, set trailing stop loss at the lowest closing price. If RSI crosses above 54 or below 32, close position.
There are three types of stop loss: price stop, RSI stop and profit stop.
Strengths
Combining trend following and overbought/oversold indicators improves timing accuracy for entries.
Trailing stop loss can protect profits according to real-time price change, avoiding rigid stop loss.
RSI two-way trigger helps locking in profits and preventing excessive pullback losses.
Using simple indicators with fixed parameters makes it easy to implement for medium-term trading.
Risks
SMA and RSI parameters may not suit all products and timeframes, requiring optimization.
Trading costs like slippage and commissions are ignored, impacting actual PnL.
Other factors like volume and market structure are not considered, leading to unreliable signals.
Overly relying on indicators and ignoring price action itself may miss reversal timing.
Stop loss method is relatively rigid, unable to adapt to huge market changes.
Improvement
Test and optimize SMA period and RSI parameters to find best combination.
Consider adding volume indicator to avoid false breakout with low volume.
Test combinations with other indicators like MACD, Bollinger Bands etc.
Add machine learning algorithms, improving signal accuracy by training with historical data.
Optimize stop loss to be more flexible, adapting to market changes.
Add risk management to control single trade loss amount.
Conclusion
This strategy integrates the strengths of SMA and RSI indicators, filtering out some noisy trading opportunities. Its simple logic is easy to implement but still requires parameter and rules optimization, together with proper risk control to operate steadily in the long run. Combining with other indicators or algorithms is also worth exploring to further enhance the robustness.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_1 | 200 | SMA Length |
| v_input_2 | 14 | RSI Length |
| v_input_3 | 51 | RSI Entry Level |
| v_input_4 | 54 | RSI Stop Level |
| v_input_5 | 32 | RSI Take Profit Level |
Source Pine Script
/*backtest
start: 2022-10-01 00:00:00
end: 2023-10-07 00:00:00
period: 2d
basePeriod: 1d
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/
// © abdllhatn
//@version=5
// strategy("Alpha Short SMA and RSI Strategy", overlay=true, initial_capital=10000, default_qty_value=100)
// Inputs
sma_length = input(200, title="SMA Length")
rsi_length = input(14, title="RSI Length")
rsi_entry = input(51, title="RSI Entry Level")
rsi_stop = input(54, title="RSI Stop Level")
rsi_take_profit = input(32, title="RSI Take Profit Level")
// Indicators
sma_value = ta.sma(close, sma_length)
rsi_value = ta.rsi(close, rsi_length)
var float trailingStop = na
var float lastLow = na
// Conditions
shortCondition = ta.crossover(rsi_value, rsi_entry) and close < sma_value
if (shortCondition)
strategy.entry("Sell", strategy.short)
trailingStop := na
lastLow := na
if (strategy.position_size < 0)
if (na(lastLow) or close < lastLow)
lastLow := close
trailingStop := close
if not na(trailingStop) and close > trailingStop
strategy.close("Sell")
if (rsi_value >= rsi_stop)
strategy.close("Sell")
if (rsi_value <= rsi_take_profit)
strategy.close("Sell")
// Plot
plot(sma_value, color=color.red, linewidth=2)
Published by ChaoZhang on the FMZ strategy square · last modified 2023-10-08. 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/SMA-and-RSI-Combination-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
- EMA and RSI Quantitative Trading StrategyPine Script · Machine learning · 1h
- Triple Moving Average Combined with MACD Quantitative StrategyPine Script · Machine learning · 1d
- London MACD RSI Bitcoin Trading StrategyPine Script · Machine learning · 1m
- Multi indicator Assisted StrategyPine Script · Machine learning · 1d
- Market Structure Swing Trading StrategyPine Script · Machine learning · 1d
- ADX EFI 50 Moving Average Channel Pullback StrategyPine Script · Machine learning · 1h