Exponential trailing stop
A trailing stop that starts below entry, only moves up, and tightens as the trade gains.
Given a trade's entry price, it draws a stop-loss line that starts initial_stop_pct below entry, 2% by default. Each bar the line may only rise: it is set to a gap below price, and that gap shrinks exponentially as profit grows, halving for every 10% of gain at the default factor. The line resets to a new starting level whenever the entry input changes, and stays flat through pullbacks.
How to read it
- The line sits on the price scale, over the candles, starting about 2% below the entry price.
- It only steps up. Each rise lifts it to a gap below the new price, and pullbacks leave it flat.
- The gap narrows as the trade gains, so a steep rally brings the line close to the candles.
- The indicator draws the level only. Price closing below it is the stop being hit, but nothing is marked.
What it outputs
- Trailing stop
- The stop-loss level for the open trade, in price units. It starts below entry, only moves up as price rises, and resets when the entry input changes.
Settings
- initial_stop_pct
- Starting stop distance below entry, as a fraction (0.02 = 2%). Raising it gives the trade more room and a lower first stop; lowering it puts the stop near entry, so small dips end the trade. It also sets the gap while the trade is at or below entry.
- tightening_factor
- Multiplies the trailing gap for every +10% of profit. At 0.5 the gap halves per 10%; at 1 it never shrinks, so the stop trails at a fixed distance. Lower values tighten faster; above 1 the gap widens as profit grows.
Pitfalls
- The stop only resets when the entry input changes. Wired to a value that moves every bar, it sits about 2% under price: SPY min, median and max all equal 0.98 times the close's.
- Negative values pass the slider range but break the math. A negative tightening_factor gives complex numbers and a TypeError in max() once in profit; a negative initial_stop_pct puts the stop above entry.
- The gap is a fixed fraction of entry, not a volatility measure, so it ignores how fast SPY is moving. The line is a level only; it does not exit a position or size one.