Hey everyone, I am working on developing an algorithm to purchase shares of a stock if it falls 1% or so from the opening price. However, when coding, I am not really sure how to define this. I want to create a variable called "open_price" so that I can then define a variable "buy_price" as "open_price * 0.99", however I am not sure how to format that using data history when coding... Any help? My code so far is included below:
current_price = data.current('SPY', "price")
open_price = data.history(context.security, "open", 1, "1d")
current_positions = context.portfolio.positions[symbol('SPY')].amount
cash = context.portfolio.cash
buy_enter = (open_price * 0.99)
if (current_price <=buy_enter) and current_positions == 0:
number_of_shares = int(cash/current_price)
order(context.security, number_of_shares)