Some logging that might help.
Click a line number in the margin for line{s} of code to set breakpoint(s), run it, then type or copy variable names in the console prompt that appears and hit [Enter] to examine them.
1969-12-31 16:00 get:110 INFO get(self, 2016-12-27 00:00:00+00:00), year 2016
stocks ['MMM', 'AXP', 'BA', 'CAT', 'KO', 'DD', 'XOM', 'GE', 'HD', 'INTC', 'IBM', 'JPM', 'JNJ', 'MCD', 'MRK', 'MSFT', 'PG', 'UTX', 'WMT', 'DIS', 'PFE', 'VZ', 'CVX', 'TRV', 'CSCO', 'UNH', 'GS', 'NKE', 'V', 'AAPL']
2016-12-27 05:45 PRINT .
2016
do_pipe, context.year 2016 == dt.year 2016
do_pipe, len(context.portfolio.positions) 0
2016-12-27 05:45 before_trading_start:162 INFO context.year 2016 to dt.year + 1 = 2017
2016-12-27 07:30 trade:119 INFO trade(), context.year 2017
stocks ['VZ', 'PFE', 'CVX', 'BA', 'CSCO', 'KO', 'IBM', 'XOM', 'CAT', 'MRK']
2017-01-03 05:45 PRINT .
2017
do_pipe, context.year 2017 == dt.year 2017
2017-01-03 05:45 before_trading_start:162 INFO context.year 2017 to dt.year + 1 = 2018
2017-01-03 07:30 trade:119 INFO trade(), context.year 2018
stocks ['VZ', 'PFE', 'CVX', 'BA', 'CSCO', 'KO', 'IBM', 'CAT', 'XOM', 'MRK']
2018-01-02 05:45 PRINT .
2018
do_pipe, context.year 2018 == dt.year 2018
2018-01-02 05:45 before_trading_start:162 INFO context.year 2018 to dt.year + 1 = 2019
2018-01-02 07:30 trade:119 INFO trade(), context.year 2019
stocks ['VZ', 'IBM', 'PFE', 'XOM', 'CVX', 'MRK', 'KO', 'CSCO', 'PG', 'GE']