Swing trading bot (strategy, code and multi-day holds)
Swing trading sits in the sweet spot between day trading and investing: hold for a few days to a few weeks to capture one meaningful price “swing,” then step aside. It's arguably the most bot-friendly style — slow enough that latency and fees barely matter, fast enough to compound. A swing bot scans for setups, enters on confirmation, and manages the trade across days while you sleep. This guide covers the setups, the daily-bar code, the overnight risks, and how to backtest it honestly.
What swing trading is
A swing trader aims to capture one leg of a larger move — the pullback-and-resume in a trend, or the bounce within a range — holding from a couple of days to a couple of weeks. Compared with scalping or day trading, the timeframe is forgiving: a few cents of slippage on a multi-percent target is noise, so a swing bot doesn't need co-located servers or millisecond execution.
Common swing setups
- Trend pullback — buy a dip to a moving average or Fibonacci level within an uptrend, exit on a swing high.
- Breakout-and-go — enter on a daily close above a multi-week high, ride for several days.
- Reversion bounce — buy an oversold daily RSI in a range, exit near the mean.
The code
python · swing.py# daily bars: buy a pullback to the 20-day EMA within an uptrend
def swing_signal(closes, ema20, ema50):
uptrend = ema20[-1] > ema50[-1]
pulled_back = closes[-1] <= ema20[-1]*1.01
turning_up = closes[-1] > closes[-2]
if uptrend and pulled_back and turning_up:
return 'buy'
return 'hold'
Why swing trading suits a bot
On daily or 4-hour bars, the bot only needs to wake up once per bar, evaluate a handful of rules, place an order, and sleep. There's no microsecond race, so you can run it on a cheap VPS. The bot's real value is consistency and patience: it takes every valid setup and skips the invalid ones, immune to the FOMO and revenge-trading that wreck discretionary swing traders.
Overnight and gap risk
Unlike a day-trading bot that's flat by the close, a swing bot carries positions overnight and over weekends, exposed to gaps from earnings, headlines, or crypto's 24/7 lurches. A stop can't protect you against a gap through it. Size for the worst-case gap, not the average day, and avoid holding into known event dates.
Sizing and risk
Set stops at a logical level (below the swing low / pullback origin), size from that distance with the position calculator, and assume your real risk is a bit larger than the stop because of gaps. Backtest on daily bars with realistic fees and slippage in the backtester, and judge the bot on whether it survives the gappy weeks, not just the smooth ones.
Frequently asked questions
What is a swing trading bot?
A swing trading bot holds positions for a few days to a few weeks to capture one meaningful price swing, then exits. It usually runs on daily or 4-hour bars, scanning for setups and managing trades automatically, and is one of the most automation-friendly trading styles.
Is swing trading good for automation?
Yes. On daily or 4-hour timeframes there is no millisecond race, so a swing bot runs fine on a cheap VPS, and a few cents of slippage is negligible against multi-percent targets. The bot's edge is patience and consistency — taking every valid setup without emotion.
What is the main risk of a swing trading bot?
Overnight and weekend gap risk. Because a swing bot holds through the close, a position can gap past its stop on news or earnings, producing a larger loss than planned. You should size for the worst-case gap and avoid holding into known event dates.
How is swing trading different from day trading?
Day trading closes all positions by the session's end to avoid overnight risk and trades fast intraday moves; swing trading holds for days to weeks to capture larger swings. Swing trading is slower, less latency-sensitive and generally easier to automate reliably.