Bollinger Bands (how to write an indicator)
All plugins

Plugin libraryExamples

Plugin

Bollinger Bands (how to write an indicator)

A short streaming indicator to copy from: one bar in, the middle, upper and lower band out.

IndicatorNo networkDesktop onlyv1.0.0

About

This plugin exists to be read. It shows the whole shape of an indicator plugin in one file: a class that takes one bar per update, keeps only the window it needs, returns None while it warms up, and exposes extra lines as properties beside value.

The engine already has Bollinger Bands built in (ctx.ind("bb")), drawn on the chart and available in every language. Use that one in a strategy; use this one as the starting point for an indicator of your own.

Parameters

NameTypeDefaultRange or optionsDescription
periodint20min 2, max 200Bars in the window the average and the standard deviation are taken over.
multfloat2min 0.5, max 5How many standard deviations the upper and lower band sit from the middle.

Use it in a strategy

pythonbands = ctx.plugin_indicator("bollinger_bands", "bollinger", {"period": 20, "mult": 2.0})
if bands is not None and bands.value is not None:
    close = ctx.bars(1)[-1].close
    if close < bands.lower:
        ctx.signal("LONG")

What it provides

valueValueThe middle band, the simple moving average of the close. None during warm up.
upperValueThe middle band plus mult population standard deviations.
lowerValueThe middle band minus mult population standard deviations.

Limits

  • A plugin indicator is not drawn on the chart and is not available in Blocks, Pine, Rust or C#; it runs on the run's own instrument only.
OrionQuant