@@ -0,0 +1,941 @@
+from zipline.api import (%0A    history,%0A    order_target,%0A    record,%0A    symbol,%0A)%0A%0A%0Adef initialize(context):%0A    context.i = 0%0A%0A%0Adef handle_data(context, data):%0A    # Skip first 300 days to get full windows%0A    context.i += 1%0A    if context.i %3C 300:%0A        return%0A%0A    # Compute averages%0A    # history() has to be called with the same params%0A    # from above and returns a pandas dataframe.%0A    short_mavg = history(100, '1d', 'price').mean()%0A    long_mavg = history(300, '1d', 'price').mean()%0A%0A    sym = symbol('AAPL')%0A%0A    # Trading logic%0A    if short_mavg%5Bsym%5D %3E long_mavg%5Bsym%5D:%0A        # order_target orders as many shares as needed to%0A        # achieve the desired number of shares.%0A        order_target(sym, 100)%0A    elif short_mavg%5Bsym%5D %3C long_mavg%5Bsym%5D:%0A        order_target(sym, 0)%0A%0A    # Save values for later inspection%0A    record(AAPL=data%5Bsym%5D.price,%0A           short_mavg=short_mavg%5Bsym%5D,%0A           long_mavg=long_mavg%5Bsym%5D)

add zipline dual moving average example