0bps

Strategy vault / Mean reversion

Bollinger Bands RSI MACD and Stochastic Multi indicator Fusion Trading Strategy

This strategy integrates Bollinger Bands, RSI, MACD and Stochastic, four different technical indicators, to make long and short decisions. First, it determines if the price is outside the Bollinger Bands channel and…

Author
ChaoZhang
Complexity
Intermediate · 82 lines
Parameters
15
Backtest bar
1d · swing
Tested on
BTC/USDT · futures

Overview

This strategy integrates Bollinger Bands, RSI, MACD and Stochastic, four different technical indicators, to make long and short decisions. First, it determines if the price is outside the Bollinger Bands channel and takes long or short positions accordingly. Then it checks whether RSI is in overbought or oversold zones and enters based on the direction. Next it looks for MACD golden cross and death cross signals and takes positions accordingly. Finally it identifies Stochastic golden cross and death cross in overbought/oversold zones. With signals from all four indicators, the strategy adopts more aggressive pyramiding positions to maximize profits.

Principles

The strategy mainly utilizes four indicators - Bollinger Bands, RSI, MACD and Stochastic.

Bollinger Bands are plotted at standard deviation levels above and below a simple moving average. Prices outside the bands suggest price has moved outside normal distribution and thus trading opportunities.

RSI calculates momentum as the ratio of higher closes to lower closes. Values below 30 suggest an oversold condition while above 70 suggests overbought. These serve as trade signals.

MACD is the difference between short and long term moving averages. Crossovers of the MACD line and signal line produce trade signals - golden cross for long and death cross for short.

Stochastic K and D line crossovers also serve as trade signals. K below 20 suggests oversold while above 80 suggests overbought. K crossing above D gives bullish signals while crossing below gives bearish signals.

Combining signals from these four indicators improves the accuracy of trade entries. Specifically, going long when price exceeds Bollinger Bands upper band, RSI below 30, MACD golden cross and Stochastic K crossing above D below 20. Pyramiding long positions when all four conditions are met. Short signals are similar.

Advantages

The main advantage of this strategy is combining multiple indicators improves accuracy and win rate.

Firstly, using indicators across different timeframes - Bollinger for medium/long-term, and MACD, RSI, Stochastic for short-term, reduces mistakes.

Secondly, requiring all indicators to align reduces false signals. Entering only when Bollinger, RSI, MACD and Stochastic all give signals avoids failure of single indicators.

Also, combining complementary indicators capitalizes on strengths of each. RSI identifies overbought/oversold, Bollinger trend changes, MACD momentum shifts etc.

Finally, pyramiding positions with confirmed signals maximizes profits versus fixed quantity trades.

Risks

Some risks to consider:

Firstly, more parameters and indicators makes optimization difficult. Extensive testing is needed to find best combinations.

Secondly, concurrent indicator signals are rare, leading to low trade frequency. Lack of alignment for long periods causes strategy underperformance.

Thirdly, pyramiding can amplify losses if indicators give wrong signals. Wrong pyramided trades have larger losses.

Finally, inconsistent indicator signals need decision rules. Strategy should have quantitative logic when indicators conflict.

Enhancements

Some ways to improve the strategy:

  1. Optimize parameters through genetic algorithms, grid search etc. to find best combinations.

  2. Add stop loss rules to control losses when price moves adversely beyond thresholds.

  3. Improve entry logic with scoring system for inconsistent indicator signals and weighted parameters.

  4. Optimize exits with profit/loss data across holding periods to generate ideal exit rules.

  5. Optimize products and time frames best suited for strategy.

  6. Account for trading costs like slippage and commissions in parameter optimization.

  7. Utilize machine learning for adaptive optimization.

Conclusion

This strategy combines multiple indicators and confirmation mechanisms for decision making. With proper parameters and risk controls, it can achieve good results. But tuning complexity and risks need to be addressed through ongoing enhancements for stability. Finding optimal indicator combinations, scientific entry/exit rules and risk control are key for sustained profitability across market conditions.

Parameters

NameDefaultWhat it controls
v_input_114lengthrsi
v_input_230overSold
v_input_370overBought
v_input_420lengthbb
v_input_52mult
v_input_6falseStrategy Direction
v_input_712fastLength
v_input_826slowlength
v_input_99MACDLength
v_input_103consecutiveBarsUp
v_input_113consecutiveBarsDown
v_input_125lengthch
v_input_1314lengthst
v_input_1480OverBoughtst
v_input_1520OverSoldst

Source Pine Script

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

//@version=2
strategy("MD strategy", overlay=true)
lengthrsi = input( 14 )
overSold = input( 30 )
overBought = input( 70 )
price = close
source = close
lengthbb = input(20, minval=1)
mult = input(2.0, minval=0.001, maxval=50)
direction = input(0, title = "Strategy Direction",  minval=-1, maxval=1)
fastLength = input(12)
slowlength = input(26)
MACDLength = input(9)
consecutiveBarsUp = input(3)
consecutiveBarsDown = input(3)
lengthch = input( minval=1, maxval=1000, defval=5)
upBound = highest(high, lengthch)
downBound = lowest(low, lengthch)
lengthst = input(14, minval=1)
OverBoughtst = input(80)
OverSoldst = input(20)
smoothK = 3
smoothD = 3

k = sma(stoch(close, high, low, lengthst), smoothK)
d = sma(k, smoothD)



ups = price > price[1] ? nz(ups[1]) + 1 : 0
dns = price < price[1] ? nz(dns[1]) + 1 : 0
MACD = ema(close, fastLength) - ema(close, slowlength)
aMACD = ema(MACD, MACDLength)
delta = MACD - aMACD

strategy.risk.allow_entry_in(direction == 0 ? strategy.direction.all : (direction < 0 ? strategy.direction.short : strategy.direction.long))

basis = sma(source, lengthbb)
dev = mult * stdev(source, lengthbb)

upper = basis + dev
lower = basis - dev

vrsi = rsi(price, lengthrsi)

if (not na(vrsi))
    if (crossover(vrsi, overSold))
        strategy.entry("RsiLE", strategy.long, comment="RsiLE")
    if (crossunder(vrsi, overBought))
        strategy.entry("RsiSE", strategy.short, comment="RsiSE")

if (crossover(source, lower))
    strategy.entry("BBandLE", strategy.long, stop=lower, oca_name="BollingerBands",  comment="BBandLE")
else
    strategy.cancel(id="BBandLE")

if (crossunder(source, upper))
    strategy.entry("BBandSE", strategy.short, stop=upper, oca_name="BollingerBands",  comment="BBandSE")
else
    strategy.cancel(id="BBandSE")
    
    
if (not na(k) and not na(d))
    if (crossover(k,d) and k < OverSoldst)
        strategy.entry("StochLE", strategy.long, comment="StochLE")
    if (crossunder(k,d) and k > OverBoughtst)
        strategy.entry("StochSE", strategy.short, comment="StochSE")   
        
if (crossover(delta, 0))
    strategy.entry("MacdLE", strategy.long, comment="MacdLE")

if (crossunder(delta, 0))
    strategy.entry("MacdSE", strategy.short, comment="MacdSE")

Published by ChaoZhang on the FMZ strategy square · last modified 2023-09-28. Collected in the Quant Trading Vault. Unvalidated research: re-test with your own data and costs before trusting it.

Build this with AgenKit

A spec is not a trading system. Paste this into your coding agent and AgenKit runs a specialist team — architecture, test-first build, risk gates, review — with paper trading on by default.

in Claude Code, Cursor, Codex & 4 more
/agenkit build a production-grade trading bot with a backtest engine, risk controls and paper trading by default from strategies/Bollinger-Bands-RSI-MACD-and-Stochastic-Multi-indicator-Fusion-Trading-Strategy.md
  1. npx agenkit install engineering-kit in your project
  2. Paste the command into your agent and approve each phase
  3. Get tests, backtest, risk controls and a paper-trading switch

Understand it first

Before you run this, read the lesson behind the idea and how to backtest it honestly. Specs like this one are the survivors of an unknown number of trials; deflate their results accordingly.

Related specs

esc

Try , , or .

↑↓ move↵ open