You've got the right idea about LastPosition, and even though I'm not familiar with SellAtAutoTrailingStop, that's the right idea too for
backtesting.
However, as discussed in the User Guide: Preferences > Trading > Trading Options,
Allow Same Bar Exits for Auto-Trading, you need to call RiskStopLevel for the Order Manager to work the order after a "live" entry.
So, putting it all together, the entry logic would look something like this -
CODE:
Please log in to see this code.