Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Signal line for TRIX

import talib

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

def handle_data(context, data):
my_stock_series = data.history(context.my_stock, fields="price", bar_count=11, frequency="1d")
trix_result = talib.TRIX(my_stock_series, timeperiod=9)

record(trix=trix_result[-1])  

signal_result = talib.EMA(trix_result, timeperiod=7)  

record(sig=signal_result[-1])

I'm trying to make a signal line for the TRIX. The signal line is an EMA of the TRIX.

Getting this message:
Exception: inputs are all NaN
There was a runtime error on line 14.

2 responses

This is the ThinkScript I'd like to duplicate to Quantopian.

Begins

declare upper;

input length = 5; #changed to 5 to fit better.
input colorNormLength = 20; #changed to 20 to fit better.
input price = close;
input signalLength = 5; #changed to 5 to fit better.

def tr = ExpAverage(ExpAverage(ExpAverage(Log(price), length), length), length);

def TRIX = (tr - tr[1]) * 10000;
def Signal = ExpAverage(TRIX, signalLength);
def ZeroLine = 0;

def Buy = TRIX crosses above Signal;
def Sell = TRIX crosses below Signal;

AddOrder(OrderType.BUY_AUTO, BUY, OPEN[-1], 1000, Color.ORANGE, color.ORANGE, "" + open[-1]);
AddOrder(OrderType.SELL_AUTO, SELL, OPEN[-1], 1000, Color.MAGENTA, color.MAGENTA, " " + ope

Riley ,

Hope this will help:

# TRIX_SIGNAL Indicator

import talib  
# ---------------------------------------  
stock, period, ema = symbol('AAPL'), 9, 7  
# ---------------------------------------  
def initialize(context):  
    schedule_function(record_trix, date_rules.every_day(), time_rules.market_open(minutes = 65))

def record_trix(context, data):  
    bars = 3*period + ema

    prices = data.history(stock, 'price', bars, '1d')  
    trix = talib.TRIX(prices, period)  
    trix_signal = talib.EMA(trix, ema) 

    record(trix = trix[-1],trix_signal = trix_signal[-1])