Use case: I’m using trailing stop orders but on top of that I’d like to also close the position if my strategy emits an exit signal.
It seems like I cannot set the trail to 0, so currently I’m relying on canceling the trail order and then place a market/limit sell order.
Alternatively I can replace the trailing stop order with a trail that will cause it to be immediately converted to a market sell order, but for that I need to know the minimum step allowed. (e.g. I can either update trail percent to 0.0001% or (1 - latestAsk / hwm) * 100. So long as Alpaca doesn’t reject the replace request)
@Poligun In general it’s not a good practice to submit (or replace) either a trailing stop or regular stop order with a value that would make it immediately ‘marketable’. Many execution partners will reject such orders. Alpaca does not explicitly reject these (so paper trading will work fine) but in live trading, when orders are sent to external partners, those partners often have rules to reject those orders. Why? It’s assumed the order is a mistake. A stop order implies one want’s to protect a downside price movement. If one wanted to execute immediately then a market order would have been placed. I couldn’t find a lot on this but here is a post with some more background.
So, you have several options. The first is, as you noted, simply cancel the existing trailing stop order, wait for it to cancel, then submit a market (or limit) order. One approach is to cancel the order, then separately have code which constantly checks for any positions which do not have outstanding open orders and then close those positions. This of course assumes one typically has an open order for all positions, but it’s convenient because it also takes care of ‘edge cases’ which may leave an odd open position.
The second approach is to not use trailing stops but rather use a regular stop in conjunction with a bracket or OCO order (ie have a take profit limit order as the other leg). Then have your algo update the stop price periodically. In essence your algo is implementing it’s own trailing stop. The benefit of this approach is 1) your algo can ‘smooth’ the stop trigger signal. A huge problem with stop orders is they will trigger from a single trade. This often causes orders to trigger too soon. and 2) your position can easily be closed by simply replacing the limit order with a marketable price.
The approach that I personally implement is to not use stop orders at all. Simply have an open take profit limit order (which could be standalone or part of a OTO order pair). Then, have the algo monitor the price. If the price ever drops to your ‘stop price’ then replace the limit price to be a marketable order to close the position.