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

Hello, I need help. I am overwhelmed to progame the Dema and WMA. Both are indicators.
Does someone is able to convert this indicators into python code?
Thanks to everybody, who wants to help

6 responses

@ Joshua,
You can use talib to get Dema and WMA.

thanks

I started coding and unfortunately there is an error and I dont know how to solve it.

Dema and WMA

import talib

------------------------------------------

STOCK = symbol('SPY'); MA = 100; BARS = MA*6;

------------------------------------------

def initialize(context):
schedule_function(record_MA, date_rules.every_day(), time_rules.market_close(), True)

def record_MA(context, data):
prices = data.history(STOCK, 'price', BARS, '1d')
dema = talib.DEMA(prices, MA )
wma = talib.WMA(prices, MA )

record(price = prices[-1], dema = dema[-1], wma = wma[-1])  

open_orders = get_open_orders()  

if dema > wma:  
    if STOCK not in open_orders:  
        order_target_percent(STOCK, 1.0)

elif dema < wma:  
    if STOCK not in open_orders:  
        order_target_percent(STOCK, -1.0)  


record(levarage = context.account.leverage)  

@ Joshua,

Try this:

    if dema[-1] > wma[-1]:  
    elif dema[-1] < wma[-1]:  

Thanks a lot. To be honest its my first program here. So I progrmmed before with Python, but I guess I have a long way to go.