Accelerating trailing stop
Flags a close through a trailing stop that, with default settings, gets wider as the trade gains.
While a trade is open, the indicator tracks the highest close since entry, starting from the entry price itself, and sets a stop initial_stop below that high (default 3%). On each new closing high the stop distance is recomputed as initial_stop x (1 + profit x acceleration_factor), with profit measured from entry at that close. The output is True on each candle whose close is at or below the stop, and it reports nothing outside a trade.
How to read it
- Markers appear only while a trade is open, that is while the entry_price input is set. With no entry, nothing is drawn.
- A marker means the close fell to or below the trailing stop, which sits below the highest close since entry (or below entry itself until a close goes higher).
- Markers repeat on each candle that stays under the stop, so the first marker of a run is the stop-out. The indicator never closes the trade; the strategy has to act on the marker.
- On the default SPY month it marked 6 candles in 2 runs, so markers are rare at default settings.
What it outputs
- Stop hit
- True on candles where the close is at or below the trailing stop while a trade is open. Stays True over each run of such candles. Nothing is reported with no open trade.
When it fires
Fires on each candle whose close is at or below the trailing stop during a trade, meaning price gave back the stop distance from its best close since entry. The first marker of a run is the stop-out; later ones repeat the same breach. On the sample SPY month: 6 candles in 2 runs.
Settings
- initial_stop
- Stop distance below the best close since entry, as a fraction (default 0.03, or 3%). Raising it leaves more room, so fewer markers. Lowering it tightens the stop, so more markers. Zero or negative values mark every candle of a trade.
- acceleration_factor
- Sets how the stop distance moves with profit at each new high: initial_stop x (1 + profit x factor). Default 2 widens the stop as the trade gains. Negative values tighten it, reaching zero at profit of 1 / |factor|; beyond that every candle marks.
Pitfalls
- The name suggests a tightening stop, but the default factor of 2 widens the stop as profit grows. Tightening needs a negative factor, and that has a cliff at profit of 1 / |factor|.
- The reference starts at the entry price and only moves on new closing highs, so until a close goes above entry the stop sits initial_stop below entry.
- It tests closes only, so an intrabar dip through the stop is not marked until a candle closes under it.