MACD指标的RSI反转策略


创建日期: 2024-01-15 12:33:14 最后修改: 2024-01-15 12:33:14
复制: 0 点击次数: 461
avatar of ChaoZhang ChaoZhang
1
关注
1241
关注者

MACD指标的RSI反转策略

概述

该策略基于MACD指标的RSI值来判断买入和卖出信号。当RSI值超过超买线或超卖区间时买入,当RSI值跌破超卖区间时止损或止盈。

策略原理

该策略结合了MACD指标和RSI指标的优点。

首先计算MACD指标的三条曲线,包括DIF线、DEA线和MACD线。然后在MACD线上再计算RSI指标,形成RSI of MACD。

当RSI of MACD指标超过30或35这个超卖区间时产生买入信号,表示MACD线进入超卖区,股价趋势开始反转上涨。当RSI of MACD指标再次跌破15这个超卖区间时产生卖出信号,表示趋势反转结束。

该策略还设置了部分止盈,当RSI of MACD指标超过80这个超买区时可以卖出部分头寸锁定部分利润。

优势分析

  • 利用MACD指标判断趋势反转点
  • 利用RSI指标判断超买超卖区域 Filter假信号
  • 结合双指标判断,精准找出买卖点位
  • 设置部分止盈,防止亏损扩大

风险分析

  • MACD指标参数设置不当,无法准确判断趋势
  • RSI指标参数设置不当,无法准确判断超买超卖
  • 部分止盈设置过于激进,可能错过更大涨幅

解决方法:

  • 优化MACD参数,找出最佳参数组合
  • 优化RSI参数,提高准确率
  • 适当放宽部分止盈条件,追求更大收益

优化方向

该策略还可以从以下几个方向进行优化:

  1. 增加止损策略,进一步控制下跌风险
  2. 增加仓位管理模块,让仓位随着价格运行逐步放大
  3. 集成机器学习模型,利用历史数据训练,进一步提升买卖点判断的准确性
  4. 尝试在更短周期如15分钟或5分钟运行,进一步提高策略频率

总结

该策略整体设计思路清晰,核心思想是利用MACD反转结合RSI过滤判断买卖点位。通过参数优化,止损管理,风险控制等手段,可以将其打造成一个非常实用的量化交易策略。

策略源码
/*backtest
start: 2024-01-07 00:00:00
end: 2024-01-14 00:00:00
period: 3m
basePeriod: 1m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © mohanee

//@version=4

strategy(title="RSI of MACD Strategy[Long only]",  shorttitle="RSIofMACD" , overlay=false, pyramiding=1,     default_qty_type=strategy.percent_of_equity,  default_qty_value=20, initial_capital=10000, currency=currency.USD)  //default_qty_value=10, default_qty_type=strategy.fixed,

	

/////////////////////////////////////////////////////////////////////////////////



// MACD Inputs ///
fastLen = input(12, title="Fast Length")
slowLen = input(21, title="Slow Length")
sigLen  = input(9, title="Signal Length")

rsiLength  = input(14, title="RSI of MACD Length")




riskCapital = input(title="Risk % of capital", defval=10, minval=1)
stopLoss=input(3,title="Stop Loss",minval=1)

takeProfit=input(false, title="Take Profit")


[macdLine, signalLine, _] = macd(close, fastLen, slowLen, sigLen)

rsiOfMACD = rsi(macdLine, rsiLength)
emaSlow = ema(close, slowLen)



//drawings
/////////////////////////////////////////////////////////////////////////////////


obLevelPlot = hline(80, title="Overbought / Profit taking line",  color=color.blue , linestyle=hline.style_dashed)
osLevelPlot = hline(30, title="Oversold / entry line", color=color.green, linestyle=hline.style_dashed)

exitLinePlot = hline(15, title="Exit line", color=color.red, linestyle=hline.style_dashed)




plot(rsiOfMACD, title = "rsiOfMACD" ,  color=color.purple)


//drawings
/////////////////////////////////////////////////////////////////////////////////




//Strategy Logic 
/////////////////////////////////////////////////////////////////////////////////

//Entry--
//Echeck how many units can be purchased based on risk manage ment and stop loss
qty1 = (strategy.equity  * riskCapital / 100 ) /  (close*stopLoss/100)  

//check if cash is sufficient  to buy qty1  , if capital not available use the available capital only
qty1:= (qty1 * close >= strategy.equity ) ? (strategy.equity / close) : qty1


strategy.entry(id="RSIofMACD", long=true,   qty=qty1,  when =  ( crossover(rsiOfMACD, 30) or crossover(rsiOfMACD, 35)  ) and close>=emaSlow )



bgcolor(abs(strategy.position_size)>=1 ? color.blue : na , transp=70)


barcolor(abs(strategy.position_size)>=1 and  ( crossover(rsiOfMACD, 30) or crossover(rsiOfMACD, 35) ) ? color.purple : abs(strategy.position_size)>=1 ? color.blue : na  )


//partial exit
strategy.close(id="RSIofMACD", comment="PExit Profit is "+tostring(close - strategy.position_avg_price,  "###.##")  ,  qty=strategy.position_size/3, when= takeProfit and abs(strategy.position_size)>=1 and close > strategy.position_avg_price and crossunder(rsiOfMACD,80) )

//Close All
strategy.close(id="RSIofMACD", comment="Close All   Profit is "+tostring(close - strategy.position_avg_price,  "###.##"), when=abs(strategy.position_size)>=1 and crossunder(rsiOfMACD,15) ) //and close > strategy.position_avg_price )


//Strategy Logic 
/////////////////////////////////////////////////////////////////////////////////