Skip to content

Bollinger Bands

Bollinger Bands are used to identify potential buying and selling opportunities based on price volatility.

Method

tm.ta.bbands(source, timeperiod, nbdevup, nbdevdn, matype)

Inputs

ParameterArgument typeDescriptionDefault Value
sourcepd.SeriesInput data series-
timeperiodintNumber of periods for the indicator5
nbdevupfloatNumber of deviations for upper band2
nbdevdnfloatNumber of deviations for lower band2
matypeintType of Moving Average0

Outputs

OutputType
upperbandnp.ndarray
middlebandnp.ndarray
lowerbandnp.ndarray

Example usage

strategy.py
import tradomate as tm
@tm.strategy()
def my_strategy(config: tm.TradomateConfig, data: tm.TradomateData):
# Trying out Bollinger Bands
upperband, middleband, lowerband = tm.ta.bbands(data.close, timeperiod=5, nbdevup=2, nbdevdn=2, matype=0)
# Get the last value and print
last_value = upperband.iloc[-1]
tm.log(f"Last value of Bollinger Bands is {last_value}")
# Plot the values of upperband
tm.plot(upperband, title="Bollinger Bands", overlay=False)