Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Building custom indicator in Quantopian

Hi, Quantopian company, I am brand new to Quantopian. I want to know if this is a right formula in Quantopian? Thanks!

high_price = history(bar_count=25, frequency='1d',field='high')  
low_price = history(bar_count=25, frequency='1d',field='low')  
close_price =history(bar_count=25, frequency='1d',field='close_price')

K = talib.EMA((close_price - low_price)/(high_price - low_price), timeperiod = 4)  
P = ((K - talib.MIN(K,21))/(talib.MAX(K,21)-talib.MIN(K,21))  
2 responses

Hello Qifeng,

For whatever reason, I couldn't get your code above to work. However, this runs, and it appears to be equivalent:

import talib

def initialize(context):  
    context.stocks = [sid(8554),sid(33652)]

def handle_data(context, data):  
    high_price = history(bar_count=25, frequency='1d',field='high')  
    low_price = history(bar_count=25, frequency='1d',field='low')  
    close_price =history(bar_count=25, frequency='1d',field='close_price')  
    r = (close_price - low_price)/(high_price - low_price)  
    P = {}

    for s in data:  
        K = talib.EMA(r[s],timeperiod = 4)  
        P[s] = (K - talib.MIN(K,21))/(talib.MAX(K,21)-talib.MIN(K,21))  
        print P[s]  

Grant

Hi Grant,Thanks so much for your great answer.