Hi there - python beginner here. I am trying to build an algorithm that deploys cash incrementally and I am running into a frustrating error. I want the algorithm to buy in incremental waves of $100k (wave_A,wave_B etc) then once it has purchased using that code not run that code again. I am trying to do this by using an IF statement at the beginning of the code to test if the 'wave' variable is a 1 or a 0, if it is a 0 it will run the code. Make sense? However I am running into a syntax error when I define the variable and I think I might be defining it in the wrong spot.. any help would be appreciated. Thanks!
def initialize(context): context.security = (sid(24)) # Will be called on every trade event for the securities you specify. def handle_data(context, data): # Implement your algorithm logic here. lot_size = context.portfolio.portfolio_value/10 number_of_lots = context.portfolio.cash/lot_size cash = context.portfolio.cash current_price = data[context.security].price number_of_shares = int((lot_size)/current_price) current_price = data[context.security].price bought_price = data[context.portfolio.positions[symbol('aapl')].cost_basis wave_A = 0 if cash >= lot_size and wave_A == 0: print "lot size" print lot_size wave_A = wave_A + 1 order(context.security, +number_of_shares) elif current_price > bought_price*1.05: order_target(context.security, 0) print "selling %" % (context.security.symbol)