Strategy vault / Machine learning
SMA RSI Sudden Buy Sell Strategy
This strategy mainly uses the average value of RSI and sudden price changes to identify market trend and reversal points. The core idea is to consider establishing positions when RSI is overbought or oversold, and…

Overview
This strategy mainly uses the average value of RSI and sudden price changes to identify market trend and reversal points. The core idea is to consider establishing positions when RSI is overbought or oversold, and look for reversal opportunities when sudden price changes occur. EMA is also used as a filter.
Principles
Calculate the SMA of RSI. When RSI SMA crosses above 60 or falls below 40, it is considered overbought or oversold, and reverse positions will be considered.
When the change of RSI exceeds a certain value, it is regarded as a sudden change. Combined with the actual close price verification, it serves as a signal to establish reverse position.
Use multiple EMAs for filtering. Only when price crosses above shorter period EMA, long position will be considered. Only when price falls below shorter period EMA, short position will be considered.
By combining the use of RSI average, sudden changes and EMA filtering, better entry points can be identified.
Advantage Analysis
Using RSI average can accurately judge overbought and oversold conditions, which is conducive to capturing reversal opportunities.
Sudden changes often signify shifts in price trend and direction, using this signal can improve the timeliness of entries.
Multi-level EMA filtering can further avoid false signals and reduce unnecessary losses.
The combination of multiple parameters as decision criteria can enhance the stability and reliability of the strategy.
Risks and Mitigations
RSI performance may be unstable and SMA hit rate may be low. RSI parameters can be optimized or other indicators can replace it.
Sudden changes could just be short-term fluctuations rather than true reversals. Increase sensing cycle length to improve judgment accuracy.
There is lag in EMA direction filtering. Test shorter period EMAs to improve sensitivity.
In general, this strategy is quite sensitive to parameter tuning. Careful tests are needed to find optimum parameter combinations. Use stop loss to control risks.
Optimization Suggestions
Test other indicators like ADX, MACD combined with RSI to find better entry points.
Increase machine learning algorithms to judge the authenticity and stability of sudden buy/sell signals.
Further enhance EMA direction filtering such as using composite judgment of different period EMAs.
Add adaptive stop loss strategy to dynamically adjust stop loss range based on market volatility.
Continue parameter optimization to find optimum parameter combinations. Evaluation criteria could be Sharpe Ratio etc.
Conclusion
This strategy firstly uses RSI average to determine overbought/oversold conditions. Reverse positions are then established when sudden changes occur. EMA is also used as an auxiliary filter. With proper parameter settings, this strategy can effectively determine market trend shifts. Overall speaking, it has good stability and practical value. There is still room for further improvement, requiring persistent testing and optimization.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_1 | 14 | length |
| v_input_2 | 10 | inst_length |
| v_input_3 | 10 | bars |
| v_input_int_1 | 20 | lookbackno2 |
| v_input_int_2 | 20 | input_ema20 |
| v_input_int_3 | 50 | input_ema50 |
| v_input_int_4 | 100 | input_ema100 |
| v_input_int_5 | 200 | input_ema200 |
| v_input_int_6 | 400 | input_ema400 |
| v_input_int_7 | 800 | input_ema800 |
| v_input_4 | 40 | over40 |
| v_input_5 | 60 | over60 |
Source Pine Script
/*backtest
start: 2023-12-12 00:00:00
end: 2023-12-19 00:00:00
period: 3m
basePeriod: 1m
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/
// © samwillington
//@version=5
strategy("sma RSI & sudden buy and sell Strategy v1", overlay=true)
price = close
length = input( 14 )
inst_length = input( 10 )
var rbc = 0
var float rsiBP = 0.0
var rsc = 0
var float rsiSP = 0.0
bars = input(10)
lookbackno2 = input.int(20)
rsi_buy = 0
rsi_sell = 0
//EMA inputs
input_ema20 = input.int(20)
ema20 = ta.ema(price, input_ema20)
input_ema50 = input.int(50)
ema50 = ta.ema(price, input_ema50)
input_ema100 = input.int(100)
ema100 = ta.ema(price, input_ema100)
input_ema200 = input.int(200)
ema200 = ta.ema(price, input_ema200)
input_ema400 = input.int(400)
ema400 = ta.ema(price, input_ema400)
input_ema800 = input.int(800)
ema800 = ta.ema(price, input_ema800)
vrsi = ta.rsi(price, length)
hi2 = ta.highest(price, lookbackno2)
lo2 = ta.lowest(price, lookbackno2)
buy_diff_rsi = vrsi - ta.rsi(close[1], length)
sell_diff_rsi = ta.rsi(close[1],length) - vrsi
//RSI high low
var int sudS = 0
var int sudB = 0
var float sudSO = 0.0
var float sudSC = 0.0
var float sudBO = 0.0
var float sudBC = 0.0
var sudBuy = 0
var sudSell = 0
var countB = 0
var countS = 0
var co_800 = false
var co_400 = false
var co_200 = false
var co_100 = false
var co_50 = false
var co_20 = false
co_800 := ta.crossover(price , ema800)
co_400 := ta.crossover(price , ema400)
co_200 := ta.crossover(price , ema200)
co_100 := ta.crossover(price , ema100)
co_50 := ta.crossover(price , ema50)
co_20 := ta.crossover(price , ema20)
if(ta.crossunder(price , ema20))
co_20 := false
if(ta.crossunder(price , ema50))
co_50 := false
if(ta.crossunder(price , ema100))
co_100 := false
if(ta.crossunder(price , ema200))
co_200 := false
if(ta.crossunder(price , ema400))
co_400 := false
if(ta.crossunder(price , ema800))
co_800 := false
if((price> ema800) and (price > ema400))
if(co_20)
if(co_50)
if(co_100)
if(co_200)
strategy.close("Sell")
strategy.entry("Buy", strategy.long, comment="spl Buy")
co_20 := false
co_50 := false
co_100 := false
co_200 := false
// too much rsi
if(vrsi > 90)
strategy.close("Buy")
strategy.entry("Sell", strategy.short, comment="RSI too overbuy")
if(vrsi < 10)
strategy.close("Sell")
strategy.entry("Buy", strategy.long, comment="RSI too oversold")
var sudbcount = 0 // counting no. of bars till sudden rise
var sudscount = 0 // counting no. of bars till sudden decrease
if(sudB == 1)
sudbcount := sudbcount + 1
if(sudS == 1)
sudscount := sudscount + 1
if((buy_diff_rsi > inst_length) and (hi2 > price))
sudB := 1
sudBO := open
sudBC := close
if((sell_diff_rsi > inst_length) )
sudS := 1
sudSO := open
sudSC := close
if(sudbcount == bars)
if(sudBC < price)
strategy.close("Sell")
strategy.entry("Buy", strategy.long, comment="sudd buy")
sudbcount := 0
sudB := 0
sudbcount := 0
sudB := 0
if(sudscount == bars)
if(sudSC > price)
strategy.close("Buy")
strategy.entry("Sell", strategy.short, comment="sudd sell")
sudscount := 0
sudS := 0
sudscount := 0
sudS := 0
over40 = input( 40 )
over60 = input( 60 )
sma =ta.sma(vrsi, length)
coo = ta.crossover(sma, over60)
cuu = ta.crossunder(sma, over40)
if (coo)
strategy.close("Sell")
strategy.entry("Buy", strategy.long, comment="modified buy")
if (cuu)
strategy.close("Buy")
strategy.entry("Sell", strategy.short, comment="modefied sell")
//plot(strategy.equity, title="equity", color=color.red, linewidth=2, style=plot.style_areabr)Published by ChaoZhang on the FMZ strategy square · last modified 2023-12-20. 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-RSI-Sudden-Buy-Sell-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
- Triple Moving Average Combined with MACD Quantitative StrategyPine Script · Machine learning · 1d
- ADX EFI 50 Moving Average Channel Pullback StrategyPine Script · Machine learning · 1h
- Multi indicator Combination StrategyPine Script · Machine learning · 1d
- EMA and RSI Quantitative Trading StrategyPine Script · Machine learning · 1h
- MACD Robot Trading StrategyPine Script · Machine learning · 1d
- Multi Indicator Dynamic Adaptive Quantitative Trading StrategyPine Script · Machine learning · 1h