0bps

Strategy vault / Breakout

Medium Long Term Quantitative Trading Strategy Based on Bollinger Bands

This article explains in detail a medium-long term quantitative trading strategy using Bollinger Bands. It generates trading signals by identifying price breakouts through the Bollinger Bands. I. Strategy Logic The…

Author
ChaoZhang
Complexity
Starter · 82 lines
Parameters
4
Backtest bar
1h · intraday
Tested on
BTC/USDT · futures

This article explains in detail a medium-long term quantitative trading strategy using Bollinger Bands. It generates trading signals by identifying price breakouts through the Bollinger Bands.

I. Strategy Logic

The strategy mainly employs the following Bollinger Bands indicators:

  1. Calculate the moving median price as the baseline over a certain period.

  2. Calculate the price standard deviation and multiply it by a factor as the range.

  3. The median ± range constructs the upper and lower bands.

  4. Price breaking through the bands generates trading signals.

The specific trading logic is:

When price breaks through the lower band, a buy signal is generated to take long positions.

When price breaks the upper band, a sell signal is generated to take short positions.

Take profit and stop loss are set at fixed percentages to lock in profits and losses.

Overall, the strategy identifies mid-long term trends by detecting price breakouts of the Bollinger Bands.

II. Advantages of the Strategy

The main advantages of this strategy are:

Firstly, Bollinger Bands can identify price breakouts and reversals to capture mid-long term trends.

Secondly, direct stop loss and take profit settings aid in prudent money management.

Lastly, simple and clear rules make this strategy easy to implement and optimize.

III. Potential Risks

However, the following risks should be noted:

Firstly, the bands need to be optimized precisely for steady signals.

Secondly, stop loss set too small risks insufficient profit, while too large increases risk.

Lastly, excessive frequent trading needs to be prevented.

IV. Summary

In summary, this article has explained a medium-long term quantitative trading strategy using Bollinger Bands for trend following. It can track price trends over the medium to long term, but requires fine tuning of the band intervals and stop loss levels. Overall it provides a relatively simple and intuitive trend following approach.

Parameters

NameDefaultWhat it controls
v_input_151Moving average
v_input_23.01マルチ
v_input_314.2Profit taking(%)
v_input_499Cutting losses(%)

Source Pine Script

/*backtest
start: 2023-08-14 00:00:00
end: 2023-09-13 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//------------------------------------
//
// 『おすすめストラテジーSS1』
// 『BitMEX XBTUSD 30Split foot directionけFor medium and long termストラテジー』
//  For this episodeストラテジーファイル
//
//
//
//------------------------------------
//[Description]
// 『おすすめストラテジーSS1』のPineスクリプトです.
//------------------------------------
 
//@version=3
// strategy(title = "『おすすめストラテジーSS1』", shorttitle="Strategy1", initial_capital=1200000, pyramiding=0, default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_type=strategy.commission.percent, commission_value=0.05, overlay=true)
 
 
//------------------------------------
//
//ストラテジーロジック
//
//------------------------------------
 
 
source = close
 
length = input(51, minval = 1, title = "Moving average")
mult = input(3.01, minval = 0.001,step=0.01, maxval = 10, title = "マルチ")
 
Rikaku = input(14.2, minval = 0.1, step=0.1,maxval = 100, title = "Profit taking(%)")
Songiri = input(99, minval = 0.1, maxval = 100, title = "Cutting losses(%)")
 
base = sma(source, length)
range = mult * stdev(source, length)
 
upper = base + range
lower = base - range
 
short_cond = crossover(source, lower)
long_cond = crossunder(source, upper)
 
 
cl = 0.0
cl := na(cl[1]) ? sma(source, length) : (cl[1] * (length - 1) + source) / length
 
plot(cl, color=black)
 
up_plot = plot(upper, color=blue)
low_plot = plot(lower, color=red)
 
fill(up_plot, low_plot,color=#009900)
 
//------------------------------------
//
//オーダーProcessing
//
//------------------------------------
 
 
if (long_cond)
 
	strategy.entry("Long_Entry", strategy.long, oca_name="BollingerBands", comment="Long")
 
	//BitFlyerのようなJPYBuildてのCaseはBelowのコードをUseいます.OtherのCurrencyペアにするCaseも1ティックがDifferentなるためNumber of beamsのChangeがNecessaryです.
	//strategy.exit("LE Exit", "BBandLE", profit = close*(Rikaku/100)*100, loss = close*(Songiri/100)*100, comment="Close")
	strategy.exit("Long_Exit", "Long_Entry", profit = close*(Rikaku/100)*10, loss = close*(Songiri/100)*10, comment="LongClose")
 
if (short_cond)
 
	strategy.entry("Short_Entry", strategy.short, oca_name="BollingerBands",  comment="Short")
 
    //BitFlyerのようなJPYBuildてのCaseはBelowのコードをUseいます.OtherのCurrencyペアにするCaseも1ティックがDifferentなるためNumber of beamsのChangeがNecessaryです.
    //strategy.exit("SE Exit", "BBandSE", profit = close*(Rikaku/100)*100, loss = close*(Songiri/100)*100, comment="Close")
    strategy.exit("Short_Exit", "Short_Entry", profit = close*(Rikaku/100)*10, loss = close*(Songiri/100)*10, comment="ShortClose")

Published by ChaoZhang on the FMZ strategy square · last modified 2023-09-14. 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/Medium-Long-Term-Quantitative-Trading-Strategy-Based-on-Bollinger-Bands.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