The Bamboo TA Indicators module provides a comprehensive suite of technical analysis tools for trading. This module imports various submodules, each dedicated to a specific category of technical indicators.
See my Youtube channel for Freqtrade tutorials, Tradingview knowledge and video's about trading strategies and algorithms I tested.
See my Patreon page for all the algorithmic strategies code (trading algorithms and automated backtests). These are all based on the Freqtrade trading bot btw.
For the Strategy League (an overview of all the trading strategies/algorithms I tested) go to dutchalgotrading.com. Ths league contains a ranked list with all the tested strategies I present on my Youtube channel and Patreon page
You can support my work by becoming a Patron on Patreon.
For one-time donations you can visit Ko-fi.com
Or send some crypto to the following addresses:
- BTC : bc1qrtmdycvzc2vntx5jmg86qysnsm6h3xa9valu0e
- ETH : 0xa27966A67F8B1225116509f6503EDf0534DE2927
- DOGE: DEPuQLhViQDtZcyXtaqqLSPQWmMs5cckht
- SOL : FDiyWgFRsLAMCuzAiuDe9yZ8BYsVnn244zYfqEz7bWom
- ADA : addr1qxyr5xxvp52vf9zmpt8gtxfnkfjs5gzxh0sm2j504wgsr2vg8gvvcrg5cj29kzkwskvn8vn9pgsydwlpk49gl2u3qx5spl8gf4
- PEPE: 0xa27966A67F8B1225116509f6503EDf0534DE2927
- SHIB: 0xa27966A67F8B1225116509f6503EDf0534DE2927
Install bamboo-ta from Pypi with:
pip install bamboo-ta
Or you can install this directly from the Github repository with the following command:
$ pip install -U git+https://github.com/DutchCryptoDad/bamboo-ta
The bleeding edge development version can be installed with:
$ pip install -U git+https://github.com/DutchCryptoDad/bamboo-ta.git@development
Using the complete module all at once.
-
Importing the complete library: Import the library into your Python scripts or Notebook.
import bamboo_ta as bta
-
Applying Indicators: Use the imported indicators on your data.
df['lsma'] = bta.calculate_lsma(df, 14)
Or individual indicators.
-
Importing Indicators: Import the necessary submodules or individual indicators directly from
bamboo_ta
.from bamboo_ta.trend import AlligatorBands, BollingerTrend, EMA, HMA, LSMA, SMA, WMA, ZLEMA
-
Applying Indicators: Use the imported indicators on your data.
result = AlligatorBands(df, "high", 13, 8, 5, jaw_shift=8, teeth_shift=5, lips_shift=3)
-
Combining Indicators: Combine multiple indicators for comprehensive analysis.
df['ema'] = EMA(df, "close", 21) df['sma'] = SMA(df, "close", 50)
-
candles
- Description: Contains indicators related to candlestick patterns.
- Indicators:
- HeikinAshi: Heikin Ashi candlesticks with optional pre and post smoothing.
- Usage:
ha_df = HeikinAshi(df, pre_smoothing_period=14, post_smoothing_period=14) df['HA_Close'] = ha_df['HA_Close'] df['HA_Open'] = ha_df['HA_Open'] df['HA_High'] = ha_df['HA_High'] df['HA_Low'] = ha_df['HA_Low']
- Usage:
- LinRegCandles: Linear Regression Candles with optional signal line.
- Usage:
lr_df = LinRegCandles(df, linreg_length=11, sma_signal=True, signal_length=11) df['LRC_Open'] = lr_df['bopen'] df['LRC_High'] = lr_df['bhigh'] df['LRC_Low'] = lr_df['blow'] df['LRC_Close'] = lr_df['bclose'] df['LRC_Signal'] = lr_df['signal']
- Usage:
- Exhaustion_Bars: Leledc Exhaustion Bars - Extended.
- Usage:
exhaustion = Exhaustion_Bars(df) df['leledc_major'] = exhaustion['leledc_major'] df['leledc_minor'] = exhaustion['leledc_minor']
- Usage:
- Dynamic_Exhaustion_Bars: Dynamic Leledc Exhaustion Bars.
- Usage:
dynamic_exhaustion = Dynamic_Exhaustion_Bars(df) df['dynamic_leledc_major'] = dynamic_exhaustion['leledc_major'] df['dynamic_leledc_minor'] = dynamic_exhaustion['leledc_minor']
- Usage:
- Pinbar: Price Action Indicator.
- Usage:
pin = Pinbar(df) df['pinbar_sell'] = pin['pinbar_sell'] df['pinbar_buy'] = pin['pinbar_buy']
- Usage:
- HeikinAshi: Heikin Ashi candlesticks with optional pre and post smoothing.
-
cycles
- Description: Includes indicators for cycle analysis.
-
momentum
- Description: Provides momentum-based indicators.
- Indicators:
- CMO: Chande Momentum Oscillator.
- Usage:
cmo = CMO(df, length=14) df['cmo'] = cmo['cmo']
- Usage:
- EWO: Elliott Wave Oscillator.
- Usage:
df['ewo'] = EWO(df, "close", 5, 35)
- Usage:
- MACD: Moving Average Convergence Divergence.
- Usage:
macd_result = MACD(df, "close", 12, 26, 9) df['macd'] = macd_result['MACD'] df['macd_signal'] = macd_result['MACD_signal'] df['macd_histogram'] = macd_result['MACD_histogram']
- Usage:
- MACD_Leader: MACD Leader.
- Usage:
macd_leader = MACD_Leader(df, 'close') df['macd_leader'] = macd_leader['macd_leader']
- Usage:
- Inverse_Fisher_Transform: Inverse Fisher Transform.
- Usage:
ift = Inverse_Fisher_Transform(df) df['ift'] = ift['ift'] # Optional levels df['level_1_35'] = 1.35 df['level_0_5'] = 0.5 df['level_0'] = 0 df['level_minus_0_5'] = -0.5 df['level_minus_1'] = -1
- Usage:
- Waddah_Attar_Explosion: Waddah Attar Explosion Indicator.
- Usage:
WAE = Waddah_Attar_Explosion(df, sensitivity=150, fast_length=20, slow_length=40, channel_length=20, mult=2.0) df['trend_up'] = WAE['trend_up'] df['trend_down'] = WAE['trend_down'] df['explosion_line'] = WAE['explosion_line'] df['dead_zone_line'] = WAE['dead_zone_line']
- Usage:
- WaveTrend_Oscillator: WaveTrend Oscillator.
- Usage:
wt = WaveTrend_Oscillator(df, 'close', n1=8, n2=12) df['wavetrend'] = wt['wavetrend']
- Usage:
- RSI: Relative Strength Index.
- Usage:
df['rsi'] = RSI(df, "close", 14)
- Usage:
- Fisher_cg: Fisher Stochastic Center of Gravity.
- Usage:
fisher = Fisher_cg(df) df['fisher_cg'] = fisher['fisher_cg'] df['fisher_sig'] = fisher['fisher_sig']
- Usage:
- QQE_Mod: QQE Mod Indicator.
- Usage:
qqe_mod = QQE_Mod(df, rsi_period=6, rsi_smoothing=5, qqe_factor=3, threshold=3, bollinger_length=50, bb_multiplier=0.35, rsi_period2=6, rsi_smoothing2=5, qqe_factor2=1.61, threshold2=3) df['QQE_Line'] = qqe_mod['QQE_Line'] df['Histo2'] = qqe_mod['Histo2'] df['QQE_Up'] = qqe_mod['QQE_Up'] df['QQE_Down'] = qqe_mod['QQE_Down']
- Usage:
- MAStreak: MA Streak Indicator.
- Usage:
df['mastreak'] = MAStreak(df, period=4, column='close')
- Usage:
- RMI: Relative Momentum Index.
- Usage:
df['rmi'] = RMI(df, length=20, mom=5)
- Usage:
- ROC: Rate of Change.
- Usage:
df['roc'] = ROC(df, column='close', period=21)
- Usage:
- SROC: Smoothed Rate of Change.
- Usage:
df['sroc'] = SROC(df, roclen=21, emalen=13, smooth=21)
- Usage:
- CMO: Chande Momentum Oscillator.
-
performance
- Description: Contains performance-related indicators.
-
statistics
- Description: Statistical indicators for trading analysis.
-
trend
- Description: Includes trend-based indicators.
- Indicators:
- AlligatorBands: Bill Williams Alligator Indicator.
- Usage:
alligator_result = AlligatorBands(df, "high", 13, 8, 5, jaw_shift=8, teeth_shift=5, lips_shift=3) df['jaw'] = alligator_result['jaw'] df['teeth'] = alligator_result['teeth'] df['lips'] = alligator_result['lips']
- Usage:
- BollingerTrend: Bollinger Trend Indicator.
- Usage:
df['BBTrend'] = BollingerTrend(df, "close", 20, 50, 2.0)
- Usage:
- BollingerTrendFastWithMA: Bollinger Trend Indicator with selectable Moving Average.
- Usage:
result = BollingerTrendFastWithMA(df, column="close", short_length=10, long_length=50, short_stddev=1.0, long_stddev=2.0, ma_type="SMA", ma_length=14) df['BBTrend'] = result['BBTrend'] df['BBTrendMA'] = result['BBTrendMA']
- Usage:
- EMA: Exponential Moving Average.
- Usage:
df['ema'] = EMA(df, "close", 21)
- Usage:
- HMA: Hull Moving Average.
- Usage:
df['hma'] = HMA(df, "close", 9)
- Usage:
- LSMA: Least Squares Moving Average.
- Usage:
df['lsma'] = LSMA(df, "close", 50)
- Usage:
- SMA: Simple Moving Average.
- Usage:
df['sma'] = SMA(df, "close", 50)
- Usage:
- WMA: Weighted Moving Average.
- Usage:
df['wma'] = WMA(df, "close", 9)
- Usage:
- ZLEMA: Zero Lag Exponential Moving Average.
- Usage:
df['zlema'] = ZLEMA(df, "close", 21)
- Usage:
- Breakouts: S/R Breakouts and Retests.
- Usage:
breakout = Breakouts(df) df['support_level'] = breakout['support_level'] df['resistance_level'] = breakout['resistance_level'] df['support_breakout'] = breakout['support_breakout'] df['resistance_breakout'] = breakout['resistance_breakout'] df['support_retest'] = breakout['support_retest'] df['potential_support_retest'] = breakout['potential_support_retest'] df['resistance_retest'] = breakout['resistance_retest'] df['potential_resistance_retest'] = breakout['potential_resistance_retest']
- Usage:
- SSLChannels: SSL Channels.
- Usage:
ssl_down, ssl_up = SSLChannels(df, length=10, mode='sma') df['ssl_down'] = ssl_down df['ssl_up'] = ssl_up
- Usage:
- SSLChannelsATR: SSL Channels with ATR.
- Usage:
ssl_down, ssl_up = SSLChannelsATR(df, length=7) df['ssl_atr_down'] = ssl_down df['ssl_atr_up'] = ssl_up
- Usage:
- PCC: Percent Change Channel.
- Usage:
upper, rangema, lower = PCC(df, period=20, mult=2) df['pcc_upper'] = upper df['pcc_rangema'] = rangema df['pcc_lower'] = lower
- Usage:
- T3: T3 Average.
- Usage:
df['t3_average'] = T3(df, length=5)
- Usage:
- AlligatorBands: Bill Williams Alligator Indicator.
-
utility
- Description: Utility functions and helper methods for technical analysis.
- Functions:
- Calculate_Exhaustion_Candles: Calculate the average consecutive length of ups and downs.
- Usage:
maj_qual, min_qual = Calculate_Exhaustion_Candles(df, window, zscore_multi)
- Usage:
- Calculate_Exhaustion_Lengths: Calculate the average length of peaks and valleys.
- Usage:
maj_len, min_len = Calculate_Exhaustion_Lengths(df)
- Usage:
- Consecutive_Count: Calculate the average consecutive count of non-zero differences.
- Usage:
avg_consecutive = Consecutive_Count(consecutive_diff)
- Usage:
- Linear_Growth: Simple linear growth function.
- Usage:
growth_value = Linear_Growth(start, end, start_time, end_time, trade_time)
- Usage:
- Linear_Decay: Simple linear decay function.
- Usage:
decay_value = Linear_Decay(start, end, start_time, end_time, trade_time)
- Usage:
- populate_leledc_major_minor: Populate Leledc Major and Minor columns.
- Usage:
df = populate_leledc_major_minor(df, maj_qual, min_qual, maj_len, min_len)
- Usage:
- True_Range: Calculate True Range (TR).
- Usage:
tr = True_Range(df)
- Usage:
- ZScore: Calculate the z-score of a series.
- Usage:
zscore = ZScore(series, window=500)
- Usage:
- ATR: Calculate the Average True Range (ATR).
- Usage:
atr = ATR(df, period=14)
- Usage:
- RMA: Calculate the Relative Moving Average (RMA).
- Usage:
rma = RMA(series, period)
- Usage:
- Calculate_Exhaustion_Candles: Calculate the average consecutive length of ups and downs.
-
volatility
- Description: Volatility indicators.
- Indicators:
- BollingerBands: Calculates Bollinger Bands (upper, middle, lower bands).
- Usage:
bb_result = BollingerBands(df, "close", 21, 2, 0) df['bb_upper'] = bb_result['BB_upper'] df['bb_middle'] = bb_result['BB_middle'] df['bb_lower'] = bb_result['BB_lower']
- Usage:
- TR: True Range (TR) calculation.
- Usage:
tr = TR(df)
- Usage:
- BollingerBands: Calculates Bollinger Bands (upper, middle, lower bands).
-
volume
- Description: Provides volume-based indicators.
- Indicators:
- OBV_Oscillator: On Balance Volume Oscillator.
- Usage:
obv_osc = OBV_Oscillator(df, n1=10, n2=21) df['OBV_Oscillator'] = obv_osc['OBV_Oscillator']
- Usage:
- OBV_Oscillator: On Balance Volume Oscillator.
Example script:
# -*- coding: utf-8 -*-
# Import necessary libraries
import pandas_ta as pta
import bamboo_ta as bta
import pandas as pd
from pandas import DataFrame
import numpy as np
# create dataframe and read the json data in the datasets directory
df = pd.read_json("./testdata/BTC_USDT-1d.json")
# name the columns that are loaded into the dataframe
df.columns = ['date', 'open', 'high', 'low', 'close', 'volume']
# the date column consists of unix time in milliseconds, so this command changes this data into human readable form.
df['date'] = (pd.to_datetime(df['date'], unit='ms'))
print(df) # This command outputs the dataframe
# Using the pandas_ta library
df['imi_ema'] = pta.ema(close=df['close'], length=7)
df['lsma'] = bta.calculate_lsma(df, 14) # Using the bamboo_ta library
print(df)
Output:
➜ python test.py
date open high low close volume
0 2017-08-17 4261.48 4485.39 4200.74 4285.08 795.150377
1 2017-08-18 4285.08 4371.52 3938.77 4108.37 1199.888264
2 2017-08-19 4108.37 4184.69 3850.00 4139.98 381.309763
3 2017-08-20 4120.98 4211.08 4032.62 4086.29 467.083022
4 2017-08-21 4069.13 4119.62 3911.79 4016.00 691.743060
... ... ... ... ... ... ...
1967 2023-01-05 16850.36 16879.82 16753.00 16831.85 163473.566410
1968 2023-01-06 16831.85 17041.00 16679.00 16950.65 207401.284150
1969 2023-01-07 16950.31 16981.91 16908.00 16943.57 104526.568800
1970 2023-01-08 16943.83 17176.99 16911.00 17127.83 135155.896950
1971 2023-01-09 17127.83 17398.80 17104.66 17178.26 266211.527230
[1972 rows x 6 columns]
date open high low close volume imi_ema lsma
0 2017-08-17 4261.48 4485.39 4200.74 4285.08 795.150377 NaN NaN
1 2017-08-18 4285.08 4371.52 3938.77 4108.37 1199.888264 NaN NaN
2 2017-08-19 4108.37 4184.69 3850.00 4139.98 381.309763 NaN NaN
3 2017-08-20 4120.98 4211.08 4032.62 4086.29 467.083022 NaN NaN
4 2017-08-21 4069.13 4119.62 3911.79 4016.00 691.743060 NaN NaN
... ... ... ... ... ... ... ... ...
1967 2023-01-05 16850.36 16879.82 16753.00 16831.85 163473.566410 16737.537534 16633.800286
1968 2023-01-06 16831.85 17041.00 16679.00 16950.65 207401.284150 16790.815651 16678.202286
1969 2023-01-07 16950.31 16981.91 16908.00 16943.57 104526.568800 16829.004238 16746.722286
1970 2023-01-08 16943.83 17176.99 16911.00 17127.83 135155.896950 16903.710678 16816.734571
1971 2023-01-09 17127.83 17398.80 17104.66 17178.26 266211.527230 16972.348009 16930.485143
[1972 rows x 8 columns]
After creating and testing the code, make a Python pip package as follows:
Update the file setup.py
and update version number.
In the library folder, create the package
python3 setup.py sdist bdist_wheel
Before uploading the package to Pypi it is wise to test the package on your system.
Load the package to the system with:
pip install .
After you've checked that everything is worknig correctly, then use the following command to upload to Pypi.
You'll have to install twine for this (pip install twine
or sudo apt install twine
)
When you get the error:
ImportError: cannot import name 'appengine' from 'requests.packages.urllib3.contrib' (/home/user/.local/lib/python3.10/site-packages/urllib3/contrib/__init__.py)
You should do a pip install --upgrade twine requests-toolbelt
.
# Check first
twine check dist/*
# Test upload first
twine upload -r testpypi dist/*
# Upload to Pypi
twine upload dist/*
Note: uploading new versions requires to delete the older versions from the /dist folder.
Another option is to use the --skip-existing
option like this:
# Testpypi
twine upload -r testpypi dist/* --skip-existing
# ProductionPypi
twine upload -r pypi dist/* --skip-existing
First create an API token (at https://test.pypi.org/manage/account/token/).
Create a file .pypirc in your home folder (e.g. nano $HOME/.pypirc
)
Add the given token to the file like this:
[testpypi]
username = __token__
password =
pypi-AgENdGVzdC5weXtMjBjOS00ZjgxLWIyZDMtYWViMDAwOTk3MWZmAAIqWzMsImU3YjkzMGVmLWQzMGItNGFhYi1iNB6NZ-rSrzc8UXHRmWp5fzZwP
[pypi]
username = __token__
password =
pypi-AgEIcHlwaS5vcmcCJDgxYWFiYjYwLTMxYmUtNDczZC1hNjBhLTU0MDJhNmQ2NmZhMgAQ3NTAtOGVkNy0xN2U0NmU0MjEzMQFAYWNj0FcsP-Slnj9-wkEWWwQXkaw
Save the file and reload environment if necessary.
Now you an upload libraries without having to use the password.