Name
基于布林通道指标的突破交易策略Dynamic-Bollinger-Breakout-Strategy
Author
ChaoZhang
Strategy Description
该策略是基于布林通道指标的突破交易策略。它通过计算布林通道的上下轨,并结合动态调整的买入卖出阈值,实现对币安BTCUSDT的自动化交易。
该策略的核心指标是布林通道。布林通道由一个N日移动平均线及其上下两个标准差通道构成。本策略中的布林通道长度为20日,标准差倍数为2。当价格接近或触及布林通道下轨时,视为过度超售,这时策略会开仓做多;当价格接近或触及布林通道上轨时,视为过度看涨,这时策略会平仓了结多单。
除布林通道指标外,本策略还引入两个可调参数:买入阈值和卖出阈值。买入阈值默认为布林下轨之下58个点,是打开多单的条件。卖出阈值默认为布林下轨之上470个点,是平仓的条件。这两个阈值可以根据实际情况和回测结果进行动态调整,使策略更具灵活性。
在满足买入条件时,策略会使用账户权益的10%开仓做多。做多后,若价格上涨幅度达到止损条件(-125%),会止损平仓。在价格上涨后触发卖出阈值时,策略会选择全部平仓,回收利润。
该策略具有以下几个主要优势:
- 使用布林通道指标,可以抓住价格异常离开轨道的机会,从而在反转时获利
- 引入动态调整的买入卖出阈值,优化入场出场机会
- 采取部分仓位做多,可以控制风险
- 设置止损条件,避免亏损进一步扩大
- 回测数据采用5分钟线,可以及时捕捉较短周期的交易机会
该策略也存在一定的风险:
- 布林带指标本身并不是百分百可靠,价格可能长时间低位震荡后再次下跌
- 阈值设定不当可能导致错过最佳入场或出场点
- 止损设置过于宽松,无法及时止损,或者过于严格,止损过于灵敏
- 回测周期选择不当,可能把一些偶然的利润当作稳定收益
对策:
- 结合更多指标判断行情,避免布林通道发出错误信号
- 测试并优化阈值参数,找到最佳参数组合
- 测试并优化止损条件,找到平衡点
- 采用更长的回测周期,检验策略的稳定性
该策略还可从以下几个方向进行优化:
- 尝试结合其他指标,例如KD、RSI等,设定更严格的入场规则,避免入场过早或过晚
- 测试不同的布林通道参数组合,优化布林通道的长度和标准差倍数
- 优化买入卖出阈值,找到最佳参数以提高获利率
- 尝试基于ATR动态调整止损比例,让止损更符合市场波动性
- 优化仓位管理,例如获利后可适当加仓,控制单笔亏损风险
本策略overall是一个较为简单实用的突破策略。它采用布林通道指标判断行情反转机会,并设置动态阈值进行入场出场。同时,策略还运用了合理的仓位管理、止损条件等来控制风险。在优化几个关键参数后,该策略可以获得较为稳定的回报。它既适合定量交易,也可作为选股或判断市场情绪的辅助工具。总的来说,本策略具有较强的实用性和拓展性。
||
This strategy is a breakout trading strategy based on the Bollinger Bands indicator. It calculates the upper and lower rails of the Bollinger Bands and combines them with dynamically adjustable buy and sell thresholds to automate trading of BTCUSDT on Binance.
The core indicator of this strategy is Bollinger Bands. Bollinger Bands consist of an N-day moving average and upper and lower bands plotted at a standard deviation level above and below it. The Bollinger Bands in this strategy have a length of 20 days and a standard deviation multiplier of 2. When the price approaches or touches the lower rail of the Bollinger Bands, it is considered oversold, and the strategy will open a long position. When the price approaches or touches the upper rail, it is considered overbought, and the strategy will close long positions.
In addition to the Bollinger Bands indicator, this strategy also introduces two adjustable parameters: buy threshold and sell threshold. The buy threshold defaults to 58 points below the lower band and serves as the entry condition for opening long positions. The sell threshold defaults to 470 points above the lower band and serves as the exit condition for closing positions. These thresholds can be dynamically adjusted based on actual market conditions and backtest results to make the strategy more flexible.
When the buy condition is met, the strategy will open a long position using 10% of the account equity. After opening the long position, if the price rises to hit the stop loss level (-125%), positions will be closed by stop loss orders. When the price rises to trigger the sell threshold, the strategy will choose to close all positions to collect profits.
The main advantages of this strategy include:
- Using Bollinger Bands can capture opportunities when prices abnormally deviate from bands and profit from reversals
- Introducing adjustable buy and sell thresholds optimizes entry and exit points
- Taking partial position sizes controls risk
- Setting stop loss condition avoids further losses
- Backtesting with 5-min intervals can capture short-term trading opportunities in a timely manner
There are also some risks with this strategy:
- Bollinger Bands itself is not 100% reliable, prices may oscillate lower for a long time before dropping again
- Improper threshold settings may cause missing the best entry or exit points
- Stop loss setting too loose may fail to stop loss in time, or too tight may cause stop loss too sensitive
- Improper backtesting period selection may take some occasional profits as stable income
Countermeasures:
- Combine more indicators to judge market conditions and avoid false signals of Bollinger Bands
- Test and optimize threshold parameters to find optimal combination
- Test and optimize stop loss conditions to find a balance
- Adopt longer backtesting period to examine stability of the strategy
The strategy can be further optimized in the following aspects:
- Try combining other indicators like KD, RSI to set stricter entry rules, avoid entering too early or too late
- Test different combinations of Bollinger Bands parameters to optimize band length and standard deviation multiplier
- Optimize buy and sell thresholds to improve profit rate
- Try adopting dynamic ATR-based stop loss ratio to match market volatility
- Optimize position sizing, e.g. appropriately pyramiding positions when in profit to control single loss risk
In summary, this is an overall simple and practical breakout strategy. It adopts Bollinger Bands to identify reversal opportunities and sets dynamic thresholds for entry and exit. Meanwhile, reasonable position sizing and stop loss conditions are utilized to control risks. After optimizing several key parameters, this strategy can yield relatively steady returns. It is suitable for algorithmic trading and can also serve as an auxiliary tool for stock picking or gauging market sentiment. Generally speaking, this strategy has strong practicality and extensibility.
[/trans]
Strategy Arguments
Argument | Default | Description |
---|---|---|
v_input_1 | 20 | 布林通道周期 |
v_input_2 | 2 | 标准差倍数 |
v_input_3 | 58 | 買入閾值 |
v_input_4 | 470 | 賣出閾值 |
Source (PineScript)
/*backtest
start: 2023-12-01 00:00:00
end: 2023-12-31 23:59:59
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © SuperDS_BTC
//@version=5
strategy("布林通道策略多5min", overlay=true)
// 布林通道计算
length = input(20, title="布林通道周期")
mult = input(2.0, title="标准差倍数")
basis = ta.sma(close, length)
dev = mult * ta.stdev(close, length)
upper = basis + dev
lower = basis - dev
// 计算买入数量:每次检查仓位的大小
// 每次买入使用总资金的10%
position_size = strategy.equity * 10 / close
// 定義可調整的閾值
buy_threshold = input(58, title="買入閾值")
exit_threshold = input(470, title="賣出閾值")
// 买入条件:当现价低于布林通道的下限减去 buy_threshold
buy_condition = close < lower - buy_threshold
// 卖出条件和结清仓位条件
exit_condition = close > lower + exit_threshold
// 买入逻辑
if buy_condition
strategy.entry("BuyLong", strategy.long, qty=position_size, comment="LongBTC")
// 卖出逻辑
if exit_condition
strategy.close("BuyLong")
// 止损逻辑
stop_loss_percent = -1.25 //止损百分比为-125%
if strategy.position_size > 0
position_profit_percent = (strategy.position_avg_price - close) / strategy.position_avg_price * 100
if position_profit_percent <= stop_loss_percent
strategy.close("BuyLong")
Detail
https://www.fmz.com/strategy/440081
Last Modified
2024-01-26 14:52:59