
This strategy is an advanced quantitative trading system based on Bollinger Bands with dynamic stop-loss and take-profit mechanisms. The core idea is to capture market momentum through breakouts of Bollinger Bands while managing risk using pip-based SL/TP levels. The strategy is applicable to various trading instruments and can be adapted to different market conditions through parameter optimization.
The strategy is based on the following core principles: 1. Uses a 20-period Simple Moving Average (SMA) as the middle band, with 2 standard deviations for upper and lower bands. 2. Generates long signals when price breaks above the lower band and closes above it; generates short signals when price breaks below the upper band and closes below it. 3. Implements dynamic SL/TP based on pips, with default settings of 10 pips for stop-loss and 20 pips for take-profit. 4. Adapts to different trading instruments through the pipValue parameter, making the strategy universal.
This is a well-designed quantitative trading strategy that captures market opportunities through Bollinger Bands breakouts with scientific risk management. The strategy offers good scalability and adaptability, with potential for further performance enhancement through suggested optimizations. It is suitable for investors interested in medium to long-term trend trading.
/*backtest
start: 2022-02-09 00:00:00
end: 2025-02-06 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Enhanced Bollinger Bands Strategy with SL/TP", overlay=true,
slippage=2)
// 入力パラメータの改善
length = input.int(20, "SMA Length", minval=1)
mult = input.float(2.0, "Standard Deviation Multiplier", minval=0.001, maxval=50)
enableLong = input.bool(true, "Enable Long Positions")
enableShort = input.bool(true, "Enable Short Positions")
pipValue = input.float(0.0001, "Pip Value", step=0.00001)
slPips = input.float(10, "Stop Loss (Pips)", minval=0)
tpPips = input.float(20, "Take Profit (Pips)", minval=0)
showBands = input.bool(true, "Show Bollinger Bands")
showSignals = input.bool(true, "Show Entry Signals")
// ボリンジャーバンド計算
basis = ta.sma(close, length)
dev = mult * ta.stdev(close, length)
upper = basis + dev
lower = basis - dev
// 可視化
plot(showBands ? basis : na, "Basis", color=color.blue)
u = plot(showBands ? upper : na, "Upper", color=color.red)
l = plot(showBands ? lower : na, "Lower", color=color.green)
fill(u, l, color=color.new(color.purple, 90))
// エントリー条件の改善
longCondition = ta.crossover(close, lower) and close > lower and enableLong
shortCondition = ta.crossunder(close, upper) and close < upper and enableShort
// ポジション管理
calcSlPrice(price, isLong) => isLong ? price - slPips * pipValue : price + slPips * pipValue
calcTpPrice(price, isLong) => isLong ? price + tpPips * pipValue : price - tpPips * pipValue
// エントリー&エグジットロジック
if longCondition
strategy.entry("Long", strategy.long, limit=lower)
strategy.exit("Long Exit", "Long",
stop=calcSlPrice(lower, true),
limit=calcTpPrice(lower, true))
if shortCondition
strategy.entry("Short", strategy.short, limit=upper)
strategy.exit("Short Exit", "Short",
stop=calcSlPrice(upper, false),
limit=calcTpPrice(upper, false))
// シグナル可視化
plotshape(showSignals and longCondition, style=shape.triangleup, location=location.belowbar, color=color.green, size=size.small)
plotshape(showSignals and shortCondition, style=shape.triangledown, location=location.abovebar, color=color.red, size=size.small)