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
Parameter | Argument type | Description | Default Value |
---|---|---|---|
source | pd.Series | Input data series | - |
timeperiod | int | Number of periods for the indicator | 5 |
nbdevup | float | Number of deviations for upper band | 2 |
nbdevdn | float | Number of deviations for lower band | 2 |
matype | int | Type of Moving Average | 0 |
Outputs
The outputs are returned as a tuple of objects. Make sure to unpack them as shown in the example usage.
Output | Type |
---|---|
upperband | np.ndarray |
middleband | np.ndarray |
lowerband | np.ndarray |
Example usage
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)