Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Slope Theory (Moving Average Alignment)

I was bored and created a throw away algorithm last night. I think I'm addicted to this platform. It's just a moving average envelope algorithm engineered to trade low cap stocks on the move. I added in the Vix in as well, to eliminate a few large draw downs. You can tweak the parameters as well. The higher you go the less money you make with price range.

11 responses

Show us more tutorials! :)

Technically, you are correct Vladimir. I changed the name to avoid confusion. Thank you.

Another thing I see glancing back at this is that if you're entering below the VWAP at a percentage threshold, it should be the price you purchased the stock at multiplied by the max loss. Also, if you're already below the discount threshold, there's no reason to buy at a higher price. Technically:

for s in context.security_listF:  
       if s not in context.portfolio.positions and data.can_trade(s) and s not in get_open_orders():  
             cp = data.current(s,'price')  
             if cp < (vwap(data,context,s) * VWAP_DISC):  
                 # price at current price if less than vwap entry point  
                 tc(lp,[s,context.pctx, cp,False],[s.symbol + ' => Market Long','Error'])  
                 context.trail[s] =  cp * MAX_LOSS  
                 tc(so,[s,0,context.trail[s],False],['Stop Price set','Error'])  
             else:  
                 tc(lp,[s,context.pctx, vwap(data,context,s) * VWAP_DISC ,False],[s.symbol + ' => Market Long','Error'])  
                 context.trail[s] =  vwap(data,context,s) * VWAP_DISC * MAX_LOSS  
                 tc(so,[s,0,context.trail[s],False],['Stop Price set','Error'])  

This increases the percentage gain, as you're obviously avoiding situations where you're buying higher at a lower price, which is probably a good idea if you're going long. #duhhh

Thank you so much for sharing! I watched the video and it was a lot of help. How did you learn to code like this and could this strategy be applied to more specific stocks?

it don't work at all, never places any trades

Posted algo is broken. Please update it.

Can remove all instances of the optional argument IBExchange.SMART to fix.

Thanks for explaining how to fix it.

Anyone got a current working version of this algo? Thx.