Back to Community
Possible to set up alerts in quantopian?

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.


1 response

The following example is adapted from 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  

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

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

    # Save values for later inspection