Strategy · Pine Script v5 · On the chart

Bolinger Bands Strategy

by PlusGenie

This strategy trades mean-reversion bounces using Bollinger Bands and constructs JSON webhook payloads for automated execution.

View on GitHub

GitHub stars1on the repository
Pine versionv5runs as is
Lines of code58
Settings4inputs
LicenceMPL-2.0
Last update2 years ago24 Dec 2023

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new strategy, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart. The trades and results appear in the Strategy Tester tab; adjust the settings with the gear icon.

Source Code

58 lines of Pine Script v5 from src/strategies/strategy_entry_and_close_bb/bolinger-bands-tradingboat.pine, published under MPL-2.0. Keep the author's credit and licence lines when you reuse it.

bolinger-bands-tradingboat.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
//@version=5
strategy("Bolinger Bands Strategy",
     overlay=true,
     initial_capital=10000,
     currency=currency.USD,
     default_qty_type = strategy.percent_of_equity,
     default_qty_value=100,
     commission_type=strategy.commission.cash_per_contract,
     commission_value=0.005, //Interactive Brokers rate
     process_orders_on_close = true)

import AlphaCentauri66367/PineTradingbotWebhook/7 as tv

i_startTime = input.time(title="Start Filter", defval=timestamp("05 Nov 2021 09:30 +0000"), group="Time Filter", tooltip="Start date & time to begin searching for setups")
i_endTime = input.time(title="End Filter",   defval=timestamp("1 Jan 2099 19:30 +0000"), group="Time Filter", tooltip="End date & time to stop searching for setups")
f_dateFilter = time >= i_startTime and time <= i_endTime

source = close
length = input.int(20, minval=1)
mult = input.float(2.0, minval=0.001, maxval=50)
[basis, upper, lower] = ta.bb(source, length, mult)

buyCondition = strategy.position_size == 0 and f_dateFilter and ta.crossover(close, lower)
sellCondition = strategy.position_size > 0 and f_dateFilter and ta.crossunder(close, upper)

plot(upper, 'BB upper', color = color.aqua)
plot(lower, 'BB lower', color = color.aqua)

webhookKey = "WebhookReceived:8c43d5"
orderRef='BB#1'
clientId=1
qty=100
if buyCondition
    msg = tv.makeWebhookJson(webhookKey, orderRef, 'strategy.entrylong', qty, clientId=clientId)
    alert(msg)
    strategy.entry("BBandLE", strategy.long, stop=lower, alert_message = "Current buy " + str.tostring(close))

bgcolor(buyCondition ? color.new(color.blue, 30) : na)
if sellCondition
    msg = tv.makeWebhookJson(webhookKey, orderRef, 'strategy.close', qty, clientId=clientId)
    alert(msg)
    strategy.close("BBandLE", alert_message = "Current close " + str.tostring(close))

//  Moving Average Indicator {
fastAverage = ta.ema(close, 10)
slowAverage = ta.ema(close, 50)
plot(fastAverage, title = "EMA 10", color=color.red)
plot(slowAverage, title = "EMA 50", color=color.red)
// Show the moving average trend with a coloured background
backgroundColor = if close > fastAverage and fastAverage > slowAverage
    color.new(color.green, 85)
else if close < fastAverage and fastAverage < slowAverage
    color.new(color.red, 85)
else
    color.new(color.orange, 90)
bgcolor(backgroundColor, title="EMA Background")
// }

Overview

Bolinger Bands Strategy opens a long position when the price crosses back above the lower band within a specified date filter and closes the position when the price crosses below the upper band. Fast and slow exponential moving averages are also calculated to color the chart background according to trend alignment. Users can adjust the band parameters and time filter range.

Details

Published by

PlusGenie on GitHub

Draws

On the price chart

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

  • The strategy enters trades without a stop loss

Topics

ib-insyncinteractive-brokers-apitradingview

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Start Filtertimetimestamp("05 Nov 2021 09:30 +0000")i_startTime
End Filtertimetimestamp("1 Jan 2099 19:30 +0000")i_endTime
lengthint20length
multfloat2.0mult
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

330 stars

This strategy calculates Bollinger Bands and Aroon oscillator values to identify mean-reversion opportunities. It enters a long position using full equity when the closing price crosses below the lower Bollinger Band while Aroon Up remains above a user-specifi

Strategy v5 Mean reversionVolatility & bands
Updated 2 months ago · None stated GitHub repository of Bollinger bands + Aroon [Alorse]

[TradersPost] Sick Sigma

by TradersPost
228 stars

Sick Sigma detects extreme statistical standard deviation moves (sigma events) to execute trades directly on the main price chart. The strategy supports both momentum and mean-reversion trading styles. Traders can configure calculation lookback periods, sigma

Strategy v6 Volatility & bandsMean reversion Repaints
Updated 3 months ago · None stated GitHub repository of [TradersPost] Sick Sigma

This strategy combines Volume Weighted Moving Average (VWMA) Bollinger Bands with 200-period and 50-period Exponential Moving Averages (EMAs). It identifies long trade opportunities when the 50 EMA is above the 200 EMA and price falls to or below the lower Fib

Strategy v4 TrendVolatility & bands
Updated 2 years ago · GPL-3.0 GitHub repository of Bollinger Band with Fib Golden Ratio (0.618)

Bollinger Bands Strategy

by cklose2000
105 stars

This strategy generates buy and sell signals based on Bollinger Band crossovers combined with a simple moving average trend filter. It enters a long position when price crosses above the lower band while trading above the SMA filter line, and enters a short po

Strategy v5 Volatility & bandsMoving averages
Updated 1 year ago · None stated GitHub repository of Bollinger Bands Strategy

Keltner Channel Trend - Eterna

by EternaHybridExchange
9 stars

This strategy plots a Keltner channel from an EMA basis and ATR bands on the price chart. It enters long when price crosses back above the lower band while trading above a slower trend EMA, and short when price crosses back below the upper band while below tha

Strategy v5 TrendVolatility & bands
Updated 7 months ago · MIT GitHub repository of Keltner Channel Trend - Eterna
5 stars

This strategy identifies shorting opportunities by calculating Fear and Greed zones based on price extremums relative to moving averages and standard deviation bands. It measures price deviation from recent highs or lows to detect extreme market conditions and

Strategy v4 Volatility & bandsMean reversion
Updated 3 years ago · Apache-2.0 GitHub repository of Fear + Greed Reversal Short Strategy

More Volatility & bands scripts

Related on ForexR

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers