Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Language problem (very newbie)

Hello, im Jesús from Spain. Im very noob on quantopian and python in general,
i need help with my first steps in this world

    roc1 = talib.ROC(prices[stock], timeperiod=11)[-1]  
    log.info("Roc1 - %.2f" %roc1 )  
    roc2 = talib.ROC(prices[stock],timeperiod=14)[-1]  
    log.info("Roc2 - %.2f" %roc2)  
    roc = roc1 + roc2  
    log.info("Suma de ROCs - %.2f" %roc)  
    cop = talib.WMA(roc, timeperiod=10)  
    log.info("Coppock - %.2f" %cop)  
    cops[stock] = cop  
    current = curr[stock]  
    closes = close[stock]

Im want to create a coppock curve in python, all code its ok but...

    cop = talib.WMA(roc, timeperiod=10)

this line is wrong... why ?

TypeError: Argument 'real' has incorrect type (expected numpy.ndarray, got numpy.float64)
There was a runtime error on line 39.

Thanks for all, and sorry for my english.

2 responses

Jesús from Spain,

Try this:

# Coppock Curve Indicator

import talib  
# ---------------------------------  
stock = symbol('SPY')  
roc_1, roc_2, cop_wma = 11, 14, 10  
# ---------------------------------  
def initialize(context):  
    schedule_function(Coppock_Curve, date_rules.every_day(), time_rules.market_close(minutes = 1)) 

def Coppock_Curve(context,data):  
    bars = roc_1 + roc_2 + cop_wma + 1 

    prices = data.history(stock, 'price', bars, '1d').dropna()   

    roc1 = talib.ROC(prices, roc_1)  
    roc2 = talib.ROC(prices, roc_2)  
    roc = roc1[-cop_wma:] + roc2[-cop_wma:]  
    Coppock = talib.WMA(roc, cop_wma) 

    log.info("Roc1 - %.2f" %roc1[-1] )  
    log.info("Roc2 - %.2f" %roc2[-1])  
    log.info("Suma de ROCs - %.2f" %roc[-1])  
    log.info("Coppock - %.2f" %Coppock[-1]) 

    record(Coppock = Coppock[-1])  

Thanks Vladimir, your solution its perfect!!