Bollinger Bands Based High Frequency Trading Strategy

Author: ChaoZhang, Date: 2023-12-21 15:37:07
Tags:

img

Overview

This strategy implements a high frequency trading strategy based on the Bollinger Bands indicator. It determines the upper and lower Bollinger bands by calculating the standard deviation and moving average of prices. When the price touches the middle band, long or short trades are executed. Each trade invests all capital with a 0.5% take profit range. This strategy is suitable for highly volatile trading pairs and exchanges without fees.

Strategy Logic

The strategy uses the Bollinger Bands indicator to determine if prices have reached overbought or oversold levels. The bands consist of an upper band, lower band and middle band. The middle band is a simple n-day moving average of prices. The upper band is the middle band plus k times the n-day standard deviation of prices. The lower band is the middle band minus k times the standard deviation. k is usually set to 2. When prices approach the upper band, it indicates overbuying. When prices approach the lower band, it indicates overselling.

This strategy sets the Bollinger period to 20 days and k to 2. When prices touch the middle band, it signals prices reverting from extreme areas, generating trading signals. The long signal is triggered when prices cross above the middle band. The short signal triggers when prices fall below the middle band.

When entering positions, all capital is invested (including equity and floating profit/loss). A 0.5% take profit range is then set. When prices move beyond 0.5%, positions are closed for profit.

Advantage Analysis

The advantages of this strategy are:

  1. Using Bollinger Bands to identify trading signals is more effective at detecting extremes than simple moving averages.

  2. The high frequency approach quickly achieves profit across short trading cycles.

  3. Investing all capital maximizes profit potential.

  4. Setting a take profit range effectively manages risk and locks in gains.

Risk Analysis

Some risks also exist:

  1. Bollinger Bands are sensitive to input parameters. Incorrect settings may produce false signals.

  2. High frequency trading requires zero-fee exchanges, otherwise fees erode profits.

  3. Investing all capital is risky. Black swan events could trigger big losses.

  4. A tight take profit range increases trade frequency and operational complexity.

Solutions:

  1. Optimize Bollinger parameters to find ideal settings.

  2. Use zero-fee exchanges like Binance Spot.

  3. Set stop losses to limit maximum loss.

  4. Widen take profit range to reduce trade frequency.

Optimization

This strategy can be improved by:

  1. Adding volume indicators like On Balance Volume to filter fakeouts.

  2. Optimizing Bollinger parameters to find best combinations.

  3. Utilizing adaptive stop loss and take profit ranges. For example, widening ranges as trades or wins accumulate.

  4. Incorporating machine learning models to predict buy/sell signals.

  5. Avoiding trades around major events like earnings reports based on fundamentals.

Conclusion

This is a high frequency strategy using Bollinger Bands for signal generation, full position sizing and small take profits. It has advantages in profitability but also weaknesses like parameter sensitivity and risk control. Further improvements can come from enhancing indicators, adaptive stops, machine learning and more to make the strategy more robust.


/*backtest
start: 2022-12-14 00:00:00
end: 2023-12-20 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5
strategy("Estrategia Bollinger Bands", shorttitle="BB Strategy", overlay=true)

// Parámetros de las Bandas de Bollinger
length = input(20, title="Longitud")
mult = input(2.0, title="Multiplicador")

// Calcula las Bandas de Bollinger
basis = ta.sma(close, length)
upper_band = basis + mult * ta.stdev(close, length)
lower_band = basis - mult * ta.stdev(close, length)

// Condiciones para realizar operaciones
price_touches_basis_up = ta.crossover(close, basis)
price_touches_basis_down = ta.crossunder(close, basis)

// Monto inicial de inversión
monto_inicial = 10

// Lógica de la estrategia
if (price_touches_basis_up)
    qty = strategy.equity + strategy.netprofit // Invertir el total del capital más las ganancias en cada operación
    direction = close > basis ? strategy.long : strategy.short
    strategy.entry("Operacion", direction, qty = 1)

// Lógica para cerrar la operación con un movimiento del 0.5% (take profit)
target_profit = 0.005 // Actualizado a 0.5%

if (strategy.position_size != 0)
    direction = strategy.position_size > 0 ? strategy.long : strategy.short
    strategy.exit("Take Profit/Close", from_entry = "Operacion", profit = close * (1 + target_profit))

// Dibuja las Bandas de Bollinger en el gráfico
plot(upper_band, color=color.blue, title="Upper Band")
plot(lower_band, color=color.red, title="Lower Band")
plot(basis, color=color.green, title="Basis")

// Muestra el monto inicial de inversión en la barra del título
var label lbl = label.new(na, na, "")
label.set_text(lbl, "Monto Inicial: $" + str.tostring(monto_inicial, "#.########"))
label.set_xy(lbl, bar_index, low)
label.set_color(lbl, color.new(color.blue, 0))


More