Hello,
I've done a lot of back testing through Excel and VBA but just recently decided to give python a shot. I don't really know much about python so my code is based off other forums. Anyways, I get this error when I try to run it in minute mode: "Runtime exception: ValueError: The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all()."
def initialize(context):
context.security = symbol('SPY')
def handle_data(context, data):
H = history(30,'1m','price')
A2 = H.tail(10).mean()
A3 = H.tail(20).mean()
A4 = H.tail(30).mean()
if A2>A3 and A3>A4:
order(context.security, + 1000 )
log.info("Buying %s" % (context.security.symbol))
elif A2<A3 or A3<A4:
order_target(context.security, 0)
log.info("Selling %s" % (context.security.symbol))
record(stock_price=data[context.security].price)
Any feedback is appreciated!