161 lines
8.4 KiB
Markdown
161 lines
8.4 KiB
Markdown
|
|||
|
|
> Name
|
||
|
|
|
||
|
|
布林带交叉信号筛选交易策略-Bollinger-Bands-Crossover-Signal-Filtering-Strategy
|
||
|
|
|
||
|
|
> Author
|
||
|
|
|
||
|
|
ChaoZhang
|
||
|
|
|
||
|
|
> Strategy Description
|
||
|
|
|
||
|
|

|
||
|
|
|
||
|
|
[trans]
|
||
|
|
#### 概述
|
||
|
|
这是一个基于布林带指标的交易策略,通过价格与布林带的交叉关系来识别市场趋势和生成交易信号。该策略使用了55周期的移动平均线作为布林带的中轨,并以1.0倍标准差作为布林带的上下轨计算依据。策略的核心是通过价格突破布林带上轨和下轨来确定做多和做空时机。
|
||
|
|
|
||
|
|
#### 策略原理
|
||
|
|
策略的运作原理主要包含以下几个关键部分:
|
||
|
|
1. 布林带计算: 使用55周期简单移动平均线(SMA)作为中轨,标准差乘数为1.0,计算上下轨。
|
||
|
|
2. 信号生成逻辑:
|
||
|
|
- 当收盘价突破上轨时,生成做多信号
|
||
|
|
- 当收盘价突破下轨时,生成做空信号
|
||
|
|
3. 信号确认机制: 使用barssince函数计算距离上次突破的周期数,通过比较多空信号的周期距离来确定最终交易方向。
|
||
|
|
4. 可视化部分: 在图表上通过三角形标记显示交易信号,使用不同颜色区分多空。
|
||
|
|
|
||
|
|
#### 策略优势
|
||
|
|
1. 信号明确: 通过价格与布林带的明确交叉关系生成交易信号,避免了模糊地带。
|
||
|
|
2. 趋势跟随: 策略本质上是趋势跟随型,能够在强势行情中获得较好收益。
|
||
|
|
3. 视觉直观: 通过颜色填充和形状标记,交易信号的识别非常直观。
|
||
|
|
4. 参数灵活: 布林带的周期和标准差倍数可以根据不同市场情况进行调整。
|
||
|
|
5. 系统完整: 包含了完整的信号生成、可视化和报警功能。
|
||
|
|
|
||
|
|
#### 策略风险
|
||
|
|
1. 震荡市风险: 在横盘震荡市场中可能产生频繁的假信号。
|
||
|
|
2. 滞后性风险: 由于使用了较长周期(55)的移动平均线,信号可能存在一定滞后。
|
||
|
|
3. 反转风险: 在趋势突然反转时,可能承受较大回撤。
|
||
|
|
4. 参数敏感性: 布林带参数的选择对策略性能影响较大。
|
||
|
|
|
||
|
|
#### 策略优化方向
|
||
|
|
1. 引入成交量确认: 可以添加成交量指标作为信号确认的辅助条件。
|
||
|
|
2. 动态参数优化: 可以根据市场波动率动态调整布林带的标准差倍数。
|
||
|
|
3. 增加趋势过滤器: 可以添加更长周期的趋势指标来过滤假信号。
|
||
|
|
4. 完善止损机制: 建议增加移动止损或固定止损来控制风险。
|
||
|
|
5. 市场状态分类: 可以增加市场状态识别模块,在不同市场状态下使用不同的参数设置。
|
||
|
|
|
||
|
|
#### 总结
|
||
|
|
这是一个基于布林带的经典趋势跟随策略,通过价格与布林带的交叉关系来捕捉市场趋势。策略设计简洁明了,具有良好的可视化效果和信号生成机制。虽然在震荡市场中可能面临挑战,但通过适当的参数优化和增加辅助指标,可以进一步提升策略的稳定性和可靠性。建议在实盘使用前进行充分的回测和参数优化。 ||
|
||
|
|
|
||
|
|
#### Overview
|
||
|
|
This is a trading strategy based on Bollinger Bands indicator that identifies market trends and generates trading signals through price crossovers with the bands. The strategy uses a 55-period moving average as the middle band and 1.0 standard deviation for calculating the upper and lower bands. The core concept is to determine long and short entry points through price breakouts of the Bollinger Bands.
|
||
|
|
|
||
|
|
#### Strategy Principles
|
||
|
|
The strategy operates on the following key components:
|
||
|
|
1. Bollinger Bands Calculation: Uses 55-period Simple Moving Average (SMA) as the middle band, with a standard deviation multiplier of 1.0 for upper and lower bands.
|
||
|
|
2. Signal Generation Logic:
|
||
|
|
- Long signal generated when closing price breaks above the upper band
|
||
|
|
- Short signal generated when closing price breaks below the lower band
|
||
|
|
3. Signal Confirmation Mechanism: Uses the barssince function to calculate periods since last breakout, comparing the period distance between long and short signals to determine final trading direction.
|
||
|
|
4. Visualization: Displays trading signals with triangle markers on the chart, using different colors for long and short positions.
|
||
|
|
|
||
|
|
#### Strategy Advantages
|
||
|
|
1. Clear Signals: Generates trading signals through definitive price crossovers with Bollinger Bands, avoiding ambiguous zones.
|
||
|
|
2. Trend Following: The strategy is essentially trend-following, capable of capturing good returns in strong market trends.
|
||
|
|
3. Visual Clarity: Trading signals are highly intuitive through color filling and shape markers.
|
||
|
|
4. Flexible Parameters: Bollinger Bands period and standard deviation multiplier can be adjusted for different market conditions.
|
||
|
|
5. Complete System: Includes comprehensive signal generation, visualization, and alert functions.
|
||
|
|
|
||
|
|
#### Strategy Risks
|
||
|
|
1. Choppy Market Risk: May generate frequent false signals in sideways, volatile markets.
|
||
|
|
2. Lag Risk: Due to the relatively long period (55) of moving average, signals may have some delay.
|
||
|
|
3. Reversal Risk: May suffer significant drawdowns during sudden trend reversals.
|
||
|
|
4. Parameter Sensitivity: Strategy performance is highly dependent on Bollinger Bands parameter selection.
|
||
|
|
|
||
|
|
#### Strategy Optimization Directions
|
||
|
|
1. Volume Confirmation: Add volume indicators as auxiliary conditions for signal confirmation.
|
||
|
|
2. Dynamic Parameter Optimization: Dynamically adjust the standard deviation multiplier based on market volatility.
|
||
|
|
3. Add Trend Filter: Incorporate longer-period trend indicators to filter false signals.
|
||
|
|
4. Improve Stop Loss Mechanism: Add trailing stop or fixed stop loss for better risk control.
|
||
|
|
5. Market State Classification: Add market state identification module to use different parameter settings under different market conditions.
|
||
|
|
|
||
|
|
#### Summary
|
||
|
|
This is a classic trend-following strategy based on Bollinger Bands, capturing market trends through price crossovers with the bands. The strategy design is clear and concise, featuring good visualization effects and signal generation mechanisms. While it may face challenges in choppy markets, the strategy's stability and reliability can be further enhanced through appropriate parameter optimization and additional auxiliary indicators. Thorough backtesting and parameter optimization are recommended before live trading.[/trans]
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
> Source (PineScript)
|
||
|
|
|
||
|
|
``` pinescript
|
||
|
|
/*backtest
|
||
|
|
start: 2024-02-19 00:00:00
|
||
|
|
end: 2025-02-16 08:00:00
|
||
|
|
period: 2h
|
||
|
|
basePeriod: 2h
|
||
|
|
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
|
||
|
|
*/
|
||
|
|
|
||
|
|
//@version=5
|
||
|
|
strategy("Bollinger Bands Filter [Strategy]", overlay=true)
|
||
|
|
|
||
|
|
// -- INPUTS (kratke tooltipy, ziadne prelomenie riadku)
|
||
|
|
src = input.source(close, title="Source", tooltip="Source for BB calc")
|
||
|
|
length = input.int(55, minval=1, title="SMA length", tooltip="Period for BB basis")
|
||
|
|
mult = input.float(1.0, minval=0.1, maxval=5, title="Std Dev", tooltip="Std Dev multiplier")
|
||
|
|
CC = input.bool(true, "Color Bars", tooltip="If true, color bars by BB logic")
|
||
|
|
|
||
|
|
// -- Bollinger calc
|
||
|
|
basis = ta.sma(src, length)
|
||
|
|
dev = mult * ta.stdev(src, length)
|
||
|
|
upper = basis + dev
|
||
|
|
lower = basis - dev
|
||
|
|
|
||
|
|
// -- Long/Short logic
|
||
|
|
longCondition = close > upper
|
||
|
|
shortCondition = close < lower
|
||
|
|
|
||
|
|
L1 = ta.barssince(longCondition)
|
||
|
|
S1 = ta.barssince(shortCondition)
|
||
|
|
|
||
|
|
longSignal = L1 < S1 and not (L1 < S1)[1]
|
||
|
|
shortSignal = S1 < L1 and not (S1 < L1)[1]
|
||
|
|
|
||
|
|
// -- Plot signals
|
||
|
|
plotshape(shortSignal ? close : na, color=color.red, style=shape.triangledown, size=size.small, location=location.abovebar, title="Short Signal")
|
||
|
|
plotshape(longSignal ? close : na, color=color.green, style=shape.triangleup, size=size.small, location=location.belowbar, title="Long Signal")
|
||
|
|
|
||
|
|
// -- Plot BB lines
|
||
|
|
plot(upper, color=color.new(color.red, 40), title="Upper BB")
|
||
|
|
plot(lower, color=color.new(color.green,40), title="Lower BB")
|
||
|
|
plot(basis, color=color.new(color.blue, 10), title="Basis")
|
||
|
|
|
||
|
|
// -- Fill
|
||
|
|
fill(plot(na), plot(na)) // 'dummy' fill reset
|
||
|
|
fill(plot(upper, display=display.none), plot(basis, display=display.none), color=color.new(color.teal, 80))
|
||
|
|
fill(plot(lower, display=display.none), plot(basis, display=display.none), color=color.new(color.orange, 80))
|
||
|
|
|
||
|
|
// -- barcolor
|
||
|
|
bcol = close > upper ? color.lime : close < lower ? color.red : na
|
||
|
|
barcolor(CC ? bcol : na)
|
||
|
|
|
||
|
|
// -- Alerts
|
||
|
|
alertcondition(longSignal, title="Long - BB", message="BB Filter Long")
|
||
|
|
alertcondition(shortSignal, title="Short - BB", message="BB Filter Short")
|
||
|
|
|
||
|
|
// -- Strategy entries
|
||
|
|
if longSignal
|
||
|
|
strategy.entry("Long", strategy.long)
|
||
|
|
|
||
|
|
if shortSignal
|
||
|
|
strategy.entry("Short", strategy.short)
|
||
|
|
|
||
|
|
```
|
||
|
|
|
||
|
|
> Detail
|
||
|
|
|
||
|
|
https://www.fmz.com/strategy/482443
|
||
|
|
|
||
|
|
> Last Modified
|
||
|
|
|
||
|
|
2025-02-18 14:47:16
|