双RSI均线突破策略是一种同时利用RSI指标和均线指标来进行判断交易时机的量化策略。该策略的核心思想是在RSI指标达到超买超卖区域时,利用均线的方向来过滤信号,寻找更优质的突破点进行建仓。
根据用户设定的参数,分别计算RSI指标和简单移动均线SMA。
当RSI上穿设定的超卖线(默认30)时,如果价格低于LONG退出均线,则产生多头信号。
当RSI下穿设定的超买线(默认70)时,如果价格高于SHORT退出均线,则产生空头信号。
用户可以选定过滤均线,当价格位于过滤均线之上时,才会产生信号。
仓位的退出判断是按照LONG退出均线和SHORT退出均线来进行的。
双指标设计,综合参考了市场两大因素,提高决策的准确性。
合理利用RSI指标的反转特征,寻找反转的时间点。
均线过滤增加判断的严谨性,避免追高杀跌。
允许自定义参数,可以针对不同品种和周期进行优化。
简单的逻辑设计,容易理解和修改。
RSI指标容易产生垂直颈线,density指标可降低此问题。
大周期下的RSI容易失效,可降低参数优化或辅助其他指标。
均线有滞后性,可适当缩短均线长度或辅助MACD等指标。
简单的判断条件,可以引入更多指标确保交易信号效果。
优化RSI参数或引入Density指标降低假信号概率。
结合趋势及波动指标如DMI、BOLL来确定趋势及支撑位。
引入MACD等指标替代或配合均线判断。
增加开仓条件逻辑,防止不理想的突破信号。
双RSI均线突破策略综合运用RSI指标判断超买超卖与均线判断趋势的方法,在理论上可以有效抓取反转机会。该策略灵活简约,容易上手,同时也适合不同品种的优化,是一种值得推荐的量化入门策略。通过引入更多指标来辅助判断,该策略可以进一步增强决策效果,提高盈利概率。
/*backtest start: 2024-01-16 00:00:00 end: 2024-01-23 00:00:00 period: 5m basePeriod: 1m exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ //Global Market Signals: RSI Strategy. //@version=4 strategy("GMS: RSI Strategy", overlay=true) LongShort = input(title="Long Only or Short Only or Both?", type=input.string, defval="Both", options=["Both", "Long Only", "Short Only"]) RSILength = input(title="RSI Length", type = input.integer ,defval=14) RSIUpper = input(title="Upper Threshold", type = input.float ,defval=70) RSILower = input(title="Lower Threshold", type = input.float ,defval=30) LongExit = input(title="Long Exit SMA Length", type = input.integer ,defval=5) ShortExit = input(title="Short Exit SMA Length", type = input.integer ,defval=5) AboveBelow = input(title="Trend SMA Filter?", type=input.string, defval="Above", options=["Above", "Below", "Don't Include"]) TrendLength = input(title="Trend SMA Length", type = input.integer ,defval=200) //Long Side if LongShort =="Long Only" and AboveBelow == "Above" strategy.entry("LONG", true, when = rsi(close,RSILength)<RSILower and close< sma(close,LongExit) and close>sma(close,TrendLength)) strategy.close("LONG", when = close>sma(close,LongExit)) if LongShort =="Long Only" and AboveBelow == "Below" strategy.entry("LONG", true, when = rsi(close,RSILength)<RSILower and close< sma(close,LongExit) and close<sma(close,TrendLength)) strategy.close("LONG", when = close>sma(close,LongExit)) if LongShort =="Long Only" and AboveBelow == "Don't Include" strategy.entry("LONG", true, when = rsi(close,RSILength)<RSILower and close< sma(close,LongExit)) strategy.close("LONG", when = close>sma(close,LongExit)) if LongShort =="Both" and AboveBelow == "Above" strategy.entry("LONG", true, when = rsi(close,RSILength)<RSILower and close< sma(close,LongExit) and close>sma(close,TrendLength)) strategy.close("LONG", when = close>sma(close,LongExit)) if LongShort =="Both" and AboveBelow == "Below" strategy.entry("LONG", true, when = rsi(close,RSILength)<RSILower and close< sma(close,LongExit) and close<sma(close,TrendLength)) strategy.close("LONG", when = close>sma(close,LongExit)) if LongShort =="Both" and AboveBelow == "Don't Include" strategy.entry("LONG", true, when = rsi(close,RSILength)<RSILower and close< sma(close,LongExit)) strategy.close("LONG", when = close>sma(close,LongExit)) //SHORT SIDE if LongShort =="Short Only" and AboveBelow == "Above" strategy.entry("SHORT", false, when = rsi(close,RSILength)>RSIUpper and close> sma(close,ShortExit) and close>sma(close,TrendLength)) strategy.close("SHORT", when = close<sma(close,ShortExit)) if LongShort =="Short Only" and AboveBelow == "Below" strategy.entry("SHORT", false, when = rsi(close,RSILength)>RSIUpper and close> sma(close,ShortExit) and close<sma(close,TrendLength)) strategy.close("SHORT", when = close<sma(close,ShortExit)) if LongShort =="Short Only" and AboveBelow == "Don't Include" strategy.entry("SHORT", false, when = rsi(close,RSILength)>RSIUpper and close> sma(close,ShortExit)) strategy.close("SHORT", when = close<sma(close,ShortExit)) if LongShort =="Both" and AboveBelow == "Above" strategy.entry("SHORT", false, when = rsi(close,RSILength)>RSIUpper and close> sma(close,ShortExit) and close>sma(close,TrendLength)) strategy.close("SHORT", when = close<sma(close,ShortExit)) if LongShort =="Both" and AboveBelow == "Below" strategy.entry("SHORT", false, when = rsi(close,RSILength)>RSIUpper and close> sma(close,ShortExit) and close<sma(close,TrendLength)) strategy.close("SHORT", when = close<sma(close,ShortExit)) if LongShort =="Both" and AboveBelow == "Don't Include" strategy.entry("SHORT", false, when = rsi(close,RSILength)>RSIUpper and close> sma(close,ShortExit)) strategy.close("SHORT", when = close<sma(close,ShortExit))