Loading page…
Loading page…
Production-grade Pine v5/v6 strategy templates with transparent Strategy Tester fees, drawdowns, ATR stops, and webhook alert hooks.
Enters pullbacks to EMA 50 only when EMA 50 > EMA 200 and ADX(14) > 20, with 2× ATR stop and 3.5× ATR target.
| Scenario | Net Profit | Profit Factor | Max Drawdown | Win Rate | Trades | Observed Behavior |
|---|---|---|---|---|---|---|
| Baseline (EMA 50/200 + ADX > 20 + ATR 2x/3.5x) | +52.4% | 1.48 | 18.6% | 44.1% | 118 | Includes realistic Binance taker fees + slippage. |
| Without ADX Filter (raw EMA pullback) | +19.1% | 1.13 | 29.4% | 38.2% | 214 | Whipsawed repeatedly during summer range-bound chop. |
1//@version=62strategy(3 "EMA 50/200 Pullback + ADX Filter (v6)",4 overlay = true,5 initial_capital = 10000,6 default_qty_type = strategy.percent_of_equity,7 default_qty_value = 100,8 commission_type = strategy.commission.percent,9 commission_value = 0.05,10 slippage = 211)12 13i_start = input.time(timestamp("2024-01-01T00:00:00Z"), "Backtest Start")14i_adxMin = input.float(20.0, "Min ADX(14)", step = 1.0)15i_slAtr = input.float(2.0, "Stop Loss (ATR)", step = 0.1)16i_tpAtr = input.float(3.5, "Take Profit (ATR)", step = 0.1)17 18emaFast = ta.ema(close, 50)19emaSlow = ta.ema(close, 200)20atrVal = ta.atr(14)21[_, _, adxVal] = ta.dmi(14, 14)22 23inWindow = time >= i_start24longSignal = inWindow and emaFast > emaSlow and adxVal > i_adxMin and ta.crossover(close, emaFast)25 26if longSignal and strategy.position_size == 027 string payload = '{"action":"buy","symbol":"' + syminfo.ticker + '","price":' + str.tostring(close) + '}'28 strategy.entry("Long", strategy.long, alert_message = payload)29 30if strategy.position_size > 031 float sl = strategy.position_avg_price - atrVal * i_slAtr32 float tp = strategy.position_avg_price + atrVal * i_tpAtr33 strategy.exit("ExitLong", from_entry = "Long", stop = sl, limit = tp)34 35plot(emaFast, "EMA 50", color = color.new(#2962ff, 0))36plot(emaSlow, "EMA 200", color = color.new(#ff9800, 0))Buys oversold dips (RSI < 30) only above the 200-bar SMA while normalized ATR is below panic threshold.
| Scenario | Net Profit | Profit Factor | Max Drawdown | Win Rate | Trades | Observed Behavior |
|---|---|---|---|---|---|---|
| RSI(14) < 30 + Close > SMA(200) + ATR% < 3.5% | +61.8% | 1.92 | 11.4% | 68.5% | 73 | Avoided 2022 bear-market falling knives via SMA 200 guard. |
| Unfiltered RSI(14) < 30 | +24.3% | 1.21 | 33.8% | 57.1% | 126 | Severe drawdown during sustained macro selloffs. |
1//@version=62strategy(3 "RSI Mean Reversion + SMA200 Guard (v6)",4 overlay = true,5 initial_capital = 25000,6 default_qty_type = strategy.percent_of_equity,7 default_qty_value = 100,8 commission_type = strategy.commission.cash_per_order,9 commission_value = 1.0,10 slippage = 211)12 13i_rsiBuy = input.int(30, "RSI Oversold Entry", minval = 5, maxval = 45)14i_rsiExit = input.int(62, "RSI Exit Level", minval = 50, maxval = 90)15i_maxAtrPc = input.float(3.5, "Max ATR % of Price", step = 0.2)16 17rsiVal = ta.rsi(close, 14)18sma200 = ta.sma(close, 200)19atrPct = (ta.atr(14) / close) * 100.020 21longCond = close > sma200 and rsiVal < i_rsiBuy and atrPct < i_maxAtrPc22exitCond = rsiVal > i_rsiExit23 24if longCond and strategy.position_size == 025 string payload = '{"action":"buy","symbol":"' + syminfo.ticker + '","rsi":' + str.tostring(rsiVal, "#.##") + '}'26 strategy.entry("MR_Long", strategy.long, alert_message = payload)27 28if strategy.position_size > 029 if exitCond30 strategy.close("MR_Long", alert_message = '{"action":"close","symbol":"' + syminfo.ticker + '"}')31 strategy.exit("MR_Stop", from_entry = "MR_Long", stop = strategy.position_avg_price * 0.94)32 33plot(sma200, "SMA 200", color = color.new(#26a69a, 0))Classic 20-bar channel breakout using previous-bar [1] highs/lows (zero lookahead) with 10-bar exit channel and 2× ATR hard stop.
| Scenario | Net Profit | Profit Factor | Max Drawdown | Win Rate | Trades | Observed Behavior |
|---|---|---|---|---|---|---|
| Donchian 20/10 + 2× ATR Hard Stop | +34.3% | 1.41 | 16.4% | 39.4% | 284 | Right-tail winners pay for frequent small breakout stops. |
1//@version=62strategy(3 "Donchian 20/10 Turtle Breakout (v6)",4 overlay = true,5 initial_capital = 50000,6 default_qty_type = strategy.fixed,7 default_qty_value = 1,8 commission_type = strategy.commission.cash_per_contract,9 commission_value = 2.25,10 slippage = 111)12 13i_entryLen = input.int(20, "Entry Channel Length", minval = 5)14i_exitLen = input.int(10, "Exit Channel Length", minval = 3)15i_atrStop = input.float(2.0, "Hard Stop (ATR)", step = 0.1)16 17upperEntry = ta.highest(high, i_entryLen)[1]18lowerExit = ta.lowest(low, i_exitLen)[1]19atrVal = ta.atr(14)20 21if close > upperEntry and strategy.position_size == 022 strategy.entry("TurtleLong", strategy.long, alert_message = '{"action":"buy","strategy":"donchian20"}')23 24if strategy.position_size > 025 float hardStop = math.max(lowerExit, strategy.position_avg_price - atrVal * i_atrStop)26 strategy.exit("TurtleExit", from_entry = "TurtleLong", stop = hardStop)27 28plot(upperEntry, "Donchian High 20", color = color.new(#26a69a, 0))29plot(lowerExit, "Donchian Low 10", color = color.new(#ef5350, 0))Filters false breakouts by requiring bar volume ≥ 1.8× SMA(20) volume and closes out before session end.
| Scenario | Net Profit | Profit Factor | Max Drawdown | Win Rate | Trades | Observed Behavior |
|---|---|---|---|---|---|---|
| 30-Bar High + Volume > 1.8× SMA(20) | +38.7% | 1.34 | 22.1% | 43.8% | 162 | Volume filter cut trade count by 48% vs raw breakout. |
1//@version=62strategy(3 "Volume-Confirmed Breakout (v6)",4 overlay = true,5 initial_capital = 10000,6 default_qty_type = strategy.percent_of_equity,7 default_qty_value = 100,8 commission_type = strategy.commission.percent,9 commission_value = 0.05,10 slippage = 211)12 13i_lookback = input.int(30, "Range Lookback", minval = 10)14i_volMult = input.float(1.8, "Min Volume Multiple", step = 0.1)15i_slAtr = input.float(1.8, "Stop Loss (ATR)", step = 0.1)16i_tpAtr = input.float(3.2, "Take Profit (ATR)", step = 0.1)17 18rangeHigh = ta.highest(high, i_lookback)[1]19volAvg = ta.sma(volume, 20)20atrVal = ta.atr(14)21 22breakout = close > rangeHigh and volume >= volAvg * i_volMult23 24if breakout and strategy.position_size == 025 strategy.entry("VolBreak", strategy.long, alert_message = '{"action":"buy","strategy":"vol_breakout"}')26 27if strategy.position_size > 028 strategy.exit(29 "VolExit",30 from_entry = "VolBreak",31 stop = strategy.position_avg_price - atrVal * i_slAtr,32 limit = strategy.position_avg_price + atrVal * i_tpAtr33 )34 35plot(rangeHigh, "Range High", color = color.new(#2962ff, 0))