MACD和RSI指标融合的震荡市场交易策略


创建日期: 2023-09-13 15:14:43 最后修改: 2023-09-13 15:14:43
复制: 0 点击次数: 624
avatar of ChaoZhang ChaoZhang
1
关注
1362
关注者

本策略名称为“MACD和RSI指标融合的震荡市场交易策略”。该策略专门针对最近较为扩张的加密货币震荡盘整市场而设计,通过结合趋势指标MACD和动量指标RSI形成交易信号。

MACD为指数移动平均线差值,可以判断市场趋势和趋势反转。当MACD的快线上穿慢线时产生买入信号;而快线下穿慢线时产生卖出信号。

RSI为相对强弱指数,判断市场超买超卖情况。RSI高于50表示超买,低于50表示超卖。本策略采用RSI指标来过滤MACD指标产生的部分噪音信号。

具体交易策略如下:

当MACD快线上穿慢线,代表短期趋势由跌转涨,但必须在RSI低位(低于预设参数)时才能确认买入信号,避免在超买区域反转带来亏损;

当MACD快线下穿慢线,代表短期趋势由涨转跌,但必须在RSI高位(高于预设参数)时才能确认卖出信号,避免在超卖区域反转亏损。

该策略适用于最近较为发育的加密货币横盘震荡市场,抓住高位低位反转的机会获得利润。但必须采取止损措施限制单笔亏损。此外,MACD和RSI参数需要根据市场调整,才能产生较为可靠的交易信号。

总体来说,MACD和RSI指标的融合运用,可以提高震荡盘整市场的交易策略效果。但任何技术指标都无法完美预测市场,交易者还需要保持对市场趋势的判断力,灵活调整策略。

策略源码
/*backtest
start: 2022-09-06 00:00:00
end: 2023-03-11 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5
strategy("Range Strat - MACD/RSI", 
     overlay=true,
     default_qty_type=strategy.percent_of_equity,
     default_qty_value=100, precision=2, initial_capital=100,
     pyramiding=2,
     commission_value=0.05)

// Make input options that configure backtest date range
startDate = input(title="Start Date", defval=13)
startMonth = input(title="Start Month", defval=6)
startYear = input(title="Start Year", defval=2022)

endDate = input(title="End Date", defval=1)
endMonth = input(title="End Month", defval=7)
endYear = input(title="End Year", defval=2200)

// Look if the close time of the current bar
// falls inside the date range
inDateRange = (time >= timestamp(syminfo.timezone, startYear,
         startMonth, startDate, 0, 0)) and
     (time < timestamp(syminfo.timezone, endYear, endMonth, endDate, 0, 0))

// RSI Settings
length = input( 14 )
overSold = input( 55 )
overBought = input( 50 )
price = open
vrsi = ta.rsi(price, length)
cu = (vrsi <= overSold)
co = (vrsi >= overBought)

//MACD Settings
fastLength = input(12)
slowlength = input(26)
MACDLength = input(9)
MACD = ta.ema(open, fastLength) - ta.ema(open, slowlength)
aMACD = ta.ema(MACD, MACDLength)
delta = MACD - aMACD
MACDco = ta.crossover(delta, 0)
MACDcu = ta.crossunder(delta, 0)

// Strategy Entry
if (not na(vrsi))
	if (inDateRange and MACDco and cu)
		strategy.entry("LONG", strategy.long, comment="LONG")
	if (inDateRange and MACDcu and co)
		strategy.entry("SHORT", strategy.short, comment="SHORT")
//plot(strategy.equity, title="equity", color=color.red, linewidth=2, style=plot.style_areabr)