该策略通过RSI指标判断超买超卖情况,并配合布林带指标的价格震荡通道,形成交易信号。当RSI指标显示超买或超卖现象,同时价格接近或触及布林带上下轨时,产生买入和卖出信号。策略综合趋势分析和震荡判断,动态找机会。
该策略主要基于以下两个指标进行判定:
计算一定周期内的相对强弱指标RSI,根据预设参数判断其是否进入超买或超卖区域,如超买区上限设定为40,超卖区下限设定为45。
计算一定周期内的布林带,通过其上轨及下轨形成价格通道,描述价格震荡的范围。
在此基础上,策略给出以下交易规则:
当RSI指标上穿45进入超卖区时,并且价格上穿布林带下轨,产生买入信号; 当RSI指标下穿40进入超卖区时,并且价格下穿布林带上轨,产生卖出信号。
该策略结合RSI与布林带指标,具有以下优势:
RSI判断超买超卖状况,布林带判断价格趋势方向,两者互相补充;
布林带上下轨可作为止损位定位,有利于风险控制;
参数设置简单,容易实现与回测;
可针对RSI参数进行优化,确定最佳超买超卖区间;
可选择不同的价格输入,适应多种市场环境。
该策略也存在一些风险:
布林带范围过宽导致止损预期差
RSI参数设置不当,超买超卖区间判断错误
无法准确判断趋势反转点,存在错过信号风险
无法有效控制亏损,存在大幅行情冲击止损风险
该策略可以从以下几个方面进行优化:
优化RSI参数,确定最佳超买超卖区间
优化布林带宽度参数,控制止损范围
加入其他指标判断趋势反转,避免漏掉信号
应用机器学习算法判断买卖时机
根据不同市场环境使用不同参数组合
增加动态止损机制
开发参数自动优化程序
总而言之,该策略通过RSI与布林带指标的配合使用,形成较为稳定的交易决策依据。策略逻辑简单清晰,有利于风险控制,但也存在一定优化空间。通过参数优化、止损优化、算法引入等方式可以进一步增强策略效果,使其更适应复杂的市场环境。该策略为构建交易系统提供了思路,值得进一步研究与应用。
/*backtest
start: 2023-08-18 00:00:00
end: 2023-09-17 00:00:00
period: 2h
basePeriod: 15m
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/
// © Mdemoio
//@version=4
strategy("Madri", shorttitle="Madri", overlay=true)
// Version 1.1
///////////// RSI
RSIlength = input(2,title="A")
RSIoverSold = 45
RSIoverBought = 40
price = close
vrsi = rsi(price, RSIlength)
///////////// Bollinger Bands
BBlength = input(150, minval=1,title="B")
BBmult = 2// input(2.0, minval=0.001, maxval=50,title="Bollinger Bands Standard Deviation")
BBbasis = sma(price, BBlength)
BBdev = BBmult * stdev(price, BBlength)
BBupper = BBbasis + BBdev
BBlower = BBbasis - BBdev
source = close
buyEntry = crossover(source, BBlower)
sellEntry = crossunder(source, BBupper)
///////////// Colors
//switch1=input(true, title="Enable Bar Color?")
//switch2=input(true, title="Enable Background Color?")
//TrendColor = RSIoverBought and (price[1] > BBupper and price < BBupper) and BBbasis < BBbasis[1] ? red : RSIoverSold and (price[1] < BBlower and price > BBlower) and BBbasis > BBbasis[1] ? green : na
//barcolor(switch1?TrendColor:na)
//bgcolor(switch2?TrendColor:na,transp=50)
///////////// RSI + Bollinger Bands Strategy
if (not na(vrsi))
if (crossover(vrsi, RSIoverSold) and crossover(source, BBlower))
strategy.entry("RSI_BB_L", strategy.long, stop=BBlower, comment="Buy")
else
strategy.cancel(id="RSI_BB_L")
if (crossunder(vrsi, RSIoverBought) and crossunder(source, BBupper))
strategy.entry("RSI_BB_S", strategy.short, stop=BBupper, comment="Sell")
else
strategy.cancel(id="RSI_BB_S")
//plot(strategy.equity, title="equity", color=red, linewidth=2, style=areabr)