Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
What is wrong with this code?

Obviously trying to learn. Simple buy when high of yesterday > high of today

def initialize(context):  
    context.aapl = sid(24)  
    open_px=data[context.stock].open_price  
    close_px=data[context.stock].close_price  
    hi=data[context.stock].high  
    lo=data[context.stock].low  
    price_history = history(bar_count=3, frequency='1d', field='price')  
    for s in data:  
    if hi.ix[-1] > hi.ix[-2]:  
    orders(s,1)  
1 response

This is under initialize. Initialize is run only once at the start of the program. You need to create a separate function that is scheduled every day using the schedule function. OR you can use handle data if you are using daily data.

How are you planning to purchase today if you need sufficient data to find the high of today? For instance, it won't be until 4PM that you know what the daily maximum is. By then you can't buy it anymore. You would probably need to buy a few minutes before close in order to do that. The code can become quite convoluted in order to do this.

Also, by the looks of your code, there is a chance you could be using lookahead data?