Swing High/Low Profit Target
Profit target at the nearest swing high (long) or swing low (short) of the last N bars. A structural exit reference instead of arbitrary R multiples.
Core idea
Instead of taking a fixed R-multiple (e.g. 2R), the swing profit target anchors on the nearest relevant price structure — the last swing high for long trades or the last swing low for short trades.
The idea: the market "remembers" these levels. Sellers/buyers pulled the trigger there before — these are natural resistance/support zones.
Calculation
Long: target = max(high) of the last N bars (excluding the last 2)
Short: target = min(low) of the last N bars (excluding the last 2)
In Botty (conditions.py):
def get_profit_target(df, latest, side, target_lookback=20):
pre_touch = df.iloc[-2 - target_lookback:-2]
if side == LONG: return float(pre_touch["high"].max())
if side == SHORT: return float(pre_touch["low"].min())
Parameter: target_lookback (default: 20) — how many bars back for the swing.
When it works
- The market still has room to reach the swing level — the target is not too tight.
- The swing level has been touched multiple times → it is better known and attracts price.
- No strong counter-trend pressure between entry and target.
When a trailing stop is better
In strong trends, price often runs past the next swing level. A profit target would cap the gains. In those phases: prefer a trailing stop.
Combination
Botty supports both at the same time: profit_target places a limit order, atr_trailing_stop or swing_stop serves as the loss limit. Whichever triggers first wins.