Intermediate Strategy Patterns
Pullback strategy, channel breakout strategy, follow-the-bear strategy, and Bollinger Band strategy: complete implementations.
EMA Pullback Strategy
Pullback strategies are the bread and butter of trend-following. Rather than chasing breakouts, you wait for price to retrace to a key level within an established trend, then enter in the direction of the trend. The logic: in an uptrend (price above 50 EMA, 50 EMA above 200 EMA), wait for price to pull back to the 21 EMA, then buy when it bounces. On BTC and ETH during trending phases, pullbacks to the 21 EMA on the 4H chart are consistently tradeable.
1//@version=52strategy("EMA Pullback", overlay=true,3 initial_capital=10000,4 default_qty_type=strategy.percent_of_equity,5 default_qty_value=95,6 commission_value=0.075, slippage=2)78// === INPUTS ===9emaFast = input.int(21, "Pullback EMA")10emaMed = input.int(50, "Trend EMA")11emaSlow = input.int(200, "Major Trend EMA")12atrMult = input.float(1.5, "ATR Stop Multiplier")13tpMult = input.float(3.0, "ATR Take-Profit Multiplier")1415// === CALCULATIONS ===16fast = ta.ema(close, emaFast)17med = ta.ema(close, emaMed)18slow = ta.ema(close, emaSlow)19atr = ta.atr(14)2021// === TREND DEFINITION ===22upTrend = med > slow and close > slow23downTrend = med < slow and close < slow2425// === PULLBACK DETECTION ===26// Price touched or crossed below the fast EMA, then bounced back above27pulledBack = low <= fast and close > fast28bullPullback = upTrend and pulledBack and close > open2930// === EXECUTION ===31if bullPullback32 strategy.entry("PB Long", strategy.long)33 strategy.exit("PB TP/SL", "PB Long",34 limit = close + atr * tpMult,35 stop = close - atr * atrMult)3637// Trend reversal exit38if ta.crossunder(med, slow)39 strategy.close_all(comment="Trend reversal")4041// === VISUALS ===42plot(fast, "21 EMA", color.new(color.blue, 0), 1)43plot(med, "50 EMA", color.new(color.orange, 0), 2)44plot(slow, "200 EMA", color.new(color.white, 30), 2)45bgcolor(bullPullback ? color.new(color.green, 90) : na)Why pullbacks outperform breakouts in crypto
Donchian Channel Breakout Strategy
The Donchian Channel plots the highest high and lowest low over N periods. The classic "Turtle Traders" strategy enters long when price breaks above the 20-day high and exits when price breaks below the 10-day low. Adding a trailing exit instead of a fixed channel exit significantly improves performance on trending assets like BTC.
1//@version=52strategy("Donchian Breakout", overlay=true,3 initial_capital=10000,4 default_qty_type=strategy.percent_of_equity,5 default_qty_value=95,6 commission_value=0.075, slippage=2)78entryLen = input.int(20, "Entry Channel Length", minval=5)9exitLen = input.int(10, "Exit Channel Length", minval=3)10atrLen = input.int(14, "ATR Length")11atrMult = input.float(3.0, "ATR Trailing Multiplier")1213// === CHANNELS ===14entryHigh = ta.highest(high, entryLen)[1] // Previous bar's channel15entryLow = ta.lowest(low, entryLen)[1]16exitLow = ta.lowest(low, exitLen)[1]17exitHigh = ta.highest(high, exitLen)[1]18atr = ta.atr(atrLen)1920// === ENTRIES ===21if close > entryHigh22 strategy.entry("DC Long", strategy.long)2324if close < entryLow25 strategy.entry("DC Short", strategy.short)2627// === EXITS ===28// Channel exit for longs: close below exit channel low29if strategy.position_size > 0 and close < exitLow30 strategy.close("DC Long", comment="Channel exit")3132// Channel exit for shorts: close above exit channel high33if strategy.position_size < 0 and close > exitHigh34 strategy.close("DC Short", comment="Channel exit")3536// ATR trailing stop as additional protection37if strategy.position_size > 038 strategy.exit("Trail Long", "DC Long",39 trail_points=atr*atrMult/syminfo.mintick,40 trail_offset=atr*1.5/syminfo.mintick)4142// === VISUALS ===43upperBand = plot(entryHigh, "Entry High", color.new(color.green, 40))44lowerBand = plot(entryLow, "Entry Low", color.new(color.red, 40))45fill(upperBand, lowerBand, color=color.new(color.blue, 95))Follow-the-Bear: Counter-Trend Exhaustion
The Follow-the-Bear strategy fades extreme moves after exhaustion signals. The idea: when price has moved too far too fast (measured by distance from a moving average and RSI extremes), a snap-back is likely. This is a mean-reversion approach that works well during choppy, range-bound periods, which describe crypto markets roughly 70% of the time.
1//@version=52strategy("Follow the Bear", overlay=true,3 initial_capital=10000,4 default_qty_type=strategy.percent_of_equity,5 default_qty_value=90,6 commission_value=0.075, slippage=2)78emaLen = input.int(21, "EMA Length")9rsiLen = input.int(7, "RSI Length")10distPct = input.float(5.0, "Distance from EMA (%)", step=0.5)11rsiExOB = input.int(80, "RSI Exhaustion OB")12rsiExOS = input.int(20, "RSI Exhaustion OS")13atrMult = input.float(1.5, "ATR Stop Mult")1415ema = ta.ema(close, emaLen)16rsi = ta.rsi(close, rsiLen)17atr = ta.atr(14)18distPctCalc = (close - ema) / ema * 1001920// Bearish exhaustion: price far above EMA + RSI overbought21bearExhaustion = distPctCalc > distPct and rsi > rsiExOB and22 close < open // Bearish candle confirms reversal starting2324// Bullish exhaustion: price far below EMA + RSI oversold25bullExhaustion = distPctCalc < -distPct and rsi < rsiExOS and26 close > open // Bullish candle confirms reversal starting2728if bullExhaustion29 strategy.entry("Fade Short", strategy.long)30 strategy.exit("Fade SL", "Fade Short",31 limit = ema,32 stop = close - atr * atrMult)3334if bearExhaustion35 strategy.close("Fade Short", comment="Bear exhaustion")3637// Time-based exit: close after 10 bars if target not hit38if strategy.position_size > 0 and bar_index - strategy.opentrades.entry_bar_index(0) > 1039 strategy.close_all(comment="Time exit")Bollinger Band Squeeze-to-Expansion Strategy
Bollinger Bands measure volatility using standard deviations around a moving average. When the bands squeeze tight (low bandwidth), volatility is compressing: an expansion is coming. The strategy enters when bandwidth expands after a squeeze, in the direction of the breakout. On BTC, Bollinger squeezes on the daily chart precede the biggest moves of the year. The bandwidth filter ensures you only trade after genuine compression, not random noise.
1//@version=52strategy("BB Squeeze Expansion", overlay=true,3 initial_capital=10000,4 default_qty_type=strategy.percent_of_equity,5 default_qty_value=95,6 commission_value=0.075, slippage=2)78bbLen = input.int(20, "BB Length")9bbMult = input.float(2.0, "BB Multiplier")10squeezeLen = input.int(120, "Squeeze Lookback")11squeezePctl = input.float(10, "Squeeze Percentile (%)")12atrMult = input.float(2.0, "ATR Stop Mult")1314// === BOLLINGER BANDS ===15basis = ta.sma(close, bbLen)16dev = ta.stdev(close, bbLen) * bbMult17upper = basis + dev18lower = basis - dev19bandwidth = (upper - lower) / basis * 1002021// === SQUEEZE DETECTION ===22// Bandwidth is in the bottom percentile of its lookback range23bwMin = ta.lowest(bandwidth, squeezeLen)24bwMax = ta.highest(bandwidth, squeezeLen)25bwPctl = (bandwidth - bwMin) / (bwMax - bwMin) * 10026isSqueeze = bwPctl < squeezePctl2728// Expansion: bandwidth was in squeeze, now expanding29wasSqueeze = ta.barssince(isSqueeze) < 530expanding = bandwidth > bandwidth[1] and bandwidth[1] > bandwidth[2]3132atr = ta.atr(14)3334// === ENTRIES ===35if wasSqueeze and expanding and close > upper36 strategy.entry("BB Long", strategy.long)37 strategy.exit("BB SL", "BB Long", stop=basis)3839if wasSqueeze and expanding and close < lower40 strategy.entry("BB Short", strategy.short)41 strategy.exit("BB SL S", "BB Short", stop=basis)4243// Exit when price returns to basis44if strategy.position_size > 0 and close < basis45 strategy.close("BB Long", comment="Back to mean")46if strategy.position_size < 0 and close > basis47 strategy.close("BB Short", comment="Back to mean")4849// === VISUALS ===50plot(upper, "Upper BB", color.new(color.blue, 40))51plot(basis, "Basis", color.new(color.gray, 40))52plot(lower, "Lower BB", color.new(color.blue, 40))53bgcolor(isSqueeze ? color.new(color.yellow, 90) : na)Crypto-specific Bollinger considerations
Put this lesson to work
Free on Thrive, no account needed.