本策略通过计算RSI指标并设定超买超卖区间,结合动态止损和目标利润退出来构建交易策略。当RSI指标上穿超卖区间时做空,下穿超卖区间时做多,同时设定追踪止损和目标利润来退出仓位。
本策略使用14日RSI指标判断市场技术形态。RSI指标反映了一段时间内涨跌动量的比例,用于判断市场是超买还是超卖。本策略中的RSI长度为14。当RSI上穿70时市场被认为超买,这时做空;当RSI下穿30时市场被认为超卖,这时做多。
另外,本策略还使用了动态追踪止损机制。当持有多头仓位时,追踪止损价为收盘价的97%;当持有空头仓位时,追踪止损价为收盘价的103%。这样可以锁定大部分利润,同时避免止损被震出。
最后,本策略还使用目标利润机制。当持仓盈利达到20%时会退出仓位。这可以锁定部分利润,避免利润回吐。
本策略具有以下几个优势:
本策略也存在一些风险需要关注:
针对上述风险,可以通过优化RSI参数,调整止损幅度,适当放宽目标利润要求来解决。
本策略可以从以下几个方向进行优化:
本策略整体思路清晰,使用RSI指标判断超买超卖,配合动态止损和目标利润退出。优点是易于理解实现,风险控制到位,可扩展性强。下一步可以从提高信号质量、动态调整参数等方向进行优化,使策略更加智能化。
/*backtest
start: 2024-01-04 00:00:00
end: 2024-02-03 00:00:00
period: 4h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Modified RSI-Based Trading Strategy", overlay=true)
// RSI settings
rsiLength = input(14, title="RSI Length")
overboughtLevel = 70
oversoldLevel = 30
// User-defined parameters
trailingStopPercentage = input(3, title="Trailing Stop Percentage (%)")
profitTargetPercentage = input(20, title="Profit Target Percentage (%)")
rsiValue = ta.rsi(close, rsiLength)
var float trailingStopLevel = na
var float profitTargetLevel = na
// Entry criteria
enterLong = ta.crossover(rsiValue, oversoldLevel)
enterShort = ta.crossunder(rsiValue, overboughtLevel)
// Exit criteria
exitLong = ta.crossover(rsiValue, overboughtLevel)
exitShort = ta.crossunder(rsiValue, oversoldLevel)
// Trailing stop calculation
if (strategy.position_size > 0)
trailingStopLevel := close * (1 - trailingStopPercentage / 100)
if (strategy.position_size < 0)
trailingStopLevel := close * (1 + trailingStopPercentage / 100)
// Execute the strategy
if (enterLong)
strategy.entry("Buy", strategy.long)
if (exitLong or ta.crossover(close, trailingStopLevel) or ta.change(close) > profitTargetPercentage / 100)
strategy.close("Buy")
if (enterShort)
strategy.entry("Sell", strategy.short)
if (exitShort or ta.crossunder(close, trailingStopLevel) or ta.change(close) < -profitTargetPercentage / 100)
strategy.close("Sell")
// Plot RSI and overbought/oversold levels
plot(rsiValue, title="RSI", color=color.blue)
hline(overboughtLevel, "Overbought", color=color.red, linestyle=hline.style_dashed)
hline(oversoldLevel, "Oversold", color=color.green, linestyle=hline.style_dashed)