
This strategy is a trading system based on the crossover of Exponential Moving Average (EMA) and Relative Strength Index (RSI). It determines entry and exit points through price-EMA crossovers and RSI overbought/oversold levels. The system incorporates comprehensive stop-loss and profit-taking mechanisms for effective risk management.
The strategy operates based on the following core logic: 1. Entry signals are generated based on price crossovers with offset EMA. A long signal occurs when price crosses above (EMA + offset); a short signal triggers when price crosses below (EMA - offset). 2. Exit mechanism includes two dimensions: fixed-point stop-loss and RSI-based profit-taking. Long positions are closed at RSI 70, while short positions are closed at RSI 28. 3. The system uses 68-period EMA for medium-term trend determination and 13-period RSI for short-term overbought/oversold identification.
The strategy combines classic technical indicators EMA and RSI to create a trading system featuring both trend-following and reversal characteristics. Its comprehensive risk control mechanisms and adjustable parameters ensure practical applicability. However, there remains room for improvement in parameter optimization and market adaptability, suggesting traders should conduct specific optimizations based on market characteristics during live implementation.
/*backtest
start: 2024-02-21 00:00:00
end: 2024-10-05 00:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Binance","currency":"ETH_USDT"}]
*/
//@version=5
strategy("EMA & RSI Custom Strategy", overlay=true)
// Input Parameters
emaLength = input.int(68, title="EMA Length")
rsiLength = input.int(13, title="RSI Period")
buyOffset = input.float(2, title="Buy Offset (above EMA)")
sellOffset = input.float(2, title="Sell Offset (below EMA)")
stopLossPoints = input.float(20, title="Stop Loss (points)")
buyRSIProfitLevel = input.int(70, title="Buy RSI Profit Level")
sellRSIProfitLevel = input.int(28, title="Sell RSI Profit Level")
// EMA and RSI Calculations
ema = ta.ema(close, emaLength)
rsi = ta.rsi(close, rsiLength)
// Buy Condition
buyPrice = ema + buyOffset
buyCondition = ta.crossover(close, buyPrice)
if buyCondition
strategy.entry("Buy", strategy.long)
// Stop Loss and Profit for Buy
if strategy.position_size > 0
if close <= strategy.position_avg_price - stopLossPoints
strategy.close("Buy", comment="Stop Loss")
if rsi >= buyRSIProfitLevel
strategy.close("Buy", comment="Profit Target")
// Sell Condition
sellPrice = ema - sellOffset
sellCondition = ta.crossunder(close, sellPrice)
if sellCondition
strategy.entry("Sell", strategy.short)
// Stop Loss and Profit for Sell
if strategy.position_size < 0
if close >= strategy.position_avg_price + stopLossPoints
strategy.close("Sell", comment="Stop Loss")
if rsi <= sellRSIProfitLevel
strategy.close("Sell", comment="Profit Target")
// Plot EMA
plot(ema, color=color.blue, title="EMA 68")