This strategy is a quantitative trading system based on Bollinger Bands and price mean reversion principles. It monitors price deviation from the moving average, combined with Bollinger Bands breakout signals, to trade when expecting price regression after market overbought/oversold conditions. The strategy uses percentage thresholds to measure price deviation and sets reasonable trigger conditions to filter false signals and improve trading accuracy.
The core logic is based on the following key elements:
This strategy captures market overbought/oversold opportunities through Bollinger Bands and mean reversion principles, effectively controlling trading risks with reasonable deviation thresholds and status tracking mechanisms. The strategy framework has good scalability and can adapt to different market environments through parameter optimization and functionality improvements. It’s recommended to focus on risk control in live trading and adjust parameters according to specific instrument characteristics.
/*backtest start: 2024-12-06 00:00:00 end: 2025-01-04 08:00:00 period: 2h basePeriod: 2h exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ //@version=5 strategy("Estratégia com Bandas de Bollinger e Sinal de Retorno", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=200) // Configurações das Bandas de Bollinger length = input.int(20, title="Período da média") mult = input.float(2.0, title="Desvio padrão") bbBasis = ta.sma(close, length) bbUpper = bbBasis + mult * ta.stdev(close, length) bbLower = bbBasis - mult * ta.stdev(close, length) // Configuração para a distância da média percent_threshold = input.float(3.5, title="Distância da média (%)") / 100 dist_from_mean = 0.0 trigger_condition = false if not na(bbBasis) dist_from_mean := math.abs(close - bbBasis) / bbBasis trigger_condition := dist_from_mean >= percent_threshold // Variáveis para identificar o estado do afastamento var bool is_outside = false var color candle_color = color.new(color.white, 0) if trigger_condition is_outside := true if is_outside and close <= bbUpper and close >= bbLower is_outside := false candle_color := color.new(color.blue, 0) // Atribui uma cor válida else candle_color := color.new(color.white, 0) // Aplicar cor às velas barcolor(candle_color) // Plotar Bandas de Bollinger plot(bbBasis, color=color.yellow, title="Média") plot(bbUpper, color=color.red, title="Banda Superior") plot(bbLower, color=color.green, title="Banda Inferior") // Lógica de entrada e saída longCondition = not is_outside and close > bbUpper if (longCondition) strategy.entry("Buy", strategy.long) shortCondition = not is_outside and close < bbLower if (shortCondition) strategy.entry("Sell", strategy.short)