Strategy vault / Machine learning
Dynamic Neural RSI Trend Following Trading Strategy
This strategy is a quantitative trading system based on moving averages, RSI indicator, and trailing stop loss. It combines trend following and momentum indicators from technical analysis, achieving risk-controlled…

Overview
This strategy is a quantitative trading system based on moving averages, RSI indicator, and trailing stop loss. It combines trend following and momentum indicators from technical analysis, achieving risk-controlled trading through strict entry and exit conditions. The core logic is to seek oversold opportunities in uptrends and protect profits using trailing stops.
Strategy Principles
The strategy uses a 200-day Simple Moving Average (SMA) as the baseline for trend judgment, combined with the Relative Strength Index (RSI) for generating trading signals. Specifically:
- Uses 200-day SMA to judge the major trend, only considering long positions when price is above the average
- Identifies oversold signals when RSI falls below preset threshold (default 40)
- Triggers long entry when both conditions are met and waiting period since last exit (default 10 days) has elapsed
- Protects profits during position holding through trailing stop loss (default 5%)
- Exits position when price breaks below trailing stop or 200-day SMA
Strategy Advantages
- Combines trend and momentum double filtering to improve trading accuracy
- Uses trailing stop mechanism to effectively lock in profits
- Sets trading intervals to avoid frequent trading
- Strong parameter adjustability to adapt to different market environments
- Clear trading logic, easy to understand and execute
- Simple calculations with high computational efficiency
Strategy Risks
- Moving average lag may cause delayed entry and exit signals
- RSI indicator may generate false signals in ranging markets
- Fixed percentage trailing stop may not suit all market environments
- Parameter optimization may lead to overfitting
- May suffer significant drawdowns in highly volatile markets
Strategy Optimization Directions
- Introduce volatility-adaptive trailing stop percentage
- Add volume indicators as auxiliary confirmation
- Replace simple moving average with exponential moving average for better sensitivity
- Incorporate market sentiment indicators to optimize trading timing
- Develop dynamic parameter optimization mechanism
- Add multi-timeframe strategy confirmation mechanism
Summary
This is a quantitative trading strategy with complete structure and clear logic. It pursues stable returns while controlling risk by combining multiple technical indicators. Although there is room for optimization, the basic framework has good practicality and extensibility. The strategy is suitable for medium to long-term investors and adapts well to different market environments.
Source Pine Script
/*backtest
start: 2025-01-09 00:00:00
end: 2025-01-16 00:00:00
period: 15m
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT","balance":49999}]
*/
//@version=5
strategy("200 SMA Crossover Strategy", overlay=false)
// Define inputs
smaLength = input.int(200, title="SMA Length")
rsiLength = input.int(14, title="RSI Length")
rsiThreshold = input.float(40, title="RSI Threshold")
trailStopPercent = input.float(5.0, title="Trailing Stop Loss (%)")
waitingPeriod = input.int(10, title="Waiting Period (Days)")
// Calculate 200 SMA
sma200 = ta.sma(close, smaLength)
// Calculate RSI
rsi = ta.rsi(close, rsiLength)
// Plot the 200 SMA and RSI
plot(sma200, color=color.blue, linewidth=2, title="200 SMA")
plot(rsi, color=color.purple, title="RSI", display=display.none)
// Define buy and sell conditions
var isLong = false
var float lastExitTime = na
var float trailStopPrice = na
// Explicitly declare timeSinceExit as float
float timeSinceExit = na(lastExitTime) ? na : (time - lastExitTime) / (24 * 60 * 60 * 1000)
canEnter = na(lastExitTime) or timeSinceExit > waitingPeriod
buyCondition = close > sma200 and rsi < rsiThreshold and canEnter
if (buyCondition and not isLong)
strategy.entry("Buy", strategy.long)
trailStopPrice := na
isLong := true
// Update trailing stop loss if long
if (isLong)
trailStopPrice := na(trailStopPrice) ? close * (1 - trailStopPercent / 100) : math.max(trailStopPrice, close * (1 - trailStopPercent / 100))
// Check for trailing stop loss or sell condition
if (isLong and (close < trailStopPrice or close < sma200))
strategy.close("Buy")
lastExitTime := time
isLong := false
// Plot buy and sell signals
plotshape(series=buyCondition, title="Buy Signal", location=location.belowbar, color=color.green, style=shape.labelup, text="BUY")
plotshape(series=(isLong and close < trailStopPrice) or close < sma200, title="Sell Signal", location=location.abovebar, color=color.red, style=shape.labeldown, text="SELL")
Published by ChaoZhang on the FMZ strategy square · last modified 2025-01-17. 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/Dynamic-Neural-RSI-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
- AI Driven Dynamic Volatility Adaptive Trend Breakout Trading StrategyPine Script · Machine learning · 2d
- 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
- Triple Moving Average Combined with MACD Quantitative StrategyPine Script · Machine learning · 1d
- kNN based Trend Following StrategyPine Script · Machine learning · 1h