Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Pipeline with 1 stock and two SimpleMovingAverage

What I'm trying to do actually, but didn't manage to find anything that make sense together is the following:
Have a pipeline for 1 single stock (just so that I can actually debug and understand how everything works) say AAPL

  • have two ExplonentialWeightedMovingAverage averages
  • have a filtering condition exp1 > exp2
  • for each minute, check the condition if True then buy else sell

I keep running into errors and so far, not even that simple example from documentation doesn't help.
Can someone please give me some hints on how to put it all together? Seems that the documentation changed so many times and I just don't get it.

2 responses

Vic,

You do not need pipeline for that task, try this:

import talib  
# ---------------------------------------------------------  
stock, ma_f, ma_s, trade_freq = symbol('AAPL'), 10, 100, 60  
# ---------------------------------------------------------  
def initialize(context):  
    set_benchmark(stock)  
    for i in range(1, 390, trade_freq):  
        schedule_function(trade, date_rules.every_day(),time_rules.market_open(minutes = i)) 

def trade(context, data):  
    if get_open_orders(): return 

    ema_fast = talib.EMA(data.history(stock, 'price', ma_f, '1d'), ma_f)  
    ema_slow = talib.EMA(data.history(stock, 'price', ma_s, '1d'), ma_s)  
    if data.can_trade(stock):  
        if(ema_fast[-1] > ema_slow[-1]):  
            order_target_percent(stock, 1.0)  
        elif (ema_fast[-1] < ema_slow[-1]):  
            order_target(stock, 0)  
    record(leverage = context.account.leverage)  

Thank you Valdimir! That seems so simple.
I always thought the pipelines are the tool for this type of computation. Then when and what shall I use pipelines for ?