Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Attempting to create a Directional Trend Index?

Hello!
So this is my first time posting in the community forum! I believe my problem is that I am trying to run a talib EMA function over only a single data point and I need a numpy.arrry of at least 14 for this to happen but I'm unsure of how to achieve that desired goal? Any help would be enormously appreciated!

import talib  
import numpy as np  
import pandas as pd

# Put any initialization logic here.  The context object will be passed to  
# the other methods in your algorithm.  
def initialize(context):  
    context.stock = sid(24)  
    context.trailing_20 = []  
    set_long_only()

# Will be called on every trade event for the securities you specify.  
def handle_data(context, data):  
    price = data[context.stock].price  
    # Load historical data for the stocks  
    high =  history(20, '1d', 'high')  
    stock_high = high[context.stock]  
    if (stock_high[-1] - stock_high[-2]) > 0:  
        xHMU = (stock_high[-1] - stock_high[-2])  
    else:  
        xHMU = 0  
    low =  history(20, '1d', 'low')  
    stock_low = low[context.stock]  
    if (stock_low[-1] - stock_low[-2]) < 0:  
        xLMD = -(stock_low[-1] - stock_low[-2])  
    else:  
        xLMD = 0  
    xPrice = (xHMU - xLMD)

    record(xPrice = xPrice)  
    Where_I_Need_Help = talib.EMA(xPrice, timeperiod=14)