Dynamic profit maximizer
Exit flag for a simulated long: trailing stop, momentum or EMA break; silent on SPY at default settings.
DynamicProfitMaximizer models a long position it enters itself: each position starts at the close of the bar after the last exit. It signals an exit on the first of four tests: the close falls to or below a trailing stop that sits trail_distance_pct under the highest close since entry, armed once the gain reaches trailing_threshold; fast momentum drops below momentum_exit_threshold; mid momentum drops below 0.8 times that threshold; or the close drops below fast EMA times ema_cross_multiplier. The atr_pct input only blocks output when it is missing and never changes an exit.
How to read it
- Markers sit on the bar where a simulated long would exit. Nothing else is drawn: no line and no pane.
- The bar after an exit opens a new position at its close, so exits can repeat through the session.
- Every input except price is fed the close here, so only the trailing stop can fire. The sample's whole range, 749.79 to 775.02, is 3.4%, short of the 4% default arm level.
What it outputs
- Exit signal
- Marks each bar where the simulated long exits. No marker on any other bar.
When it fires
Fires on the bar a simulated long would exit: the close reaches its armed trailing stop, fast momentum falls below its level, mid momentum below 0.8 of it, or the close drops below EMA times the multiplier. It never fired on the default SPY sample; read a marker as an exit, not a reversal.
Settings
- trailing_threshold
- Gain from entry needed to arm the trailing stop, as a fraction (0.04 is 4%). Raising it waits for a bigger win, so the stop rarely arms on short moves; lowering it arms sooner. Zero arms at breakeven, and a negative value arms even at a loss.
- trail_distance_pct
- How far below the highest close since entry the stop sits (0.015 is 1.5%). Raising it allows deeper pullbacks; lowering it exits on smaller ones. The stop only moves up. Negative values put it above the peak, so an armed trade exits at once.
- momentum_exit_threshold
- Level the fast momentum input must fall below to exit (default -0.015); the mid input is tested against 0.8 times this level. Raising it toward zero exits sooner on weaker momentum; lowering it waits for a deeper drop.
- ema_cross_multiplier
- Exit when the close drops below fast EMA times this (default 0.98, so 2% under the EMA). Raising it toward 1 exits on smaller dips; above 1 it exits even while price is over the EMA. Negative values switch this test off.
Pitfalls
- At defaults it draws nothing on the SPY sample: the trailing stop needs a 4% gain, and the sample's price range is only 3.4%.
- Momentum and EMA exits only mean something when fed real momentum and EMA series. This explainer feeds price into them, so they stay silent here.
- The trailing stop is checked only while the gain stays at or above trailing_threshold. A price under the stop after the gain has fallen back below that level does not trigger it.