Bollinger Bands Heiken Ashi Short-term Trading Strategy

Author: ChaoZhang, Date: 2023-12-27 15:52:08



This strategy combines the Bollinger Bands indicator and the Heiken Ashi technique to identify trading opportunities by detecting the direction of Heiken Ashi candles and the width of Bollinger Bands. It adopts 10-second K-line bars to determine the trend direction. As a high-frequency algorithmic trading strategy, it is suitable for quantitative trading on high-speed public chains such as Solana.

Strategy Logic

This strategy makes judgments mainly based on the following two indicators:

  1. Heiken Ashi Technique: Determine the price trend direction by calculating the open and close prices of Heiken Ashi candles. If there are N consecutive bullish Heiken Ashi candles, it is considered as a bullish signal. If there are N consecutive bearish Heiken Ashi candles, it is considered as a bearish signal.

  2. Bollinger Bands Indicator: Measure the volatility and overheat of prices by calculating the standard deviation range. If the width of Bollinger Bands is greater than a threshold, it means high price fluctuation and a significant trend.

The specific trading logic is:

  • Go long if there are consecutive N bullish Heiken Ashi signals and the Bollinger Bands width is greater than the volatility threshold.

  • Go short if there are consecutive N bearish Heiken Ashi signals and the Bollinger Bands width is greater than the volatility threshold.

By combining the Bollinger Bands and Heiken Ashi indicators, this strategy comprehensively judges the market volatility and the price trend direction, capturing short-term profit opportunities at high frequency time scales.


This strategy has the following advantages:

  1. Improved signal accuracy by combining multiple indicators. Heiken Ashi determines the general trend while Bollinger Bands measures volatility. The combination enhances the reliability of trading signals.

  2. High-frequency algorithmic trading to capture short-term profits. 10-second bars combined with efficient exchanges like Solana enable high-frequency entry and exit suitable for short-term scalping.

  3. Great flexibility in adjustable parameters. The numbers of Heiken Ashi candles, Bollinger Bands parameters etc. can be adjusted to adapt to different market environments.

  4. Simple implementation and easily extensible. This strategy mainly employs basic indicators with concise code, facilitating future expansions of functionality.

Risks and Solutions

The main risks of this strategy include:

  1. Slippage risk from high-frequency trading. Adopt efficient exchanges, adjust trading frequency and other means to avoid.

  2. Failure when Bollinger Bands contract. Combine with other indicators like KDJ to determine trend.

  3. False signals from Heiken Ashi. Adjust candle numbers, confirm with other indicators when necessary.

  4. Great influence from news in high-frequency time frames. Pay attention to significant news events and pause trading when necessary.

Future Improvements

This strategy can be further improved in the following aspects:

  1. Leverage deep learning etc. to judge reliability of Heiken Ashi signals.

  2. Add stop loss mechanisms to control per trade risks.

  3. Form portfolio trading with more indicators to enhance stability.

  4. Adjust parameters for different coins and construct cross-coin portfolios.

  5. Utilize high-frequency data for trend prediction and early opportunity spotting.


This is a typical short-term high-frequency algorithmic trading strategy combining Heiken Ashi and Bollinger Bands. It has advantages like relatively high signal accuracy and capturing short-term profits at high frequency. It also has certain risks like slippage and false signals. Optimization methods like parameter tuning, risk control mechanisms and indicator combinations can help improve it. Overall it is a highly extensible short-term quantitative strategy idea.

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

strategy("ANCIENT TECHNOLOGY", overlay=true)

// Input for the number of consecutive candles
consecutiveCandles = input(1, title="Number of Consecutive Candles", minval=1, maxval=6)

// Bollinger Band parameters
lengthBB = input(4, title="Bollinger Band Length")
multBB = input(20, title="Bollinger Band Multiplier")
volatilityThreshold = input(0.2, title="Volatility Threshold")

// Calculate Bollinger Bands
basisBB = sma(close, lengthBB)
devBB = multBB * stdev(close, lengthBB)
upperBB = basisBB + devBB
lowerBB = basisBB - devBB
bandWidth = upperBB - lowerBB

// Initialize Heiken Ashi variables
var float haOpen = na
var float haClose = na

// Update Heiken Ashi calculations
if (na(haOpen))
    haOpen := (open + close) / 2
    haOpen := (haOpen + haClose) / 2
haClose := (open + high + low + close) / 4

// Function to check for consecutive green or red Heiken Ashi candles
f_consecutive(dir, len) =>
    count = 0
    for i = 0 to len - 1
        if (dir == "green" and haClose[i] > haOpen[i]) or (dir == "red" and haClose[i] < haOpen[i])
            count := count + 1
    count == len

// Trading conditions based on Heiken Ashi and Bollinger Band width
longCondition = f_consecutive("green", consecutiveCandles) and bandWidth > volatilityThreshold
shortCondition = f_consecutive("red", consecutiveCandles) and bandWidth > volatilityThreshold

// Trading logic
if (longCondition)
    strategy.entry("Long", strategy.long)

if (shortCondition)
    strategy.entry("Short", strategy.short)

// Plot entry signals on the chart for visualization
plotshape(series=longCondition, title="Long Signal", location=location.belowbar,, style=shape.labelup, text="BUY")
plotshape(series=shortCondition, title="Short Signal", location=location.abovebar,, style=shape.labeldown, text="SELL")