Answering another forum question earlier today, I found we don't have a clean example for this use case.
To use this example in your code, you need a way to define your tradeable universe. I used get_fundamentals to define what I was trading.
Note that this doesn't guarantee the order will fill. On some days, the positions aren't closed because there wasn't enough trading volume!