Back to Community
HELP! Where can I find the parameters for the indicators available in TA-LIB?!?!?!?!?!

I am a seasoned trader and investor. I, however, am a noob around code. I understand the basics of python but to implement my strategy I need the use of more indicators available through TA-LIB. I don't know how to call out the indicators in the code nor do i know the parameters that would be within the code for the particular indicator as well.

5 responses

Take a look in the documentation . Scroll down several paragraphs to the section titled "Common Usage: Using TA-Lib". Basically you get the technical data (ie price or volume data) using the 'data.history' function, then use that result in any of the TA-lib functions. Remember to import TA-lib first. Here's an example directly from the help docs.

import talib

def initialize(context):  
    # AAPL  
    context.my_stock = sid(24)

def handle_data(context, data):  
    my_stock_series = data.history(context.my_stock, "price", bar_count=30, frequency="1d")  
    ema_result = talib.EMA(my_stock_series, timeperiod=12)  

The issue with using the TA-lib functions is they only work on a single security at a time. Typically however one has a large universe of securities with the goal of selecting specific securities. This selection is based upon 'factors' generated from the output of TA-lib functions. This implies iterating a TA-lib function over the universe of securities. The best way to do this (assuming daily and not minutely data is required) is to use a pipeline. Here is a link to how this can be implemented (how to use any TA-lib function as a custom factor via iteration)

Some of the TA-lib functions have been graciously re-written to be more efficient and work with pipeline. See here (pipeline 'vector' implementations of a number of TA-lib functions)

Info on all the TA-lib functions and their parameters can be found here (documentation on all the TA-lib functions)

Hope that helps.

@danwhitnable Thank you for the response!
Tremendous help!

why is there a time period of 12 in the "ema result" but not in the data.history for teh my_stock_series?

its gathering the data for the last 30 days, but it is not averaging it or anything correct? and then the timeperiod=12 in teh ema_result does what? wouldnt that be the 12 ema of your context.mystock, but why then grab the 30 day price history in the data?

"why is there a time period of 12 in the "ema result" but not in the data.history for teh my_stock_series?"

The TA-lib functions generally return a series of values. They typically don't return a single value. So, in the case of the above example 'talib.EMA', the function accepts a series of prices and returns a series of exponential moving averages. The input data can be any length. The TA-lib functions will return a series which is the same length as the input data. So, in this case it will return a series of length 30. The first 12 elements of the series (ie 0 through 11) will be NaN but starting with the 12th element they will be the exponential moving averages of the previous 12 days data. If the data is shorter than the timeperiod, you will get a series of all NaN values.

One often just wants the latest value so that is why, in the example, it used the last value in the series to record using the [-1] notation.


As far as why grab more data than you need. Typically not necessary. However, it depends upon what you want to do. If you don't just want the last data value but instead really do want a series (maybe you are calculating RSI and want the average RSI over the last 5 days) then the data will be longer than the timeperiod.

Awesome thank you so much for your help and explaining that to me!:)