Yes, you can do what you explained. It's actually the default behavior of the Quantopian backtest engine (ie Zipline). Orders placed in a given bar are filled at the close of that bar**. The bar close price is used by the built-in slippage models to calculate a fill price. One point of confusion however may be what 'current' prices are.
One can never really get prices for the 'current bar' without interjecting lookahead bias. The only data one can know is previous data (ie data from the last bar). One can't even know the open values for the current bar. There is no guarantee when the open order of a bar actually took place (ie the first order for a bar). Consider a bar with an interval [9:32, 9:33) (meaning the half-open interval greater than or equal to time 9:32 and less than time 9:33). The first order during that bar may have executed at 9:32:35 (35 seconds after the beginning of the bar). If one's code ran at the very beginning of the bar then this 'open' order would not have occurred yet. The 'current' prices on Quantopian therefore refer to data which would be known at the current bar which are the previous bars prices and volume.
Let's see how this looks as orders are placed. Consider a simple algo which places an order for a single share of SPY. Then, if a single share is held, then the algo sells that share (back to zero). Repeat buying and selling like this throughout the day. Attached is an algo which does that. Below is the log output.
2011-01-04 08:31 handle_data:20 INFO
2011-01-04 08:31 handle_data:23 INFO previous bar SPY close price: 127.32
2011-01-04 08:31 handle_data:29 INFO No SPY positions. Ordering SPY
2011-01-04 08:32 handle_data:20 INFO
2011-01-04 08:32 handle_data:23 INFO previous bar SPY close price: 127.23
2011-01-04 08:32 handle_data:35 INFO bought SPY at 127.23
2011-01-04 08:32 handle_data:37 INFO selling SPY
2011-01-04 08:33 handle_data:20 INFO
2011-01-04 08:33 handle_data:23 INFO previous bar SPY close price: 127.276
2011-01-04 08:33 handle_data:29 INFO No SPY positions. Ordering SPY
2011-01-04 08:34 handle_data:20 INFO
2011-01-04 08:34 handle_data:23 INFO previous bar SPY close price: 127.22
2011-01-04 08:34 handle_data:35 INFO bought SPY at 127.22
2011-01-04 08:34 handle_data:37 INFO selling SPY
It begins at the bar labeled "2011-01-04 08:31". This is the interval [8:31, 8:32) (these times are US Central). It orders a share of SPY.
The next bar "8:32" shows the previous bar (ie 8:31) close price of 127.23. It also shows that one share of SPY has filled at 127.23. It places an order to sell the share of SPY.
The next bar "8:33" shows no SPY positions. The previous sell order filled at the end of the previous bar.
The next bar "8:34" shows the previous bar (ie 8:33) close price of 127.22. It also shows that one share of SPY has filled at 127.22.
The next bar "8:35" shows no SPY positions. The sequence repeats...
This demonstrates the ordering and filling sequence. For another more detailed explanation of how the Quantopian backtest engine (ie Zipline) models orders take a look at this post. (https://www.quantopian.com/posts/newb-question-on-how-orders-are-modelled).
** One small detail is that, technically, orders are filled at the very beginning of a bar. However, functionally this is identical to filling at the close of the previous bar.
Hope this helps with your code.
Disclaimer
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.