Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Determine trend using frequency of MA crossovers

The topic of determining trend was recently queried. Here's a simplistic means for finding when trends are in place or when price is choppy. It uses two moving averages, one short and one long, and counts the number of crossing events. If more crossing event have been occurring then the market is likely range bound. If the number of crosses is falling or low, then perhaps price has entered a trending period (thereby reducing the number of times the MAs cross).

The code uses a deque to march along and keep track of the cross events. A simple test to see if the cross count is low enough to enter a trade is then used.

It's a simplistic model but it demonstrates a rather novel way of determining if a trend is in place.

This is a demo only. The technique to guestimate trend is just a curiosity that some may find entertaining.