Your First Strategies
Complete walkthroughs: RSI strategy, breakout strategy, and pinbar strategy: each with entry logic, exits, and risk management.
RSI Mean Reversion Strategy
The RSI (Relative Strength Index) strategy is the classic starting point for strategy development. The logic is simple: when RSI drops below 30, the asset is oversold and likely to bounce. When RSI rises above 70, it is overbought and likely to pull back. On BTC daily charts, RSI below 30 has historically marked significant buying opportunities during bear market capitulations. On shorter timeframes like the 4H, it generates more frequent but noisier signals.
1//@version=52strategy("RSI Mean Reversion", overlay=true,3 initial_capital=10000,4 default_qty_type=strategy.percent_of_equity,5 default_qty_value=95,6 commission_type=strategy.commission.percent,7 commission_value=0.075,8 slippage=2)910// === INPUTS ===11rsiLen = input.int(14, "RSI Length", minval=2)12oversold = input.int(30, "Oversold Level", minval=5, maxval=50)13overbought = input.int(70, "Overbought Level", minval=50, maxval=95)14useEmaFilt = input.bool(true, "Use EMA Trend Filter")15emaLen = input.int(200, "EMA Filter Length", minval=10)1617// === CALCULATIONS ===18rsi = ta.rsi(close, rsiLen)19ema200 = ta.ema(close, emaLen)2021// === ENTRY CONDITIONS ===22// Buy when RSI crosses below oversold AND price is above 200 EMA (uptrend filter)23longCondition = ta.crossunder(rsi, oversold) and (useEmaFilt ? close > ema200 : true)2425// Sell when RSI crosses above overbought26exitCondition = ta.crossover(rsi, overbought)2728// === EXECUTION ===29if longCondition30 strategy.entry("RSI Long", strategy.long)3132if exitCondition33 strategy.close("RSI Long", comment="RSI overbought")3435// === RISK MANAGEMENT ===36// 5% stop loss as safety net37strategy.exit("SL", "RSI Long",38 loss = close * 0.05 / syminfo.mintick)3940// === VISUALS ===41plot(ema200, "EMA 200", color.yellow, 2)42bgcolor(longCondition ? color.new(color.green, 90) : na)43bgcolor(exitCondition ? color.new(color.red, 90) : na)Calculate the RSI
ta.rsi(close, 14) computes the 14-period RSI. This measures the ratio of average gains to average losses over the lookback period, producing a value between 0 and 100. Lower values mean more selling pressure relative to buying.Add the trend filter
Define entry and exit
ta.crossunder(rsi, 30) fires once when RSI moves from above 30 to below 30. The exit fires when RSI crosses above 70. This gives clear, non-ambiguous signals.Add a stop loss
strategy.exit() protects against the times when oversold becomes more oversold. Without this, a single crash could wipe out months of gains.N-Bar Breakout Strategy
Breakout strategies capture moves when price pushes through a significant level. The N-bar high breakout buys when price exceeds the highest high of the last N bars. This works well on trending assets like BTC and SOL during strong momentum phases. Adding a volume filter confirms that the breakout has institutional participation rather than being a low-volume wick.
1//@version=52strategy("N-Bar 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)78// === INPUTS ===9lookback = input.int(20, "Breakout Lookback", minval=5)10volMult = input.float(1.5, "Volume Multiplier", minval=1.0, step=0.1)11atrMult = input.float(2.0, "ATR Stop Multiplier", minval=0.5, step=0.5)12atrLen = input.int(14, "ATR Length")1314// === CALCULATIONS ===15highestHigh = ta.highest(high, lookback)16lowestLow = ta.lowest(low, lookback)17avgVolume = ta.sma(volume, lookback)18atr = ta.atr(atrLen)1920// === CONDITIONS ===21breakoutUp = close > highestHigh[1] and volume > avgVolume * volMult22breakoutDown = close < lowestLow[1] and volume > avgVolume * volMult2324// === EXECUTION ===25if breakoutUp26 strategy.entry("Breakout Long", strategy.long)27 strategy.exit("ATR Stop", "Breakout Long",28 stop = close - atr * atrMult)2930if breakoutDown31 strategy.close("Breakout Long", comment="Breakdown exit")3233// === VISUALS ===34plot(highestHigh[1], "Resistance", color.new(color.green, 40), 1, plot.style_stepline)35plot(lowestLow[1], "Support", color.new(color.red, 40), 1, plot.style_stepline)Volume confirmation matters
Pin Bar Reversal Strategy
Pin bars (pinocchio bars) are single-candle reversal patterns characterized by a long wick and a small body. A bullish pin bar has a long lower wick (buyers rejected lower prices) and closes near the high. A bearish pin bar has a long upper wick (sellers rejected higher prices) and closes near the low. On ETH and BTC, pin bars at key support/resistance levels are among the highest-probability single-candle setups.
1//@version=52strategy("Pin Bar Reversal", 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 ===9wickRatio = input.float(2.5, "Wick-to-Body Ratio", minval=1.5, step=0.5)10atrMult = input.float(1.5, "ATR Stop Multiplier", step=0.5)11tpMult = input.float(2.0, "ATR Take-Profit Multiplier", step=0.5)12useEmaTrend = input.bool(true, "Require Trend Alignment")13emaLen = input.int(50, "EMA Length")1415// === CALCULATIONS ===16body = math.abs(close - open)17upperWick = high - math.max(close, open)18lowerWick = math.min(close, open) - low19atr = ta.atr(14)20ema = ta.ema(close, emaLen)2122// === PIN BAR DETECTION ===23bullPin = lowerWick > body * wickRatio and24 upperWick < body and25 body > 0 and26 (useEmaTrend ? close > ema : true)2728bearPin = upperWick > body * wickRatio and29 lowerWick < body and30 body > 0 and31 (useEmaTrend ? close < ema : true)3233// === EXECUTION ===34if bullPin35 stopPrice = low - atr * atrMult36 tpPrice = close + atr * tpMult37 strategy.entry("Pin Long", strategy.long)38 strategy.exit("Pin TP/SL", "Pin Long",39 limit = tpPrice,40 stop = stopPrice)4142if bearPin43 strategy.close("Pin Long", comment="Bear pin exit")4445// === VISUALS ===46plotshape(bullPin, "Bull Pin", shape.triangleup,47 location.belowbar, color.green, size=size.small)48plotshape(bearPin, "Bear Pin", shape.triangledown,49 location.abovebar, color.red, size=size.small)50plot(ema, "EMA", color.yellow, 1)Calculate body and wicks
math.abs(close - open). The lower wick is math.min(close, open) - low. For a valid bullish pin bar, the lower wick must be at least 2.5x the body size. This ensures genuine rejection.Filter with trend
Set ATR-based risk
Put this lesson to work
Free on Thrive, no account needed.