该策略是一个基于指数移动平均线(EMA)和相对强弱指数(RSI)的交叉交易系统。策略通过价格与EMA的交叉以及RSI指标的超买超卖水平来确定入场和出场时机。系统设计了完整的止损和获利机制,能够有效控制风险。
策略主要依据以下核心逻辑运作: 1. 入场信号基于价格与偏移EMA的交叉。当价格向上穿越(EMA + 偏移值)时产生做多信号;当价格向下穿越(EMA - 偏移值)时产生做空信号。 2. 出场机制包含两个维度:固定点数止损和基于RSI的获利了结。做多持仓在RSI达到70时获利了结,做空持仓在RSI达到28时获利了结。 3. 系统采用68周期EMA作为中期趋势判断指标,13周期RSI作为短期超买超卖判断指标。
该策略通过结合EMA和RSI两个经典技术指标,构建了一个兼具趋势跟踪和反转特征的交易系统。完善的风险控制机制和可调参数设计使其具有良好的实用性。然而,策略的参数优化和市场适应性仍有提升空间,建议交易者在实盘应用时结合市场特征进行针对性优化。
/*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")