The Awesome Oscillator (AO) is a momentum indicator used to measure market momentum by comparing the 5-period and 34-period simple moving averages (SMA) of the median price.
- AO helps identify the strength of a market's trend. Positive values indicate bullish momentum, while negative values indicate bearish momentum.
df['ao'] = bta.awesome_oscillator(df, 'high', 'low', 5, 34)['ao']
df
(pandas.DataFrame): Input DataFrame containing thehigh
andlow
columns.high_col
(str): Column name for the high prices. Default is'high'
.low_col
(str): Column name for the low prices. Default is'low'
.window1
(int): Short period for the SMA. Default is5
.window2
(int): Long period for the SMA. Default is34
.fillna
(bool): IfTrue
, fills NaN values with0
. Default isFalse
.
- DataFrame: A DataFrame with the
'ao'
column.
The Chande Momentum Oscillator (CMO) measures the momentum of price changes over a specified period, developed by Tushar Chande.
- CMO oscillates between -100 and 100. Positive values suggest upward momentum, while negative values suggest downward momentum.
df['cmo'] = bta.chande_momentum_oscillator(df)
df['cmo_signal'] = df['cmo'].rolling(window=10).mean() # Using SMA for signal
df
(pandas.DataFrame): Input DataFrame containing theclose
column.length
(int): Lookback period for the CMO calculation. Default is14
.
- DataFrame: A DataFrame with the
'cmo'
column.
The Elliott Wave Oscillator (EWO) is used to identify trends and market patterns. It is calculated as the difference between two simple moving averages (SMA), then normalized by the price.
- EWO helps traders identify the direction of the trend based on the relationship between short-term and long-term moving averages.
df['ewo'] = bta.elliott_wave_oscillator(df, 'close', 5, 35)
df
(pandas.DataFrame): Input DataFrame containing the specified column.column
(str): The column on which EWO is calculated. Default is'close'
.sma1_period
(int): Short period for the SMA. Default is5
.sma2_period
(int): Long period for the SMA. Default is35
.
- DataFrame: A DataFrame with the
'ewo'
column.
The Fisher Stochastic Center of Gravity Indicator, developed by John Ehlers, identifies potential market turning points by calculating the center of gravity of price movements.
- CG values above zero may indicate overbought conditions, while values below zero may suggest oversold conditions.
fscg = bta.ehlers_fisher_stochastic_center_of_gravity(df)
df['cg'] = fscg['cg']
df['trigger'] = fscg['trigger']
df
(pandas.DataFrame): Input DataFrame containinghigh
andlow
columns.length
(int): Lookback period for the indicator. Default is8
.
- DataFrame: A DataFrame with the
'cg'
and'trigger'
columns.
The Intraday Momentum Index (IMI) combines candlestick analysis with the principles of the Relative Strength Index (RSI) to measure intraday momentum. It evaluates the relationship between opening and closing prices to identify potential market trends and reversals.
- IMI Values:
IMI > 70
: Indicates overbought conditions, signaling a potential sell opportunity.IMI < 30
: Indicates oversold conditions, signaling a potential buy opportunity.IMI Between 30 and 70
: Indicates neutral market conditions.
The IMI is particularly useful for short-term trading, where the relationship between open and close prices is significant.
# Calculate IMI and add it to the DataFrame
df['imi'] = bta.calculate_intraday_momentum_index(df, length=14)
df
(pandas.DataFrame): The input DataFrame must contain the following columns:'open'
: Opening price.'close'
: Closing price.
length
(int, default=14
): The lookback period over which gains and losses are summed to calculate the IMI.
pd.Series
: A Pandas Series representing the Intraday Momentum Index (IMI) values.
- The IMI is most effective in volatile markets or when analyzing short-term price movements.
- Ensure the input DataFrame contains the
'open'
and'close'
columns; otherwise, the function will raise aValueError
.
The Kaufman's Adaptive Moving Average (KAMA) adjusts to market noise or volatility, closely following prices when price swings are small and adjusting when price swings widen.
- KAMA helps identify the overall trend, time turning points, and filter price movements in volatile markets.
df['kama'] = bta.kaufmans_adaptive_moving_average(df)['kama']
df
(pandas.DataFrame): Input DataFrame containing theclose
column.close_col
(str): Column name for the close prices. Default is'close'
.window
(int): Period for the efficiency ratio. Default is14
.pow1
(int): Period for the fastest EMA constant. Default is2
.pow2
(int): Period for the slowest EMA constant. Default is30
.fillna
(bool): IfTrue
, fills NaN values with the close prices. Default isFalse
.
- DataFrame: A DataFrame with the
'kama'
column.
Here is the extended documentation, including everything from the MACD function onward in the momentum.py
module. The documentation follows the same format with descriptions, interpretations, usage examples, and parameter explanations.
The MACD (Moving Average Convergence Divergence) is a momentum indicator that shows the relationship between two moving averages of a security’s price. It is commonly used to spot trend direction and strength.
- MACD Line (
macd
): The difference between the short-term and long-term EMAs. A positive value indicates bullish momentum, while a negative value suggests bearish momentum. - Signal Line (
macd_signal
): A smoothed version of the MACD line, used to generate buy or sell signals. - MACD Histogram (
macd_histogram
): The difference between the MACD line and the Signal line. Positive values suggest upward momentum, and negative values suggest downward momentum.
macd_result = bta.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']
df
(pandas.DataFrame): Input DataFrame containing the column to be used for calculation.column
(str): The column on which MACD is to be calculated. Default is'close'
.short_window
(int): The short-term period for the EMA. Default is12
.long_window
(int): The long-term period for the EMA. Default is26
.signal_window
(int): The period for the signal EMA. Default is9
.
- DataFrame: A DataFrame with the
'macd'
,'macd_signal'
, and'macd_histogram'
columns.
The MACD Leader is a variation of the standard MACD that aims to provide an earlier signal using a different calculation method, focusing on faster reaction to market changes.
- MACD Leader is used similarly to the standard MACD, but it attempts to signal trend changes earlier by using a different approach to EMA calculations.
df['macd_leader'] = bta.macd_leader(df, 'close')['macd_leader']
df
(pandas.DataFrame): Input DataFrame containing the source column.src
(str): The column to use for calculations. Default is'close'
.fast_length
(int): Length for the fast EMA. Default is12
.slow_length
(int): Length for the slow EMA. Default is26
.signal_length
(int): Length for the signal EMA. Default is9
.
- DataFrame: A DataFrame with the
'macd_leader'
column.
The MA Streak Indicator tracks the number of bars a given moving average is rising or falling, highlighting trends by color-coding them as positive (green) or negative (red).
- MA Streak shows how long a moving average has been increasing or decreasing, helping to identify the strength and longevity of trends.
df['ma_streak'] = bta.ma_streak(df, length=10, src='close', matype=1)['ma_streak']
df
(pandas.DataFrame): Input DataFrame containing the data.length
(int): Period for the moving average calculation. Default is10
.src
(str): The column name to use for the moving average calculation. Default is'close'
.matype
(int): Type of moving average to use. Options are: 1 - SMA, 2 - EMA, 3 - HMA, 4 - WMA, 5 - VWMA. Default is1
.
- DataFrame: A DataFrame with the
'ma_streak'
column.
The Momentum Divergence (momdiv) indicator identifies potential buy and sell signals by applying Bollinger Bands to a momentum calculation. It also checks if the current high or low breaches the highest high or lowest low over a specified lookback period, providing additional insights into price extremes.
- Buy Signal:
- Triggered when the momentum crosses below the lower Bollinger Band, indicating potential upward price movement.
- Sell Signal:
- Triggered when the momentum crosses above the upper Bollinger Band, signaling potential downward price movement.
- Highest High (coh):
- Indicates the current high equals or exceeds the highest high over the lookback period.
- Lowest Low (col):
- Indicates the current low equals or falls below the lowest low over the lookback period.
momdiv_result = bta.momentum_divergence(df, mom_length=5, bb_length=5, bb_dev=1.0, lookback=5)
df['momentum_divergence_mom'] = momdiv_result['momentum_divergence_mom']
df['momentum_divergence_upperb'] = momdiv_result['momentum_divergence_upperb']
df['momentum_divergence_lowerb'] = momdiv_result['momentum_divergence_lowerb']
df['momentum_divergence_buy'] = momdiv_result['momentum_divergence_buy']
df['momentum_divergence_sell'] = momdiv_result['momentum_divergence_sell']
df['momentum_divergence_coh'] = momdiv_result['momentum_divergence_coh']
df['momentum_divergence_col'] = momdiv_result['momentum_divergence_col']
df
(pandas.DataFrame): The input DataFrame containing OHLC data with the following required columns:close
high
low
mom_length
(int, default=10
): The period for momentum calculation.bb_length
(int, default=20
): The period for Bollinger Bands calculation.bb_dev
(float, default=2.0
): The standard deviation multiplier for Bollinger Bands.lookback
(int, default=30
): The period for detecting the highest high and lowest low.
A DataFrame with the following columns:
momentum_divergence_mom
: The calculated momentum values.momentum_divergence_upperb
: The upper Bollinger Band for momentum.momentum_divergence_lowerb
: The lower Bollinger Band for momentum.momentum_divergence_buy
: Boolean column indicating buy signals (momentum crosses below the lower Bollinger Band).momentum_divergence_sell
: Boolean column indicating sell signals (momentum crosses above the upper Bollinger Band).momentum_divergence_coh
: Boolean column indicating the current high equals or exceeds the highest high over the lookback period.momentum_divergence_col
: Boolean column indicating the current low equals or falls below the lowest low over the lookback period.
- Adjusting
mom_length
can change the sensitivity of the momentum calculation. Shorter lengths respond more quickly to price changes. - The
bb_dev
parameter controls how far the Bollinger Bands are from the mean. A higher value results in wider bands and fewer signals.
The Percentage Price Oscillator (PPO) is a momentum indicator similar to MACD, but it shows the percentage difference between two EMAs, which allows for better comparison across assets of varying prices.
- PPO helps identify trend direction and momentum. The PPO histogram shows the difference between the PPO and the Signal line.
ppo = bta.percentage_price_oscillator(df)
df['ppo'] = ppo['ppo']
df['ppo_signal'] = ppo['ppo_signal']
df['ppo_hist'] = ppo['ppo_hist']
df
(pandas.DataFrame): Input DataFrame containing the close column.close_col
(str): Column name for close prices. Default is'close'
.window_slow
(int): Long-term period for EMA. Default is26
.window_fast
(int): Short-term period for EMA. Default is12
.window_sign
(int): Period for the signal EMA. Default is9
.fillna
(bool): IfTrue
, fills NaN values with 0. Default isFalse
.
- DataFrame: A DataFrame with the
'ppo'
,'ppo_signal'
, and'ppo_hist'
columns.
The Percentage Volume Oscillator (PVO) compares the percentage difference between two volume-based EMAs, helping identify trends in trading volume.
- PVO is used to assess the strength of volume trends. A positive value suggests increased volume, while a negative value suggests lower volume.
pvo = bta.percentage_volume_oscillator(df)
df['pvo'] = pvo['pvo']
df['pvo_signal'] = pvo['pvo_signal']
df['pvo_hist'] = pvo['pvo_hist']
df
(pandas.DataFrame): Input DataFrame containing the volume column.volume_col
(str): Column name for volume data. Default is'volume'
.window_slow
(int): Long-term period for EMA. Default is26
.window_fast
(int): Short-term period for EMA. Default is12
.window_sign
(int): Period for the signal EMA. Default is9
.fillna
(bool): IfTrue
, fills NaN values with 0. Default isFalse
.
- DataFrame: A DataFrame with the
'pvo'
,'pvo_signal'
, and'pvo_hist'
columns.
The Relative Momentum Index (RMI) applies the RSI formula to momentum rather than price, helping identify overbought or oversold conditions based on momentum.
- RMI is similar to RSI but provides more sensitivity to momentum changes, making it useful for spotting potential trend reversals.
df['rmi'] = bta.relative_momentum_index(df, length=20, mom=5)['rmi']
df
(pandas.DataFrame): Input DataFrame containing the data.length
(int): Period for the EMA calculation. Default is20
.mom
(int): Momentum period. Default is5
.
- DataFrame: A DataFrame with the
'rmi'
column.
Sure! Below is the full documentation for all the indicators starting from Relative Momentum Index (RMI) onward in Markdown format. Due to the length, I will break it into multiple parts, but it will cover everything from where we left off.
The Rate of Change (ROC) is a momentum oscillator that measures the percentage change in price between the current price and the price n periods ago.
- ROC values above 0 indicate upward momentum, while values below 0 indicate downward momentum.
df['roc'] = bta.rate_of_change(df, column='close', period=21)['roc']
df
(pandas.DataFrame): Input DataFrame containing the data.column
(str): The column name on which ROC is applied. Default is'close'
.period
(int): Period for the ROC calculation. Default is21
.
- DataFrame: A DataFrame with the
'roc'
column.
The Smoothed Rate of Change (SROC) applies an exponential moving average (EMA) to the Rate of Change (ROC) to smooth out short-term fluctuations.
- SROC provides a smoother momentum signal compared to regular ROC, making it useful for identifying longer-term trends.
df['sroc'] = bta.smoothed_rate_of_change(df, roclen=21, emalen=13, smooth=21)['sroc']
df
(pandas.DataFrame): Input DataFrame containing the data.roclen
(int): Period for the ROC calculation. Default is21
.emalen
(int): Period for the EMA calculation. Default is13
.smooth
(int): Smoothing period for the ROC calculation. Default is21
.
- DataFrame: A DataFrame with the
'sroc'
column.
The Waddah Attar Explosion (ATR) is used to identify potential breakout opportunities by combining the MACD and Bollinger Bands with an ATR-based dead zone line.
- Waddah Attar Explosion helps traders identify breakout situations. The trend_up column signals bullish conditions, while trend_down indicates bearish conditions.
wae = bta.waddah_attar_explosion_atr(df)
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']
df
(pandas.DataFrame): Input DataFrame containingopen
,high
,low
, andclose
columns.sensitivity
(int): Sensitivity factor for the indicator. Default is150
.fast_length
(int): Length for the fast EMA. Default is20
.slow_length
(int): Length for the slow EMA. Default is40
.channel_length
(int): Length for the Bollinger Bands. Default is20
.mult
(float): Standard deviation multiplier for the Bollinger Bands. Default is2.0
.
- DataFrame: A DataFrame with
'trend_up'
,'trend_down'
,'explosion_line'
, and'dead_zone_line'
columns.
The WaveTrend oscillator is used to identify overbought and oversold conditions in the market, providing insights into potential reversals or continuations of trends.
- WaveTrend shows whether the market is overbought or oversold. It has two lines, WT1 and WT2, that can be used to identify potential crossovers indicating buy or sell signals.
wt = bta.wave_trend(df, chlen=10, avg=21, smalen=4)
df['wt1'] = wt['wt1']
df['wt2'] = wt['wt2']
df
(pandas.DataFrame): Input DataFrame containing the data.chlen
(int): Channel length for the EMA calculation. Default is10
.avg
(int): Average period for the EMA calculation. Default is21
.smalen
(int): Period for the SMA calculation. Default is4
.
- DataFrame: A DataFrame with
'wt1'
and'wt2'
columns.
The WaveTrend Oscillator (WTO) is used to identify overbought and oversold conditions in the market by smoothing price data and analyzing trends. It combines two Exponential Moving Averages (EMAs) and measures deviations from them to produce the oscillator.
df['wto'] = bta.wave_trend_oscillator(df, 'close')['wavetrend']
df
(pandas.DataFrame): Input DataFrame containing the source column.src
(str): Column to use for the oscillator calculation. Default is'close'
.n1
(int): Length for the first EMA. Default is8
.n2
(int): Length for the second EMA. Default is12
.
- DataFrame: A DataFrame with a
'wavetrend'
column representing the calculated oscillator.
The QQE Mod is a technical analysis indicator that enhances the standard Relative Strength Index (RSI) by applying smoothing techniques and Bollinger Bands to generate buy and sell signals. It helps identify market trends and breakouts by smoothing out volatility.
qqe_mod_result = bta.qqe_mod(df, rsi_period=6, rsi_smoothing=5, qqe_factor=3, threshold=3, bollinger_length=50, bb_multiplier=0.35)
df['qqe_line'] = qqe_mod_result['qqe_line']
df['histo2'] = qqe_mod_result['histo2']
df['qqe_up'] = qqe_mod_result['qqe_up']
df['qqe_down'] = qqe_mod_result['qqe_down']
df
(pandas.DataFrame): Input DataFrame containing the'close'
column.rsi_period
(int): Period for RSI calculation. Default is6
.rsi_smoothing
(int): Smoothing period for RSI. Default is5
.qqe_factor
(int): Fast QQE Factor. Default is3
.threshold
(int): Threshold value for buy/sell signals. Default is3
.bollinger_length
(int): Length for Bollinger Bands calculation. Default is50
.bb_multiplier
(float): Multiplier for Bollinger Bands. Default is0.35
.rsi_period2
(int): Period for the second RSI calculation. Default is6
.rsi_smoothing2
(int): Smoothing period for the second RSI. Default is5
.qqe_factor2
(float): QQE Factor for the second QQE. Default is1.61
.threshold2
(int): Threshold value for the second QQE. Default is3
.
- DataFrame: A DataFrame with the following columns:
'qqe_line'
: The QQE line.'histo2'
: The histogram showing differences in price momentum.'qqe_up'
: Signals for upward price movement.'qqe_down'
: Signals for downward price movement.
The Relative Strength Index (RSI) is a momentum oscillator that measures the speed and change of price movements. It is commonly used to identify overbought or oversold conditions in the market.
df['rsi'] = bta.relative_strength_index(df, column='close', period=14)['rsi']
df
(pandas.DataFrame): Input DataFrame containing at least the column specified for the RSI calculation.column
(str): The column on which RSI is calculated. Default is'close'
.period
(int): The look-back period for RSI calculation. Default is14
.
- DataFrame: A DataFrame with a
'rsi'
column containing the calculated RSI values.
The Stochastic Momentum Index (SMI) is a momentum indicator developed by William Blau that can help identify trend reversal points by measuring how close the current price is to its recent price range's midpoint.
- SMI values closer to +100 indicate overbought conditions, while values closer to -100 suggest oversold conditions.
df['smi'] = bta.stochastic_momentum_index(df, k_length=9, d_length=3)['smi']
df
(pandas.DataFrame): Input DataFrame containinghigh
,low
, andclose
columns.k_length
(int): Period for %K. Default is9
.d_length
(int): Period for %D. Default is3
.
- DataFrame: A DataFrame with the
'smi'
column.
The Stochastic Oscillator is a momentum indicator that compares the closing price of a security to its price range over a specified period. It helps identify overbought or oversold conditions by measuring the current price relative to the high-low range over a given period.
stoch = bta.stochastics_oscillator(df, 'high', 'low', 'close', 14, 3)
df['stoch'] = stoch['stoch']
df['stoch_signal'] = stoch['stoch_signal']
df['stoch_hist'] = stoch['stoch_hist']
df
(pandas.DataFrame): Input DataFrame containing the price data.high_col
(str): Column name for the high prices. Default is'high'
.low_col
(str): Column name for the low prices. Default is'low'
.close_col
(str): Column name for the close prices. Default is'close'
.window
(int): Lookback period for the Stochastic Oscillator calculation. Default is14
.smooth_window
(int): Lookback period for calculating the Stochastic Signal. Default is3
.fillna
(bool): IfTrue
, fill NaN values. Default isFalse
.
- DataFrame: A DataFrame with the following columns:
'stoch'
: The Stochastic %K line, representing the raw stochastic oscillator value.'stoch_signal'
: The Stochastic %D line, which is a smoothed version of %K.'stoch_hist'
: The Stochastic Histogram, which is the difference between %K and %D.
- The Stochastic Oscillator fluctuates between 0 and 100. Values above 80 indicate overbought conditions, and values below 20 indicate oversold conditions.
- The Stochastic Signal (%D) is a smoothed version of the oscillator and can be used to generate buy/sell signals when it crosses above or below the %K line.
- The Stochastic Histogram represents the difference between the %K and %D lines, providing insight into the momentum of the trend.
The Stochastic RSI is a technical analysis indicator that applies the Stochastic oscillator formula to RSI values, helping identify overbought and oversold conditions more accurately.
- Stochastic RSI generates buy and sell signals when %K and %D lines cross, with %K above %D indicating a potential buy, and %K below %D signaling a potential sell.
stoch_rsi = bta.stochastic_rsi(df, length_rsi=14, length_stoch=14, smooth_k=3, smooth_d=3)
df['stoch_rsi_k'] = stoch_rsi['stoch_rsi_k']
df['stoch_rsi_d'] = stoch_rsi['stoch_rsi_d']
df
(pandas.DataFrame): Input DataFrame containing a'close'
column.length_rsi
(int): Period for the RSI calculation. Default is14
.length_stoch
(int): Period for the Stochastic calculation. Default is14
.smooth_k
(int): Smoothing period for %K line. Default is3
.smooth_d
(int): Smoothing period for %D line. Default is3
.
- DataFrame: A DataFrame with
'stoch_rsi_k'
and'stoch_rsi_d'
columns.
The True Strength Index (TSI) shows both trend direction and overbought/oversold conditions by measuring the strength of price movements.
- TSI above 0 indicates bullish momentum, while values below 0 suggest bearish momentum. It is often used with signal lines to confirm trends.
df['tsi'] = bta.true_strength_index(df, 'close', 25, 13)['tsi']
df
(pandas.DataFrame): Input DataFrame containing theclose
column.close_col
(str): Column name for the close prices. Default is'close'
.window_slow
(int): Long period. Default is25
.window_fast
(int): Short period. Default is13
.fillna
(bool): IfTrue
, fills NaN values with0
. Default isFalse
.
- DataFrame: A DataFrame with the
'tsi'
column.
The Ultimate Oscillator (UO) combines short-term, intermediate-term, and long-term price action into one oscillator, helping to spot potential reversals.
- UO values above 70 suggest overbought conditions, while values
below 30 indicate oversold conditions.
df['uo'] = bta.ultimate_oscillator(df, 'high', 'low', 'close', 7, 14, 28)['uo']
df
(pandas.DataFrame): Input DataFrame containing thehigh
,low
, andclose
columns.high_col
(str): Name of the column containing high price data. Default is'high'
.low_col
(str): Name of the column containing low price data. Default is'low'
.close_col
(str): Name of the column containing close price data. Default is'close'
.window1
(int): Short period. Default is7
.window2
(int): Medium period. Default is14
.window3
(int): Long period. Default is28
.weight1
(float): Weight of short BP average. Default is4.0
.weight2
(float): Weight of medium BP average. Default is2.0
.weight3
(float): Weight of long BP average. Default is1.0
.fillna
(bool): IfTrue
, fills NaN values with50
. Default isFalse
.
- DataFrame: A DataFrame with the
'uo'
column.
The Williams %R is a momentum indicator that measures overbought and oversold levels in the market.
- Williams %R values closer to
-100
indicate oversold conditions, while values closer to0
suggest overbought conditions.
df['williams_r'] = bta.williams_r(df, 'high', 'low', 'close', 14)['williams_r']
df
(pandas.DataFrame): Input DataFrame containing thehigh
,low
, andclose
columns.high_col
(str): Name of the column containing high price data. Default is'high'
.low_col
(str): Name of the column containing low price data. Default is'low'
.close_col
(str): Name of the column containing close price data. Default is'close'
.lbp
(int): Lookback period. Default is14
.fillna
(bool): IfTrue
, fills NaN values with-50
. Default isFalse
.
- DataFrame: A DataFrame with the
'williams_r'
column.