Supertrend Strategy: ATR Trend-Following You Can Automate
Master the Supertrend indicator with ATR settings, Pine Script strategy code, and AI agent automation that filters whipsaws 24/7.

Most traders discover Supertrend by accident — they slap it on a trending chart, watch it nail every major move, and immediately start live trading it. Then they hit a consolidating week and get chopped apart by six false signals in a row. The indicator didn't fail. They used a trend-following tool in a non-trending market.
Supertrend is one of the cleanest directional filters available. When price is moving, it stays out of your way and keeps you on the right side. The problem is that it has no opinion on whether price should be moving, which is exactly where a reasoning layer — whether that's your own judgment or an AI agent — earns its keep.
What you'll learn:
- How Supertrend calculates its line and why the ATR period and factor control everything
- How to set entries, exits, and reversals around the flip signal
- A complete Pine Script v6 strategy with an ATR trailing stop you can copy and run today
- Which ATR/factor combinations suit scalping versus swing trading
- How to filter false flips with an EMA trend check and higher-timeframe confirmation
- How to configure an AI agent that runs this logic 24/7 without babysitting it
How Supertrend Actually Works
Supertrend is not a standalone oscillator. It is a channel-based trend filter built on top of Average True Range. The calculation is straightforward: take a midpoint (typically hl2, the average of high and low), add and subtract a multiple of ATR from it, and then apply a ratchet rule that prevents the line from moving against the current trend direction.
The two parameters are:
- ATR Period: the lookback for the ATR calculation, default 10
- Factor: the multiplier applied to ATR before adding/subtracting from the midpoint, default 3.0
When price closes above the upper band, Supertrend flips bullish and plots below price in green. When price closes below the lower band, it flips bearish and plots above price in red. The flip is the signal. There is no ambiguity about what the indicator is saying — it is either long or short, nothing in between.
The ratchet rule is what makes it useful. Once the line flips bullish, it can only move up, never down. This means it acts as a trailing stop that tightens as the trend matures, locking in more of the move with each new bar.
ATR Period and Factor: The Real Settings Debate
Traders spend a lot of time arguing about whether to use 7, 10, or 14 for the ATR period and whether 2.0, 3.0, or 4.0 is the "right" factor. The honest answer is that both parameters control the same tradeoff: responsiveness versus whipsaw resistance.
A lower factor (e.g., 1.5–2.0) puts the line closer to price. You get earlier entries and earlier exits, but you also get stopped out of valid trends on normal retracements. A higher factor (e.g., 4.0–5.0) keeps the line far from price, filtering noise but giving back significant profit before the signal fires.
The ATR period works similarly. A shorter period (7–8) makes ATR more reactive to recent volatility, so the bands compress and expand faster. A longer period (14–21) smooths ATR and makes the bands more stable.
| Configuration | ATR Period | Factor | Best For | Typical False Signal Rate |
|---|---|---|---|---|
| Scalper | 7 | 1.5 | 5-min / 15-min crypto | High — needs additional filter |
| Default | 10 | 3.0 | 1H / 4H most assets | Moderate |
| Swing | 14 | 3.5 | Daily forex / equities | Low |
| Position | 21 | 4.5 | Weekly crypto / commodities | Very low, late entries |
| Volatile crypto | 10 | 4.0 | 1H BTC/ETH during high-vol | Moderate-low |
The default (10, 3.0) is a reasonable starting point on the 1-hour and 4-hour charts. For daily charts on forex pairs, (14, 3.5) tends to reduce the noise from overnight gaps. For 15-minute crypto, you almost always need a secondary filter regardless of the factor setting.
Pine Script v6 Strategy: Entry, Exit, and ATR Trailing Stop
Here is a complete, copy-pasteable Pine Script v6 strategy. It enters long on a bullish Supertrend flip, enters short on a bearish flip, and manages each trade with an ATR-based trailing stop that ratchets in the direction of the trade. The strategy reverses position on the opposite flip rather than just exiting flat.
//@version=6
strategy("Supertrend ATR Strategy", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=10)
// ── Inputs ──────────────────────────────────────────────────────────────
atrPeriod = input.int(10, "ATR Period", minval=1)
factor = input.float(3.0, "Factor", minval=0.5, step=0.5)
atrStopMult = input.float(1.5, "ATR Stop Multiplier", minval=0.5, step=0.25)
// ── Supertrend Calculation ───────────────────────────────────────────────
[supertrend, direction] = ta.supertrend(factor, atrPeriod)
// ── ATR for trailing stop ────────────────────────────────────────────────
atr = ta.atr(atrPeriod)
// ── Signal Detection ─────────────────────────────────────────────────────
bullFlip = direction == -1 and direction[1] == 1 // flipped bullish this bar
bearFlip = direction == 1 and direction[1] == -1 // flipped bearish this bar
// ── Entry Logic ──────────────────────────────────────────────────────────
if bullFlip
strategy.entry("Long", strategy.long)
if bearFlip
strategy.entry("Short", strategy.short)
// ── ATR Trailing Stop ────────────────────────────────────────────────────
longStop = strategy.position_avg_price - atrStopMult * atr
shortStop = strategy.position_avg_price + atrStopMult * atr
if strategy.position_size > 0
strategy.exit("Long Exit", "Long", stop=longStop)
if strategy.position_size < 0
strategy.exit("Short Exit", "Short", stop=shortStop)
// ── Visuals ───────────────────────────────────────────────────────────────
plot(supertrend, color=direction == -1 ? color.green : color.red, linewidth=2, title="Supertrend")
plotshape(bullFlip, style=shape.triangleup, location=location.belowbar, color=color.green, size=size.small, title="Bull Flip")
plotshape(bearFlip, style=shape.triangledown, location=location.abovebar, color=color.red, size=size.small, title="Bear Flip")
A few notes on the implementation:
ta.supertrend()returns both the line value and the direction integer (−1 = bullish, +1 = bearish). Comparingdirectiontodirection[1]catches the exact bar of the flip.- The ATR trailing stop uses
strategy.position_avg_priceas the anchor, not the entry bar's high/low. This makes it less sensitive to the exact entry price and more consistent across different market conditions. atrStopMult = 1.5gives the trade room to breathe on the 1-hour chart. On the 15-minute chart, 1.0–1.25 is often sufficient. On the daily chart, go to 2.0.- The strategy reverses automatically because a new
strategy.entryin the opposite direction closes the existing position before opening the new one.
Filtering Whipsaws: EMA and Higher-Timeframe Confirmation
Raw Supertrend on any timeframe below 4H will generate whipsaws during ranging periods. The fix is not to keep tweaking the factor — it is to add a filter that tells the strategy whether the market is actually trending.
The two most practical filters are:
1. EMA slope filter. Calculate a 200-period EMA. Only take long flips when price is above the 200 EMA, and only take short flips when price is below it. This single rule eliminates the majority of counter-trend chop entries.
2. Higher-timeframe Supertrend. Run a second Supertrend on a timeframe that is 4–5x your trading timeframe. If you trade the 1-hour chart, check the 4-hour Supertrend direction. Only take signals that align with the higher-timeframe trend.
// Add this to the strategy above to enable HTF filtering
htfDirection = request.security(syminfo.tickerid, "240", ta.supertrend(factor, atrPeriod)[1], lookahead=barmerge.lookahead_off)
// Only trade in the direction of the 4H Supertrend
if bullFlip and htfDirection < 0
strategy.entry("Long", strategy.long)
if bearFlip and htfDirection > 0
strategy.entry("Short", strategy.short)
The [1] offset on request.security prevents lookahead bias — you are reading the completed 4-hour bar's direction, not the current one still forming. This is a critical detail. Backtests without this offset will show inflated results because they are reading future data.
If you are already familiar with how the MACD crossover strategy handles multi-timeframe confirmation, the logic here is identical in principle: the higher timeframe sets the directional bias, the lower timeframe provides the entry timing. You can read more about that layered approach in the MACD Crossover Strategy guide.
Position Sizing with ATR Scaling
Fixed percentage position sizing works, but it ignores the fact that a 10% equity trade in a low-volatility environment is a very different risk than a 10% trade when ATR is spiking. ATR-scaled sizing normalizes your risk per trade regardless of current market conditions.
The formula is:
Position Size = (Account Equity × Risk %) / (ATR Stop Distance in price)
For example: $50,000 account, risk 1% per trade ($500), ATR stop distance = 200 pips (0.0200 on EUR/USD). Position size = $500 / 0.0200 = 25,000 units (0.25 standard lots).
In Pine Script, you can implement this by passing a dynamic qty to strategy.entry calculated from the current ATR value. This keeps your dollar risk per trade constant regardless of whether you are trading a quiet Tuesday on EUR/USD or a volatile BTC breakout.
// ATR-scaled position sizing (add to the strategy)
riskPct = input.float(1.0, "Risk Per Trade %", minval=0.1, step=0.1) / 100
stopDist = atrStopMult * atr
riskAmount = strategy.equity * riskPct
qty = riskAmount / (stopDist * syminfo.pointvalue)
if bullFlip
strategy.entry("Long", strategy.long, qty=qty)
if bearFlip
strategy.entry("Short", strategy.short, qty=qty)
This approach pairs naturally with the RSI Divergence Strategy if you want to add a confirmation layer that reduces position size when RSI is showing divergence against the Supertrend signal.
Common Mistakes That Kill Supertrend Performance
Using it in ranging markets without a filter. This is the single biggest mistake. Supertrend is a trend-following tool. In a 200-pip EUR/USD range, it will flip back and forth generating losses on every signal. The 200 EMA filter or HTF check described above is not optional — it is the difference between a positive expectancy system and a loss machine.
Over-optimizing the factor. Running a parameter sweep and finding that factor=2.7 had the best backtest return on the last 12 months of BTC data tells you almost nothing useful. Factor settings that are curve-fit to historical data degrade fast when volatility regimes shift. Stick to round numbers (2.0, 2.5, 3.0, 3.5, 4.0) and test across multiple assets and time periods.
Ignoring the ATR trailing stop and holding until the flip. Supertrend's built-in trailing behavior is useful, but it can give back 30–40% of a move before flipping. Adding a tighter ATR stop (1.5x ATR from entry) captures more of the trend on shorter timeframes where moves are less sustained.
Treating every flip as equal. A flip that occurs after a 15-bar consolidation is a very different signal from a flip that occurs three bars after the previous flip. Requiring a minimum number of bars since the last flip (e.g., barssince(bullFlip) > 5) reduces the frequency of chop reversals.
Applying it to illiquid assets. Supertrend on a thinly traded altcoin or a micro-cap stock will generate signals based on ATR that is inflated by bid-ask spread noise, not actual price movement. Stick to assets with sufficient volume that ATR reflects real volatility.
Advanced Configuration: Multi-Timeframe Supertrend and Regime Detection
The most effective Supertrend setups in 2026 use three timeframes simultaneously: a fast timeframe for entry timing, a medium timeframe for directional bias, and a slow timeframe for regime classification.
Here is how to think about the three layers:
- Slow timeframe (daily or weekly): Is the market in a trending regime at all? If the daily Supertrend has been in the same direction for 20+ bars, you are in a trending regime. If it has flipped more than 4 times in 20 bars, you are ranging — stand aside.
- Medium timeframe (4H or daily): What is the current directional bias? Long or short?
- Fast timeframe (1H or 15M): Where is the exact entry? Wait for the flip on this timeframe that aligns with layers 1 and 2.
For ATR period selection across timeframes, a consistent approach is to use a period that captures approximately the same number of calendar days of volatility. On the 1-hour chart, ATR(10) covers roughly 10 hours. On the 4-hour chart, ATR(10) covers 40 hours (about 1.5 trading days). On the daily chart, ATR(10) covers 10 trading days (2 calendar weeks). This consistency makes the factor setting more comparable across timeframes.
One non-obvious parameter choice: on cryptocurrency markets that trade 24/7, reduce the ATR period by 20–30% compared to what you would use on traditional markets. Crypto's continuous session means 10 bars of ATR on the 4-hour chart represents 40 real hours of price action, but traditional market ATR periods were designed for 6.5-hour trading days. A period of 7–8 on the 4H crypto chart is roughly equivalent to 10 on a 4H forex chart in terms of calendar time covered.
Running This 24/7 with an AI Agent
The Supertrend strategy has a structural problem for manual traders: the best setups often occur during off-hours. A BTC breakout at 3 AM, a EUR/USD trend day that starts at the London open while you are asleep — these are the moves Supertrend is designed to catch, and they are exactly the ones you miss.
This is where Agentic Traders adds a layer that a Pine Script alert cannot. Instead of firing a notification and waiting for you to act, you describe the full strategy logic in plain English and the agent reasons through it and executes autonomously. For example, you might configure an agent like this:
"Watch the 1-hour BTC/USDT chart. When the Supertrend (10, 3.0) flips bullish AND the 4-hour Supertrend is also bullish AND price is above the 200 EMA, enter a 2% long position. Set an ATR trailing stop at 1.5x the current ATR. If the 1-hour Supertrend flips bearish, close the long and evaluate whether to enter short based on whether the 4-hour Supertrend has also flipped. Run this check on ETH/USDT and SOL/USDT simultaneously."
The agent does not just mechanically execute those conditions. It reasons about them: if the 4-hour Supertrend just flipped bearish two bars ago and the 1-hour is now also flipping, it weights that alignment more heavily. If ATR is spiking to 3x its 20-period average (a potential news event), it can reduce position size or wait for the first bar to close before entering. That kind of contextual reasoning is what separates an AI agent from a rules-based bot — a distinction worth understanding if you are comparing approaches to AI crypto trading.
FAQ
What is the best Supertrend setting for the 1-hour chart? For most liquid assets on the 1-hour chart, (10, 3.0) is the standard starting point. If you are trading high-volatility crypto pairs like BTC or ETH, move the factor to 3.5 or 4.0 to reduce whipsaws during consolidation. Always pair it with a 200 EMA filter — the raw signal on the 1-hour chart alone has too many false flips during ranging periods.
Can Supertrend be used for scalping on the 5-minute chart? Yes, but it requires aggressive filtering. On the 5-minute chart, use (7, 2.0) for responsiveness, but require that both the 15-minute and 30-minute Supertrends are in the same direction before taking any trade. Without multi-timeframe alignment, the 5-minute signal is essentially noise in all but the strongest trending conditions.
How does Supertrend differ from a moving average crossover? A moving average crossover (like the EMA 9/21 cross) generates signals based on two lagging averages. Supertrend generates signals based on price's relationship to a volatility-adjusted band. This makes Supertrend more adaptive to current market volatility — the band widens during high-ATR periods and narrows during low-ATR periods, whereas moving average crossovers are blind to volatility. In practice, Supertrend tends to have fewer signals but each signal represents a more significant price move relative to current conditions.
Should I use Supertrend as my only exit signal? Not on timeframes below 4H. The flip signal can give back 20–40% of a move on shorter timeframes before it fires. Use the ATR trailing stop described in the code above as your primary exit, and treat the opposite Supertrend flip as a reversal signal rather than just an exit. On daily and weekly charts, the flip itself is a reasonable exit because the moves are large enough that the give-back is acceptable.
Does Supertrend work on stocks and forex, or just crypto? It works across all asset classes. The parameter adjustment to make is the factor: forex pairs tend to trend smoothly and can tolerate a lower factor (2.5–3.0), while individual stocks have gap risk and benefit from a higher factor (3.5–4.5) to avoid being stopped out by overnight gaps. Commodities sit in between. The core logic — ATR-based band with a ratchet rule — is asset-agnostic.
What to Test Next
Supertrend is one of the most backtestable indicators in existence because its signal is binary and unambiguous. That makes it a good foundation for systematic strategy development.
The natural next step is combining it with a momentum filter. Supertrend tells you the direction; an RSI or MACD reading at the time of the flip tells you whether there is momentum supporting that direction. A bullish Supertrend flip where RSI is at 35 (recovering from oversold) is a very different trade from a flip where RSI is already at 65 (extended). Adding that filter does not add complexity for its own sake — it adds information that improves signal quality.
If you are running this on multiple assets simultaneously (which is where the 24/7 automation angle becomes essential), also consider how you will handle correlated positions. Three simultaneous long signals on BTC, ETH, and SOL during a crypto bull run are not three independent trades — they are one directional bet spread across three assets. ATR-scaled sizing helps, but you should also cap your total directional exposure across correlated assets. The MACD Crossover Strategy article covers a similar portfolio-level consideration for trend-following systems running on multiple instruments.
The Supertrend strategy is not a magic system. It is a clean, testable, automatable framework for staying on the right side of trends. Set it up properly, filter the ranging periods, size positions to your actual risk tolerance, and let the trend do the work.
Related Articles
- MACD Crossover Strategy: Signals, Backtest & AI Automation
- RSI Divergence Strategy: Spot Reversals and Automate With AI
- Artificial Intelligence Crypto Trading: 2026 Guide to AI Agents
- Stochastic Oscillator Strategy: %K/%D Crosses Done Right
Try this Supertrend strategy with an AI agent that runs it 24/7, filters whipsaws in real time, and executes across crypto, forex, and commodities at Agentic Traders.
Stochastic Oscillator Strategy: %K/%D Crosses Done Right
Master stochastic oscillator strategy with 80/20 levels, %K/%D crossovers, Pine Script code, and an AI agent that confirms structure before entry.
StrategiesMACD Crossover Strategy: Signals, Backtest & AI Automation
Master MACD crossovers with exact 12/26/9 parameters, a Pine Script v6 backtest, and an AI agent that filters noise with trend confluence.
IndicatorsRSI Divergence Strategy: Spot Reversals and Automate With AI
Master regular and hidden RSI divergence with exact parameters, a Pine Script detector, and an AI agent that confirms reversals before trading.
StrategiesBroken Wing Butterfly Options: Setup, Risk & Profit Mechanics
Master the broken wing butterfly options strategy with real Greeks, strike selection formulas, and Python code for asymmetric risk-reward setups in 2026.
Run this strategy with an AI Trader.
Tell the AI your strategy. It picks the indicators, reasons through every setup, and trades for you 24/7. Free to start. No code.
Build your AI Trader — free