Adaptive trailing stop
Marks where a trailing stop set 1.8 ATR below the highest close since entry gets hit.
This is a trailing stop-out, not a price level. It arms when an entry price appears and starts the stop 1.5% below that price. As closes make new highs, the stop moves up to sit 1.8 ATR(14) below the highest close, and it never moves down. A close at or below the stop is marked with its price and ends the trade. The percent trail and momentum scaling are in the code, but at default settings the ATR trail is the tighter stop on SPY one-minute bars, so they change almost nothing.
How to read it
- Each marker sits on a close where the trailing stop was hit, and its value is that close.
- The stop rises with new closing highs and never falls, so a marker means the move gave back about 1.8 ATR from its best close.
- With no entry signal connected, every close counts as a new entry, so trades restart almost at once. On SPY with defaults that is about 75 markers a day.
What it outputs
- Stop hit
- The close on each bar where the trailing stop is hit, which ends a trade. Nothing is drawn between markers.
When it fires
Fires on a bar whose close is at or below the trail, meaning the close has fallen about 1.8 ATR from the highest close since the trade armed. It marks a pullback big enough to end a trade. Read it as the exit point of a trailing stop, not as a reversal signal.
Settings
- initial_stop_pct
- Distance of the stop below the entry price when a trade arms. At defaults the ATR trail replaces it almost at once, so it barely moves the chart. Negative values put the stop above the price and stop out on the next bar.
- trailing_stop_pct
- Percent trail below the highest close, used only when it is tighter than the ATR trail. At 2.5% it is far wider than the ATR trail, so it rarely decides the stop. Values near 0.1% or below can make it the active stop, depending on ATR.
- atr_multiplier
- How many ATRs the stop trails below the highest close since entry. Raising it widens the trail: fewer stop-outs, longer holds. Lowering it tightens the trail and marks more small pullbacks. At zero every bar fires; negative values stop out at once.
- momentum_window
- Bars of rate of change that scale the percent trail. At defaults the ATR trail wins, so the chart barely changes at any value. It only sets how long the warm-up lasts at the start of a run.
Pitfalls
- With no entry signal connected, the chart treats every close as an entry, so markers are stop-outs of trades that never happened. Read them as stop tests, not real exits.
- The momentum scaling reads backwards: it widens the percent trail on positive momentum and narrows it on negative, the opposite of the docstring. It only matters when the percent trail is the active stop.
- Bug: during the first bars of a run, while ATR or momentum is warming up, the code returns the stop price as if a stop had been hit. Those markers sit at a stop level and do not end a trade.