The resource loading... loading...

Quantitative Trading Strategy Based on Bollinger Bands and RSI

Author: ChaoZhang, Date: 2023-12-20 15:39:19
Tags:

img

Overview

This strategy designs a quantitative trading strategy based on Bollinger Bands and the Relative Strength Index (RSI). It combines trend tracking and overbought/oversold judgment to enter the market at the beginning of a trend and exit at overbought/oversold levels to profit.

Strategy Principle

The strategy uses Bollinger Bands to determine price trends and support/resistance levels. Prices approaching the lower Bollinger Band are seen as an oversold signal, while prices approaching the upper Bollinger Band are seen as an overbought signal. At the same time, it incorporates the RSI indicator to determine if oversold or overbought conditions exist.

The specific trading rules are: go long when the price is below the lower Bollinger Band and the RSI is below 30; go short when the price is above the upper Bollinger Band and the RSI is above 70. For profit taking, set the middle Bollinger Band or the opposite Bollinger Band as the take profit level. The stop loss is set at a certain percentage from the entry price.

Advantages

The strategy combines Bollinger Bands’ trend tracking ability and RSI’s overbought/oversold judgement to capture good trend start timing. Also, the profit taking and stop loss strategies provide clear risk management.

Compared to using a single indicator like Bollinger Bands or RSI alone, this strategy utilizes multiple indicators and parameters to improve decision accuracy. With proper parameter tuning, it can achieve relatively stable performance.

Risks

The strategy relies heavily on parameter optimization. Incorrect parameter settings can lead to missing trends or generating false signals. For example, mismatching Bollinger period may cause such issues. Take profit and stop loss levels also need careful assessment.

The strategy also depends on the trading instrument. For highly volatile assets, Bollinger Band parameters need to be adjusted accordingly. For instruments with unclear trends, the performance may suffer as well. Also affected by transaction costs, slippage and extreme market events.

Parameter optimization testing is recommended to evaluate profit taking/stop loss levels and performance across different assets and market regimes. Maintain risk management buffers.

Optimization Directions

Several aspects can be improved:

  1. Evaluate and optimize parameters for Bollinger Bands and RSI to better match the trading instrument characteristics

  2. Incorporate additional indicators like KDJ, MACD to build a multifactor model

  3. Assess profit taking/stop loss strategies, such as trailing stop loss or scaled exit

  4. Conduct dynamic parameter tuning based on specific assets and market conditions

  5. Add machine learning models to judge signal quality and risk levels

Summary

This strategy integrates Bollinger Bands and RSI for a comprehensive trend following system. There is further room for improving effectiveness and stability through parameter tuning and risk management. Custom adjustments and optimizations are recommended based on individual needs and risk preference for better performance.


/*backtest
start: 2023-11-01 00:00:00
end: 2023-11-30 23:59:59
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=4
strategy("BB + RSI Estrategia", overlay=true)

longitud = input(20, title="Longitud BB", minval=5, maxval=50, step=1)
multiplicador = input(2.0, title="Multiplicador BB", type=input.float, step=0.1)
timeframe_bb = input("D", title="Marco de Tiempo BB", type=input.resolution)
rsi_length = input(14, title="Longitud RSI", minval=5, maxval=50, step=1)
rsi_overbought = input(70, title="Nivel de sobrecompra RSI", minval=50, maxval=80, step=1)
rsi_oversold = input(30, title="Nivel de sobreventa RSI", minval=20, maxval=50, step=1)
take_profit = input("Central", title="Take Profit (banda)", options=["Central", "Opuesta"])
stop_loss = input(2.00, title="Stop Loss", type=input.float, step=0.10)

var SL = 0.0

[banda_central, banda_superior, banda_inferior] = security(syminfo.tickerid, timeframe_bb, bb(close, longitud, multiplicador))
rsi_value = rsi(close, rsi_length)

comprado = strategy.position_size > 0
vendido = strategy.position_size < 0

if not comprado and not vendido
    if close < banda_inferior and rsi_value < rsi_oversold
        // Realizar la compra
        cantidad = round(strategy.equity / close)
        strategy.entry("Compra", strategy.long, qty=cantidad, when=cantidad > 0)
        SL := close * (1 - (stop_loss / 100))

    if close > banda_superior and rsi_value > rsi_overbought
        // Realizar la Venta
        cantidad = round(strategy.equity / close)
        strategy.entry("Venta", strategy.short, qty=cantidad, when=cantidad > 0)
        SL := close * (1 + (stop_loss / 100))

if comprado
    // Verificar el take profit
    if take_profit == "Central" and close >= banda_central
        strategy.close("Compra", comment="TP")
        SL := 0

    if take_profit == "Opuesta" and close >= banda_superior
        strategy.close("Compra", comment="TP")
        SL := 0
    // Verificar el stop loss
    if close <= SL
        strategy.close("Compra", comment="SL")
        SL := 0

if vendido
    // Verificar el take profit
    if take_profit == "Central" and close <= banda_central
        strategy.close("Venta", comment="TP")
        SL := 0

    if take_profit == "Opuesta" and close <= banda_inferior
        strategy.close("Venta", comment="TP")
        SL := 0
    // Verificar el Stop loss
    if close >= SL
        strategy.close("Venta", comment="SL")
        SL := 0

// Salida
plot(SL > 0 ? SL : na, style=plot.style_circles, color=color.red)
g1 = plot(banda_superior, color=color.aqua)
plot(banda_central, color=color.red)
g2 = plot(banda_inferior, color=color.aqua)
fill(g1, g2, color=color.aqua, transp=97)

// Dibujar niveles de sobrecompra/sobreventa del RSI
hline(rsi_overbought, "RSI Overbought", color=color.red)
hline(rsi_oversold, "RSI Oversold", color=color.green)

More