策略
RSI和布林带双重策略RSI-and-Bollinger-Bands-Double-Strategy
ChaoZhang · PineScript · 均值回归 · 2024-04-03 17:54:52
概述
该策略结合了相对强弱指数(RSI)和布林带(Bollinger Bands)两个技术指标,当价格低于布林带下轨时产生买入信号,当价格高于布林带上轨时产生卖出信号。该策略只有在RSI指标和布林带指标同时处于超卖或超买状态时才会触发交易信号。
策略原理
- 根据设定的RSI参数计算RSI值。
- 使用布林带公式计算布林带中轨、上轨和下轨。
- 判断当前收盘价是否突破布林带上轨或下轨。
- 判断当前RSI值是否高于超买阈值或低于超卖阈值。
- 当布林带和RSI指标同时满足买入或卖出条件时,产生相应的交易信号。
优势
- 结合了趋势和动量两种技术指标,能够更全面地判断市场状态。
- 同时使用两个指标作为过滤条件,有效降低了假信号的出现概率。
- 代码逻辑清晰,参数设置灵活,适合不同市场环境和交易风格。
风险
- 在震荡市中,该策略可能会产生较多的亏损交易。
- 参数设置不当可能导致策略表现欠佳,需要根据实际情况进行优化。
- 该策略未设置止损,可能面临较大的回撤风险。
优化方向
- 可以根据市场特点和个人偏好,对RSI和布林带的参数进行优化。
- 引入其他技术指标如MACD、均线等,提高信号的可靠性。
- 设置合理的止损和止盈,控制单笔交易风险。
- 对于震荡市,可以考虑增加判断条件或减小仓位,降低频繁交易带来的成本。
总结
RSI和布林带双重策略通过结合趋势和动量指标,能够比较全面地判断市场状态,并给出相应的交易信号。但该策略在震荡市中表现可能欠佳,且未设置风险控制措施,因此实盘运用时需要谨慎。通过优化参数、引入其他指标和设置合理的止损止盈等方式,可以进一步提升该策略的稳定性和盈利能力。
参数
| 参数 | 默认值 | 说明 |
|---|---|---|
| v_input_1 | 14 | RSI Period Length |
| v_input_2 | 20 | Bollinger Period Length |
| v_input_3 | 2 | Bollinger Bands Standard Deviation |
源码(78 行)
/*backtest
start: 2024-03-01 00:00:00
end: 2024-03-31 23:59:59
period: 4h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=4
strategy("Bollinger + RSI, Double Strategy (by ChartArt) v1.1", shorttitle="CA_-_RSI_Bol_Strat_1.1", overlay=true)
// ChartArt's RSI + Bollinger Bands, Double Strategy - Update
//
// Version 1.1
// Idea by ChartArt on January 18, 2015.
//
// This strategy uses the RSI indicator
// together with the Bollinger Bands
// to sell when the price is above the
// upper Bollinger Band (and to buy when
// this value is below the lower band).
//
// This simple strategy only triggers when
// both the RSI and the Bollinger Bands
// indicators are at the same time in
// a overbought or oversold condition.
//
// In this version 1.1 the strategy was
// both simplified for the user and
// made more successful in backtesting.
//
// List of my work:
// https://www.tradingview.com/u/ChartArt/
//
// __ __ ___ __ ___
// / ` |__| /\ |__) | /\ |__) |
// \__, | | /~~\ | \ | /~~\ | \ |
//
//
///////////// RSI
RSIlength = input(14,title="RSI Period Length")
RSIoverSold = 30
RSIoverBought = 70
price = close
vrsi = rsi(price, RSIlength)
///////////// Bollinger Bands
BBlength = input(20, minval=1,title="Bollinger Period Length")
BBmult = 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)
plot(BBbasis, color=color.blue,title="Bollinger Bands SMA Basis Line")
p1 = plot(BBupper, color=color.red,title="Bollinger Bands Upper Line")
p2 = plot(BBlower, color=color.green,title="Bollinger Bands Lower Line")
fill(p1, p2)
// Entry conditions
crossover_rsi = crossover(vrsi, RSIoverSold) and crossover(source, BBlower)
crossunder_rsi = crossunder(vrsi, RSIoverBought) and crossunder(source, BBupper)
///////////// RSI + Bollinger Bands Strategy
if (not na(vrsi))
if (crossover_rsi)
strategy.entry("RSI_BB_L", strategy.long, comment="RSI_BB_L")
else
strategy.cancel(id="RSI_BB_L")
if (crossunder_rsi)
strategy.entry("RSI_BB_S", strategy.short, comment="RSI_BB_S")
else
strategy.cancel(id="RSI_BB_S")