How should i create a buy low sell high strategy in quantopian.
My idea
Assumption: the stock is trending higher
pre_stock_price= price of the previous stock
new_stock_price= price of the latest stock
stock_price_per= ((new_stock_price - pre_stock_price)/pre_stock_price)
if stock_price_per > 0.1 or stock_price_per < -0.05
sell stock
buy stock at current price
end if
I know this strategy is not a good one but I am using it to my own learning purpose. I have so far written this much code.
def initialize(context):
context.aapl = sid(24)
set_commission(commission.PerShare(cost=0.01))
context.max_notional = 100000.1
context.min_notional = -100000.0
def handle_data( context , data ):
price = data[context.aapl].price
the problem is how i will compare a new apple stock price with an old apple stock price.