For practice, I created a new algorithm with only these to line in the handle_data section:
order_target(sid(8554), 1000, style=LimitOrder(limit_price=180))
order_target(sid(8554), -1000, style=LimitOrder(limit_price=190))
My understanding this that this should try to order 1000 shares of SPY if the market is below $180, and try to short 1000 shares if it rises above 190. Furthermore, if the price stays above 190, the position should stay short @ 1000 shares, only changing if it drops below $180.
Well, it does buy 1000 shares to start (from the Transaction Details) as expected with a price well below $180. and it holds those 1000 shares for a while
2011-01-04
- Buys $127,660.00 (1 transactions)
But later it goes crazy.
On May 22, 2015, when the high was only 189.98 (not $190 in the limit order statement) it goes short. Even MORE strangely, it places one order for -1000, but then enters 850 more orders for -2000!
2014-05-22
- Sells $323,755,406.00 (851 transactions)
Then starting on October 12 (a Sunday!) it buys 1699000 shares 28 times! The next few months it continues buying & selling millions of shares (billions of $). Finally in December, 2104, the transactions stop completely. At this point SPY is trading consistently above $200.
What in the world is happening???