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:
There are also some risks with this strategy:
Countermeasures:
The strategy can be further optimized in the following aspects:
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.
/*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")