Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Possible to set up alerts in quantopian?

Hello,
Is it possible to set up a 'condition' and get an alert when a stock meets that condition? If so, can you please point me to the documentation/example.

I've tried to search the documentation / forum and I couldn't find anything.

Thanks!

1 response

The following example is adapted from http://zipline.readthedocs.org/en/latest/quickstart.html#dual-moving-average-example to show logs whenever a condition is met. Is that what you're looking for?

from collections import deque as moving_window  
import numpy as np

def initialize(context):  
    # Add 2 windows, one with a long window, one  
    # with a short window.  
    # Note that this is bound to change soon and will be easier.  
    context.short_window = moving_window(maxlen=100)  
    context.long_window = moving_window(maxlen=300)


def handle_data(context, data):  
    # Save price to window  
    context.short_window.append(data[symbol('AAPL')].price)  
    context.long_window.append(data[symbol('AAPL')].price)

    # Compute averages  
    short_mavg = np.mean(context.short_window)  
    long_mavg = np.mean(context.long_window)

    # Trading logic  
    if short_mavg > long_mavg:  
        log.info('short_mavg {smavg} > long_mavg {lmavg}'.format(smavg=short_mavg, lmavg=long_mavg))  
    elif short_mavg < long_mavg:  
        log.info('short_mavg {smavg} < long_mavg {lmavg}'.format(smavg=short_mavg, lmavg=long_mavg))

    # Save values for later inspection  
    record(AAPL=data[symbol('AAPL')].price,  
           short_mavg=short_mavg,  
           long_mavg=long_mavg)