Strategy vault / Mean reversion
RSI50_EMA Long Only Strategy
The strategy named "RSI50 EMA Long Only Strategy" mainly uses the crossover signals of two technical indicators, Relative Strength Index (RSI) and Exponential Moving Average (EMA), to make trading decisions. It opens…

Overview
The strategy named "RSI50_EMA Long Only Strategy" mainly uses the crossover signals of two technical indicators, Relative Strength Index (RSI) and Exponential Moving Average (EMA), to make trading decisions. It opens a long position when the price breaks above the upper band of EMA from below and RSI is above 50, and closes all long positions when the price breaks below the lower band of EMA from above or RSI falls below 50. This strategy only takes long positions and does not short, it is a trend-following strategy.
Strategy Principle
- Calculate EMA and ATR to get the upper and lower bands of EMA.
- Calculate RSI.
- When the closing price crosses above the upper band of EMA and RSI is above 50, open a long position.
- When the closing price crosses below the lower band of EMA or RSI falls below 50, close all long positions.
- Only long, no short.
Strategy Advantages
- Suitable for use in a strong market, can effectively capture the upward trend of strong stocks.
- Uses both EMA and RSI indicators to better confirm trend signals and improve signal reliability.
- Position management uses percentage stop loss, risk is controllable.
- The code logic is clear and simple, easy to understand and implement.
Strategy Risks
- Prone to frequent trading and large drawdowns in volatile markets.
- Improper parameter selection can lead to signal failure. For example, improper selection of EMA length will lead to lagging trend judgment; improper selection of RSI upper and lower limits will lead to undesirable entry and exit points.
- The strategy can only capture unilateral upward trends, and cannot grasp downward and oscillating trends, easy to miss opportunities.
Strategy Optimization Directions
- Introduce trend confirmation indicators, such as MACD, to improve the accuracy of trend judgment.
- Optimize parameters for RSI, or introduce RSI divergence and other improvements to signals.
- Consider adding trailing stop loss or volatility stop loss to improve risk control.
- Consider adding reversal entry logic in oscillating markets and downward trends.
Summary
The RSI50_EMA Long Only Strategy is a simple and easy-to-use trend-following strategy based on RSI and EMA, suitable for use in unilateral upward trends. The strategy has clear logic and obvious advantages, but also has some shortcomings and risks. By introducing more auxiliary indicators, optimizing parameters, improving risk control and other measures, the stability and profitability of the strategy can be further improved. However, in actual application, it is necessary to flexibly adjust and improve according to market characteristics, personal risk preferences and other factors.
Source Pine Script
/*backtest
start: 2023-05-05 00:00:00
end: 2024-05-10 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=4
strategy("RSI50_EMA Long Only Strategy", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100)
len = input(11, type=input.integer, minval=1, title="Length")
mul = input(2, type=input.float, minval=0, title="Multiplier")
rsicap = input(50, type=input.integer, minval=1, title="rsicap")
rsi_1 = rsi(close,20)
price = sma(close, 2)
average = ema(close, len)
diff = atr(len) * mul
bull_level = average + diff
bear_level = average - diff
bull_cross = crossover(price, bull_level)
RENTRY = crossover(rsi_1,rsicap)
bear_cross = crossover(bear_level, price)
EXIT = crossunder(rsi_1,50)
strategy.entry("Buy", strategy.long, when=bull_cross)
strategy.close("Buy", when=bear_cross) //strategy.entry("Sell", strategy.short, when=bear_cross)
if (RENTRY)
strategy.entry("RSI", strategy.long, when=bull_cross)
if (EXIT)
strategy.close("RSICLose", when=bull_cross) //strategy.entry("Sell", strategy.short, when=bear_cross)
plot(price, title="price", color=color.black, transp=50, linewidth=2)
a0 = plot(average, title="average", color=color.red, transp=50, linewidth=1)
a1 = plot(bull_level, title="bull", color=color.green, transp=50, linewidth=1)
a2 = plot(bear_level, title="bear", color=color.red, transp=50, linewidth=1)
fill(a0, a1, color=color.green, transp=97)
fill(a0, a2, color=color.red, transp=97)
Published by ChaoZhang on the FMZ strategy square · last modified 2024-05-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.
/agenkit build a production-grade trading bot with a backtest engine, risk controls and paper trading by default from strategies/RSI50_EMA-Long-Only-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
- Customizable Non Repainting HTF MACD MFI Scalable Bot StrategyPine Script · Mean reversion · 1d
- Dynamic Adaptive Multi Timeframe Trend Following and Range Reversal Hybrid StrategyPine Script · Mean reversion · 2d
- MACD Cross Period Trading StrategyPine Script · Mean reversion · 1d
- CCTBBO Reversal Tracking StrategyPine Script · Mean reversion · 45m
- Multi Indicator Weighted Smart Trading StrategyPine Script · Mean reversion · 2d
- MACD RSI and EMA StrategyPine Script · Mean reversion · 1d