Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Looking for some help

Could someone please explain to me why the algo is only running the first stock (shortone) and not the others (shorttwo, marketone, ), and a possible fix? Appreciate any help!

context.shortone = sid(8089)  
context.shorttwo = sid(28326)  
context.marketone = sid(27437)  
bought_in = False  

if data.can_trade(context.shortone) and bought_in == False and ((current_pricea > 45.00) == True).bool():
order_target_percent(context.shortone, 0.35)
bought_in = True

elif data.can_trade(context.shortone) and bought_in == True and ((current_pricea <= 45.00) == True).bool():
order_target_percent(context.shortone, 0)
bought_in = False

if data.can_trade(context.shorttwo) and bought_in == False and ((current_priceb > 27.00) == True).bool():
order_target_percent(context.shorttwo, 0.20)
bought_in = True

elif data.can_trade(context.shorttwo) and bought_in == True and ((current_priceb <= 27.00) == True).bool():
order_target_percent(context.shorttwo, 0)
bought_in = False

if data.can_trade(context.marketone) and bought_in == False and ((current_pricec > 41.00) == True).bool():
order_target_percent(context.marketone, 0.20)
bought_in = True

elif data.can_trade(context.marketone) and bought_in == True and ((current_pricec <= 41.00) == True).bool():
order_target_percent(context.marketone, 0)
bought_in = False

1 response

i didn't read it very carefully, but i think after placing the first order, you set bought_in to True, and consequent calls will see that bougth_in is True.