Here's a framework that accomplishes your 'Template 2'. I made a few assumptions like not holding more than one position of a stock at a time and 'price' is the last close price, etc. It's pretty well commented so you can add and change things in their approriate areas.
As Umar pointed out, there are a lot of algorithm designs in the forums here. Everyone has their own style and approach. The main reason I like (and use) this approach is that the actual trading rules are encapsulated in a single place (a string) and not spread out around the code. Changing the rules doesn't entail changing a lot of code. The buy rules are defined on line 163 and the sell rules on line 179. Any of the algorithm 'constants' can be changed in the initialize section.
First thing to note. You wanted to trade a fixed $20k per stock. Generally this isn't a good approach. One needs to manually watch the account leverage and moreover, the backtest returns and beta will be highly dependent upon starting balance. Sizing positions based upon a percent of the portfolio size fixes this and makes for a more scalable algorithm. The framework allows for both. Just set 'context.use_fixed_positions' to False and then set 'context.max_positions' to your target number of positions (20 seems to be a good number for this particular strategy).
Also note, this is a good framework to easily backtest ideas. It doesn't however handle all exceptions and ordering issues that could arise in live trading.
Let me know if this is along the lines of what you were looking for.
Dan