Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Simple and good Idea (Just learning Phyton )

Hi, i have the idea about the strategy, it is simple but works well on real life, but i had hard time to make it on the script.
please give me advice on daily chart for specific stock.
1. Buy when Exponential Moving Averages ( EMA ) short and long ( 10,100 ) crossed.
2. Relative Strength Index (RSI) using value 14, and buy if the RSI under 30.

Thanks

1 response

Hello,

I just joined myself. I've played around with python in the past so I'll give this a try.

def initialize(context):  
    context.goog = sid(26578) #Google  
    context.max_notional = 1000000.1  #upper trade limit  
    context.min_notional = -1000000.0 #lower trade limit

def handle_data(context, data):  
    #Calculate EMAs  
    lead = data[context.goog].mavg(10)  
    lag = data[context.goog].mavg(100)  
    #Price of google over time  
    price = data[context.goog].price  
    #Calculate Position  
    notional = context.portfolio.positions[context.goog].amount * price  
    #Go long when lead>lag and short when lead<lag  
    if lead < lag and notional > context.min_notional:  
        order(context.goog,-100) #short 100 shares  
    elif lead > lag and notional < context.max_notional:  
        order(context.goog,+100) #long 100 shares  
    #Plot Price and EMAs  
    record(Close = price, Lead = lead, Lag = lag)  

Let me know when you get the RSI going.

-Marc