Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Can anyone see this Simple Programming Error?

Hi All,

I am having trouble implementing my FIRST ever algorithm in Quantopian. Here is where I run into trouble, I am creating a function called day1_close which runs in initialize() as a schedule function 20minutes before the close. This function determines whether or not to buy a security based on the price difference between the OPEN price that day and the current PRICE (20minutes before the close).

def day1_close(context,data):
"""
Execute BUY order according to the schedule_function(day1_close) timing.
"""
# First, get security's OPEN price TODAY.
open_price = data.history(context.security,
fields='open',
bar_count=1,
frequency='1d')

current_price = data.current(context.security, 'price')  

#Now compare the OPEN price today with the CURRENT PRICE * 1.5%.  
if data.can_trade(context.security):  
   if (current_price > (1.015 * open_price)):       #this is line 55.  
        order_target_percent(context.security, 1)

Here is the error I receive:
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all(). There was a runtime error on line 55(.

I can see from the valueError that my boolean:
'if (current_price > (1.015 * open_price))' statement appears to be evaluating incorrectly... Can anyone see the obvious error?

In case you couldn't tell, I am new to programming as well as Quantopian ;)