Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Algorithm not selling stocks at target price

Hi everybody, I am having a bit of trouble with this algorithm. It's a simple buy low and sell high algorithm for a simple market ETF that I am testing out before I try on some fancier algorithms.

This algorithm seemed to just run 3-4 transactions and stopped.
In the code, I had the profit_ratio set to 1.05.
The final purchase was on 2012-05-21 for 160 shares of VTI at $66.71.
When the price of VTI later exceeded 70.0455, a sell order was not executed.
Would anybody be able to explain to me if there is anything in this code that is preventing it from selling again?
Furthermore, is this code checking the price of the stock at every minute? If not, is there a way to make it do so?

Thanks!

2 responses

Some other things to think about and tracking of orders

2017-11-01 06:31 track_orders:87 INFO track_orders active. Headers ...  
2017-11-01 06:31 track_orders:88 INFO              Shares     Shares  
2017-11-01 06:31 track_orders:89 INFO Min   Action Order  Sym  Now   at Price   PnL   Stop or Limit   Cash  Id  
2017-11-09 06:40 trade:39 INFO  buy VTI at prc 132.42  pct_in_range 0 < buy_pct_trigger 25  
2017-11-09 06:40 trade:39 INFO  buy SPY at prc 257.94  pct_in_range 5 < buy_pct_trigger 25  
2017-11-09 06:40 _trac:105 INFO   10   Buy 19 SPY _ at 257.94                                10000  dd12  
2017-11-09 06:40 _trac:105 INFO   10   Buy 37 VTI _ at 132.42                                10000  a28f  
2017-11-09 06:41 _trac:105 INFO   11      Bot 37 VTI (37) at 132.37                          198  a28f  
2017-11-09 06:41 _trac:105 INFO   11      Bot 19 SPY (19) at 257.83                          198  dd12  
2017-12-04 06:40 trade:28 INFO sell VTI at prc 137.266 > cb 132.437185 * profit_ratio 1.035 = 137.072486475  
2017-12-04 06:40 _trac:105 INFO   10   Sell -37 VTI (37) at 137.27                           198  1514  
2017-12-04 06:41 _trac:105 INFO   11      Sold -37 VTI _ at 137.26                           5274  1514  
2017-12-06 06:40 trade:39 INFO  buy VTI at prc 135.288  pct_in_range 6 < buy_pct_trigger 25  
2017-12-06 06:40 _trac:105 INFO   10   Buy 37 VTI _ at 135.29                                5274  917d  
2017-12-06 06:41 _trac:105 INFO   11      Bot 37 VTI (37) at 135.29                          266  917d  
2017-12-13 06:40 trade:28 INFO sell SPY at prc 267.33 > cb 257.9589145 * profit_ratio 1.035 = 266.987476508  
2017-12-13 06:40 _trac:105 INFO   10   Sell -19 SPY (19) at 267.33                           266  16bb  
2017-12-13 06:41 _trac:105 INFO   11      Sold -19 SPY _ at 267.36                           5343  16bb  
2017-12-22 06:40 trade:39 INFO  buy SPY at prc 267.35  pct_in_range 9 < buy_pct_trigger 25  
2017-12-22 06:40 _trac:105 INFO   10   Buy 19 SPY _ at 267.35                                5343  4dc2  
2017-12-22 06:41 _trac:105 INFO   11      Bot 19 SPY (19) at 267.36                          261  4dc2  
2018-01-08 06:40 trade:28 INFO sell VTI at prc 140.15 > cb 135.358645 * profit_ratio 1.035 = 140.096197575  
2018-01-08 06:40 _trac:105 INFO   10   Sell -37 VTI (37) at 140.15                           286  9e8f  
2018-01-08 06:41 _trac:105 INFO   11      Sold -37 VTI _ at 140.24                           5472  9e8f  
2018-01-16 06:40 trade:28 INFO sell SPY at prc 279.725 > cb 267.49468 * profit_ratio 1.035 = 276.8569938  
2018-01-16 06:40 _trac:105 INFO   10   Sell -19 SPY (19) at 279.73                           5472  124a  
2018-01-16 06:41 _trac:105 INFO   11      Sold -19 SPY _ at 279.74                           10784  124a  
2018-01-30 06:40 trade:39 INFO  buy VTI at prc 144.97  pct_in_range 0 < buy_pct_trigger 25  
2018-01-30 06:40 trade:39 INFO  buy SPY at prc 282.94  pct_in_range 0 < buy_pct_trigger 25  
2018-01-30 06:40 _trac:105 INFO   10   Buy 19 SPY _ at 282.94                                10784  8fbc  
2018-01-30 06:40 _trac:105 INFO   10   Buy 37 VTI _ at 144.97                                10784  235d  
2018-01-30 06:41 _trac:105 INFO   11      Bot 19 SPY (19) at 282.70                          48  8fbc  
2018-01-30 06:41 _trac:105 INFO   11      Bot 37 VTI (37) at 144.86                          48  235d  
2018-08-28 06:40 trade:28 INFO sell VTI at prc 150.12 > cb 144.93343 * profit_ratio 1.035 = 150.00610005  
2018-08-28 06:40 _trac:105 INFO   10   Sell -37 VTI (37) at 150.12                           136  f76e  
2018-08-28 06:41 _trac:105 INFO   11      Sold -37 VTI _ at 150.10                           5686  f76e  

Thanks! That's a pretty good interesting code to track orders. I included that in my code but it still doesn't seem to be selling after 2012-05-21. Would you know how to fix that?