Strategy · Pine Script v5 · On the chart

Bolinger Bands Strategy

by PlusGenie

This long-only strategy plots Bollinger Bands, 20 bars and 2.5 deviations by default, along with a 10 and a 50 period EMA and a background that shades the EMA trend.

View on GitHub

GitHub stars1on the repository
Pine versionv5runs as is
Lines of code54
Settings2inputs
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

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

bolinger-bands-tradingboat_future.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=10000000,
     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/10 as tv

source = close
length = input.int(20, minval=1)  // Shorten the length to make the Bollinger Bands more responsive to price movements.
mult = input.float(2.5, minval=0.001, maxval=50)  // Adjust the multiplier to widen/narrow the bands, accommodating the potentially greater volatility in futures.
[basis, upper, lower] = ta.bb(source, length, mult)


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

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

webhookKey = "WebhookReceived:8c43d5"
orderRef='CME202403_BB1'
qty=4
if buyCondition
    msg = tv.makeWebhookJson(webhookKey, orderRef, 'strategy.entrylong', qty, contract='future', ticker='ES', exchange='CME', lastTradeDateOrContractMonth='202403')
    strategy.entry("BBandLE", strategy.long, stop=lower)
    alert(msg, alert.freq_once_per_bar_close)


bgcolor(buyCondition ? color.new(color.blue, 30) : na)
if sellCondition
    msg = tv.makeWebhookJson(webhookKey, orderRef, 'strategy.close', qty, contract='future', ticker='ES', exchange='CME', lastTradeDateOrContractMonth='202403')
    strategy.close("BBandLE")
    alert(msg, alert.freq_once_per_bar_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

When flat, it buys after the close crosses back above the lower band, and it closes the position when the close crosses below the upper band. Each action sends a futures-style webhook message, configured for E-mini S&P contracts, for an Interactive Brokers bridge. It has no stop loss or profit target.

Details

Published by

PlusGenie on GitHub

Draws

On the price chart

Markets

Indices

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
lengthint20length
multfloat2.5mult
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

Alert BB + RSI [Alorse] is a multi-symbol mean-reversion strategy designed for cryptocurrency trading. It evaluates Bollinger Bands and the Relative Strength Index (RSI) across up to 20 user-defined ticker symbols simultaneously. The strategy enters long posit

Strategy v4 Oscillators & momentumVolatility & bands
Updated 2 months ago · None stated GitHub repository of Alert BB + RSI [Alorse]
228 stars

The Mean Reversion Strategy Template calculates a baseline mean using SMA, EMA, or VWAP alongside upper and lower deviation bands based on standard deviation, ATR, or percentage offsets. It generates long and short entries when price touches, bounces from, or

Strategy v6 Mean reversionMoving averages
Updated 3 months ago · None stated GitHub repository of Mean Reversion Strategy Template
106 stars

This strategy backtests a long Bollinger Band deal on the price chart for 3Commas-style bots. It plots short and long simple moving averages, offset bands, and the average entry price of the open deal. A long starts when price crosses the lower band inside a c

Strategy v4 Volatility & bandsMoving averages
Updated 2 years ago · GPL-3.0 GitHub repository of 3Commas Bollinger Strategy

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
104 stars

This strategy combines Bollinger Bands with a short RSI to fade moves that leave the bands and then return. A long requires the prior bar below the lower band and oversold, then a close back inside the band while RSI is between 30 and 50. Shorts mirror that at

Strategy v5 Oscillators & momentumVolatility & bands
Updated 3 years ago · MIT GitHub repository of Bollinger Bands and RSI Strategy
37 stars

This strategy plots Bollinger Bands on the price chart using a simple moving average and a multiple of standard deviation. It places a long stop entry when close crosses above the lower band and a short stop entry when close crosses below the upper band. Pendi

Strategy v5 Volatility & bandsMean reversion
Updated 3 years ago · MIT GitHub repository of Bollinger Bands Strategy directed

More Mean reversion 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