New to Python. I'm trying to run the following code but getting the ValueError: The truth value of a Series is ambiguous.
I've done some research and I understand that the error is occurring because of line "if current_price > high_price" and that I can't compare 2 panda series like that.
Could someone please enlighten me on how to correct this error?
Basic idea of the code is to compare the 20 day high/low to the current price. Thanks!
def rebalance(context,data): #Return the 20 day high/low prices and current prices high_price_history = data.history(context.security, 'high' , bar_count=20 , frequency='1d') low_price_history = data.history(context.security, 'low' , bar_count=20 , frequency='1d') current_price = data.current(context.security, 'price') high_price = high_price_history.max() low_price = low_price_history.min() if current_price > high_price: order_target_percent(context.security,1) elif current_price < low_price: order_target_percent(context.security,1)