Zeal Terminal Open in Zeal Terminal

Pine Script v5 · Strategy

TradePro's 2 EMA + Stoch RSI + ATR Strategy

A Pine Script v5 strategy built on EMA (close, 50), RSI (src, 14) and SMA or Stoch (3). It has 4 order rules, 2 entries among them, and trades long and short with the default settings. Exits use a stop loss and a profit target. Each trade commits 100% of equity and pays no commission. 23 settings; defaults include Start Year 2011, Start Month 1 and Start Day 1.

Generated from the script's code by a template: every clause is a fact read from the source. Not written by a person or a model, and not taken from the author's description.

Does TradePro's 2 EMA + Stoch RSI + ATR Strategy repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 7 of 7 trades.
How did TradePro's 2 EMA + Stoch RSI + ATR Strategy do on BTCUSDT 1D with default settings?
−2.70%
From 26 Jan 2024 to 21 Oct 2026, over 18 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Does TradePro's 2 EMA + Stoch RSI + ATR Strategy run in Pine Script v6?
No
The v6 version runs in Zeal Terminal's engine, but its results differ from the v5 version: Trades differ: 18 before, 9 after on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. It is shown for reference and is not offered as a download.
Does TradePro's 2 EMA + Stoch RSI + ATR Strategy use a stop loss?
Yes
strategy.exit sets a stop on line 136, 137.
Does TradePro's 2 EMA + Stoch RSI + ATR Strategy run in Zeal Terminal?
Yes
It compiles in 55 ms and runs 1,000 bars in 122 ms, in the browser.

BTCUSDT · 1D · default settings

  • ema1
  • ema2
  • ATR Short Stop Loss
  • ATR Long Stop Loss
  • Entry Price
  • L PT
  • S PT
  • L SL
  • S SL
  • L BE PT
  • S BE PT
  • L Entry Trigger
  • Stoch Cross Up
  • Higher low
  • S Entry Trigger
  • Stoch Cross down
Prerendered with the defaults. Change anything and run it here. The script runs in your browser.
Settings (21)
0.0050,000100,000AprJulOct2025AprJulOct2026AprJulOct$9,730$20,253Equity from $10,000
Binance BTCUSDT 1D candles, 26 Jan 2024 to 21 Oct 2026, 1,000 bars, default settings. Triangles mark entries; circles mark exits. Lines are what the script plots.
Net profit
−2.70%
−$270.11
Buy and hold
+102.5%
same period
Closed trades
18
6 won · 10 lost
Profitable
33.3%
of closed trades
Profit factor
0.94
gross profit ÷ gross loss
Max drawdown
21.97%
−$2,196.73

One run with the author's default settings, $10,000 starting capital, commission as the script sets it. A single backtest says little about future results and is not a recommendation. Backtests are simulations on historical data and are not investment advice.

Review

What a careful reader of this script would point out, found by checking the source and the backtest.

  • Check

    No commission

    The backtest assumes free trading. Results on any real exchange will be lower.

  • Check

    Every trade uses all the equity

    default_qty_value is 100% of equity.

  • Note

    1 setting has no label

    In the settings dialog be_RR (line 74) shows an empty name. The labels on this page come from the variable names.

  • Note

    No slippage

    Fills are assumed at the exact open price. Add slippage in the properties for a more realistic test.

Settings

Every input the script declares, with its default and what it feeds. Bounds are the ones the script enforces.

SettingDefaultType and rangeFeeds
Backtesting window
Start Year2011inttimestart
Start Month1int · min 1 · max 12timestart
Start Day1int · min 1 · max 31timestart
Finish Year2050inttimefinish
Finish Month12int · min 1 · max 12timefinish
Finish Day31int · min 1 · max 31timefinish
EMA
EMA Length 150intema1
EMA Length 2200intema2
Stochastic RSI
K3int · min 1k
D3int · min 1d
RSI Length14int · min 1rsi1
Stochastic Length14int · min 1k
ATR Stoploss Finder
Length14int · min 1a up down line 57 line 60 line 63 line 65
SmoothingEMAstring · options ['RMA', 'SMA', 'EMA', 'WMA']line 56 line 59 line 62
Multiplier0.7float · step 0.1a up down
Source for upper bandhighsourceup
Source for lower bandlowsourcedown
Show ATR BandstrueboolATR Short Stop Loss ATR Long Stop Loss
Long ATR SLcolor.purplecolorATR Long Stop Loss
Short ATR SLcolor.purplecolorATR Short Stop Loss
Profit Target
Reward to Risk ratio (X times SL)2.0float · step 0.1L_PT S_PT
Move SL to breakeven when RR hittrueboolL_SL S_SL
Be RR (no label in the script)1.0floatL_be_PT S_be_PT

What it calculates

  • EMAclose, EMA Length 1 (50)ema1 · line 21
  • EMAclose, EMA Length 2 (200)ema2 · line 22
  • RSIsrc, RSI Length (14)rsi1 · line 33
  • SMA / Stochta.stoch(rsi1, rsi1, rsi1, lengthStoch), K (3)k · line 34
  • SMAk, D (3)d · line 35
  • Crossunderk, dstoch_crossdown · line 38
  • Crossoverk, dstoch_crossup · line 39
  • Pivothighk, 1, 1P_hi · line 40
  • Pivotlowk, 1, 1P_lo · line 41
  • ValuewhenP_hi, k, 1previous_high · line 42
  • ValuewhenP_lo, k, 1previous_low · line 43
  • ValuewhenP_hi, k, 0recent_high · line 44
  • ValuewhenP_lo, k, 0recent_low · line 45
  • TRtruea · line 66
  • TRtrueup · line 67
  • TRtruedown · line 68

Signal flow

How price data and settings reach the orders. Each box is a name in the script, or several computed the same way; each arrow is a value one of them reads. Hover a box for its members.

The script has 80 named inputs, calculations, conditions and outputs, too many to draw legibly here; the tables above list them.

Order rules

OrderFires whenBy defaultLine
Open Long longL_entry1On133
Open Short shortS_entry1On135
Exit Exit Long stop and limitevery barOn136
Exit Exit Short stop and limitevery barOn137

Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.

Does it repaint?

No

No repainting patterns in the source, and the live replay matched history.

7/7trades identical when replayed liveThe last 300 bars, from 26 Dec 2025, were fed to the engine as live ticks, four per bar, and compared with the historical run. Orders are decided once per closed bar, so nothing can change mid-bar.
  • ClearHigher-timeframe dataThe script requests no other symbol or timeframe.
  • ClearFuture-bar referencesNo negative history offsets such as close[-1].
  • ClearIntrabar recalculationNo varip, calc_on_every_tick or realtime-only state. Orders are decided once per closed bar.
  • ClearOrder timingOrders fill at the next bar's open, after the signal bar has closed.

The checks read the source; the replay runs it. Together they catch the common causes, not every possible one.

Other markets

The same script with default settings on 8 Binance markets. Each row is a separate backtest over the most recent 1,000 bars.

MarketNetBuy and holdTradesWonProfit factorMax drawdownPeriod
BTCUSDT 1D−2.7%+102.5%1833%0.9422.0%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+13.6%+5.5%1839%2.284.8%8 May 2026 – 21 Oct 2026
ETHUSDT 1D−38.5%+9.8%1718%0.4340.5%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+3.9%+8.4%1421%1.377.3%8 May 2026 – 21 Oct 2026
SOLUSDT 1D−13.0%+16.7%1926%0.7836.5%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h−10.7%+21.5%1520%0.5913.6%8 May 2026 – 21 Oct 2026
BNBUSDT 1D−32.7%+148.3%2015%0.4334.6%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+3.8%+17.1%2425%1.238.3%8 May 2026 – 21 Oct 2026

Backtests are simulations on historical data and are not investment advice.

Settings heatmap

Two settings that feed the entry signal, moved around their defaults. The best in-sample pair (D 5, Length 12) made +5.0% before 26 Dec 2025 and +1.3% after it, against −0.0% for the defaults. 50% of the 32 combinations made money in-sample and 28% out-of-sample.

Before 26 Dec 2025 · in-sample
Length ↓ · D →2345
7−23%−2%+2%+5%
8−22%−2%+2%+5%
10−22%−2%+2%+5%
12−22%−2%+2%+5%
14−22%−3%+2%+5%
17−22%−3%+1%+5%
20−22%−3%+1%+5%
24−22%−4%+1%+5%
From 26 Dec 2025 · out-of-sample
Length ↓ · D →2345
7−4%−0%−1%+1%
8−4%−0%−1%+1%
10−4%−0%−1%+1%
12−4%−0%−1%+1%
14−4%−0%−1%+2%
17−4%−0%−1%+2%
20−4%−0%−1%+2%
24−2%+2%+2%−3%

Net P&L of trades opened in each period, as a share of starting capital. marks the defaults and the best in-sample cell. Hover a cell for its trade count. Backtests are simulations on historical data and are not investment advice.

The trades

By market direction

At entry, last 90 barsTradesWonP&L
Rising market475%$2,058.26
Sideways market825%−$780.83
Falling market617%−$1,547.54

Rising and falling mean the market moved more than 15% over the 90 bars before entry.

How bad could the drawdown be?

30.7%

The 95th percentile of the worst drawdown when the same 18 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 14.5% to 30.7%; the tick is what actually happened, 21.0%. Order luck alone moves it this much.

0%35%
All 18 trades
SideEntryExitBarsP&L
short6 Sep 2024 56,180.0013 Sep 2024 60,023.707−$684.18
short10 Oct 2024 60,636.0014 Oct 2024 63,856.404−$494.77
long13 Jan 2025 94,545.1013 Jan 2025 91,456.000−$288.21
long20 Feb 2025 96,644.4024 Feb 2025 93,095.404−$313.34
long1 Mar 2025 84,349.904 Mar 2025 84,349.903$0.00
long6 Apr 2025 83,538.006 Apr 2025 80,250.900−$323.43
long18 Apr 2025 84,947.9022 Apr 2025 92,161.804$670.54
long24 Jun 2025 105,334.0014 Jul 2025 121,909.0020$1,348.06
long23 Aug 2025 116,936.0025 Aug 2025 109,412.002−$637.91
long29 Sep 2025 112,164.003 Oct 2025 121,328.004$757.93
long3 Nov 2025 110,541.003 Nov 2025 107,219.000−$301.58
short17 Jan 2026 95,550.9020 Jan 2026 91,525.703$410.02
short27 Mar 2026 68,820.3010 Apr 2026 73,369.7014−$670.51
short13 Apr 2026 70,741.6013 Apr 2026 74,774.000−$539.97
short26 Apr 2026 77,625.0027 Apr 2026 79,373.301−$201.19
short13 May 2026 80,504.5023 May 2026 75,286.2010$565.97
short24 Jul 2026 65,099.007 Aug 2026 65,099.0014$0.00
short7 Sep 2026 80,341.8010 Sep 2026 76,604.903$432.45

Similar scripts

Indicators and strategies built from the same calculations, run on BTCUSDT 1D with their own defaults so they can be compared directly.

ScriptSharesTypeNetTradesMax drawdown
TradePro's 2 EMA + Stoch RSI + ATR Strategy this page—v5 strategy−2.7%1822.0%
X48 - Strategy - MA Type Cross + TPSL - Future&Spot - V.2 by X4815162342ema rsi sma pivothigh pivotlow valuewhenv5 strategydoes not run in Zeal Terminal
RSI Divergence X Ichimoku Cloud X 200EMA by tradethrillsema rsi pivotlow pivothighv4 strategy−196,793.0%71,854.6%
Alert(), alertcondition() or strategy alerts- by Peter_Osma pivothigh pivotlow valuewhenv4 strategy+7,640,000.0%191919.9%
Quantitative Trend Strategy- Uptrend long by CheatCode1sma pivothigh pivotlow valuewhenv5 strategy+5.9%2832.8%
Moving Stop-Loss mechanism + alerts to MT4-MT5 by Peter_Osma pivothigh pivotlow valuewhenv5 strategy−9,857,600.0%1914,436.8%

Upgrade and export

Written in Pine Script v5. The clean-v5 step types the settings and moves when = into if blocks, which v6 requires; it is run before and after like any upgrade.

  • 4 settings use the untyped input() (line 6, 9, 50, 51). It still compiles in v6; input.int, input.float or input.source state the type.
  • No v6-only features. v6 is not needed to run this script.

Clean v5

VerifiedDownload the v5 script

Same 18 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.

  • Line 6: input() → input.int()
  • Line 9: input() → input.int()
  • Line 50: input() → input.source()
  • Line 51: input() → input.source()
⋯// ********************************** Trade Period / Strategy Setting **************************************-startY = input(title='Start Year', defval=2011, group = "Backtesting window")+startY = input.int(title='Start Year', defval=2011, group = "Backtesting window")startM = input.int(title='Start Month', defval=1, minval=1, maxval=12, group = "Backtesting window")startD = input.int(title='Start Day', defval=1, minval=1, maxval=31, group = "Backtesting window")-finishY = input(title='Finish Year', defval=2050, group = "Backtesting window")+finishY = input.int(title='Finish Year', defval=2050, group = "Backtesting window")finishM = input.int(title='Finish Month', defval=12, minval=1, maxval=12, group = "Backtesting window")⋯m = input.float(0.7, 'Multiplier', step = 0.1, group = group_atr)-src1 = input(high, "Source for upper band", group = group_atr)+src1 = input.source(high, "Source for upper band", group = group_atr)-src2 = input(low, "Source for lower band", group = group_atr)+src2 = input.source(low, "Source for lower band", group = group_atr)showatr = input.bool(true, 'Show ATR Bands', group = group_atr)⋯

Does it run in Pine Script v6?

No

The v6 version runs in Zeal Terminal's engine, but its results differ from the v5 version: Trades differ: 18 before, 9 after on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. It is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.

⋯// © PtGambler-//@version=5+//@version=6strategy("2 EMA + Stoch RSI + ATR [Pt]", shorttitle = "2EMA+Stoch+ATR", overlay=true, initial_capital = 10000, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, calc_on_order_fills = false, max_bars_back = 500)⋯

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 55 msYes 1,000 bars in 122 msNot measured
PineTSNot testedNot testedNot measured

“Matches TradingView” needs this script's own output exported from TradingView and compared bar by bar, which has not been done for this script. The engine is built on OpenPineScript, whose conformance results are in its conformance report.

Source

Copied verbatim from the author's published script, with its licence header intact. The author may have updated the original since this snapshot.

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/// © PtGambler//@version=5strategy("2 EMA + Stoch RSI + ATR [Pt]", shorttitle = "2EMA+Stoch+ATR", overlay=true, initial_capital = 10000, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, calc_on_order_fills = false, max_bars_back = 500)// ********************************** Trade Period / Strategy Setting **************************************startY = input(title='Start Year', defval=2011, group = "Backtesting window")startM = input.int(title='Start Month', defval=1, minval=1, maxval=12, group = "Backtesting window")startD = input.int(title='Start Day', defval=1, minval=1, maxval=31, group = "Backtesting window")finishY = input(title='Finish Year', defval=2050, group = "Backtesting window")finishM = input.int(title='Finish Month', defval=12, minval=1, maxval=12, group = "Backtesting window")finishD = input.int(title='Finish Day', defval=31, minval=1, maxval=31, group = "Backtesting window")timestart = timestamp(startY, startM, startD, 00, 00)timefinish = timestamp(finishY, finishM, finishD, 23, 59)// ******************************************************************************************group_ema = "EMA"group_stoch = "Stochastic RSI"group_atr = "ATR Stoploss Finder"// ----------------------------------------- 2 EMA -------------------------------------ema1_len = input.int(50, "EMA Length 1", group = group_ema)ema2_len = input.int(200, "EMA Length 2", group = group_ema)ema1 = ta.ema(close, ema1_len)ema2 = ta.ema(close, ema2_len)plot(ema1, "ema1", color.white, linewidth = 2)plot(ema2, "ema2", color.orange, linewidth = 2)ema_bull = ema1 > ema2ema_bear = ema1 < ema2// -------------------------------------- Stochastic RSI -----------------------------smoothK = input.int(3, "K", minval=1, group = group_stoch)smoothD = input.int(3, "D", minval=1, group = group_stoch)lengthRSI = input.int(14, "RSI Length", minval=1, group = group_stoch)lengthStoch = input.int(14, "Stochastic Length", minval=1, group = group_stoch)src = closersi1 = ta.rsi(src, lengthRSI)k = ta.sma(ta.stoch(rsi1, rsi1, rsi1, lengthStoch), smoothK)d = ta.sma(k, smoothD)var trigger_stoch_OB = k > 80var trigger_stoch_OS = k < 20stoch_crossdown = ta.crossunder(k, d)stoch_crossup = ta.crossover(k, d)P_hi = ta.pivothigh(k,1,1)P_lo = ta.pivotlow(k,1,1)previous_high = ta.valuewhen(P_hi, k, 1)previous_low = ta.valuewhen(P_lo, k, 1)recent_high = ta.valuewhen(P_hi, k, 0)recent_low = ta.valuewhen(P_lo, k, 0)// --------------------------------------- ATR stop loss finder ------------------------length = input.int(title='Length', defval=14, minval=1, group = group_atr)smoothing = input.string(title='Smoothing', defval='EMA', options=['RMA', 'SMA', 'EMA', 'WMA'], group = group_atr)m = input.float(0.7, 'Multiplier', step = 0.1, group = group_atr)src1 = input(high, "Source for upper band", group = group_atr)src2 = input(low, "Source for lower band", group = group_atr)showatr = input.bool(true, 'Show ATR Bands', group = group_atr)collong = input.color(color.purple, 'Long ATR SL', inline='1', group = group_atr)colshort = input.color(color.purple, 'Short ATR SL', inline='2', group = group_atr)ma_function(source, length) =>    if smoothing == 'RMA'        ta.rma(source, length)    else        if smoothing == 'SMA'            ta.sma(source, length)        else            if smoothing == 'EMA'                ta.ema(source, length)            else                ta.wma(source, length)a = ma_function(ta.tr(true), length) * mup = ma_function(ta.tr(true), length) * m + src1down = src2 - ma_function(ta.tr(true), length) * mp1 = plot(showatr ? up : na, title='ATR Short Stop Loss', color=colshort)p2 = plot(showatr ? down : na, title='ATR Long Stop Loss', color=collong)// ******************************* Profit Target / Stop Loss *********************************************RR = input.float(2.0, "Reward to Risk ratio (X times SL)", step = 0.1, group = "Profit Target")breakeven = input.bool(true, "Move SL to breakeven when RR hit", group = "Profit Target", inline = 'breakenven')be_RR = input.float(1.0, "", inline = 'breakeven', group = "Profit Target")var L_PT = 0.0var S_PT = 0.0var L_SL = 0.0var S_SL = 0.0var L_be_PT = 0.0var S_be_PT = 0.0BSLE = ta.barssince(strategy.opentrades.entry_bar_index(0) == bar_index)entry_price = strategy.position_size != 0 ? strategy.opentrades.entry_price(0) : naif strategy.position_size > 0 //and BSLE == 1    L_PT := L_PT[1]    L_SL := (breakeven and high >= L_be_PT) ? entry_price : L_SL[1]    S_PT := close - (up - close)*RR    S_SL := up    L_be_PT := L_be_PT[1]    S_be_PT := close - (up - close)*be_RRelse if strategy.position_size < 0 //and BSLE == 1    S_PT := S_PT[1]    S_SL := (breakeven and low <= S_be_PT) ? entry_price : S_SL[1]    L_PT := close + (close-down)*RR    L_SL := down    S_be_PT := S_be_PT[1]    L_be_PT := close + (close-down)*be_RRelse if strategy.position_size != 0    L_PT := L_PT[1]     S_PT := S_PT[1]else    L_PT := close + (close-down)*RR    L_SL := down    S_PT := close - (up - close)*RR    S_SL := up    L_be_PT := close + (close-down)*be_RR    S_be_PT := close - (up - close)*be_RRentry_line = plot(entry_price, "Entry Price", color.white, linewidth = 1, style = plot.style_linebr)L_PT_line = plot(strategy.position_size > 0 and BSLE > 0 ? L_PT : na, "L PT", color.green, linewidth = 2, style = plot.style_linebr)S_PT_line = plot(strategy.position_size < 0 and BSLE > 0 ? S_PT : na, "S PT", color.green, linewidth = 2, style = plot.style_linebr)L_SL_line = plot(strategy.position_size > 0 and BSLE > 0 ? L_SL : na, "L SL", color.red, linewidth = 2, style = plot.style_linebr)S_SL_line = plot(strategy.position_size < 0 and BSLE > 0 ? S_SL : na, "S SL", color.red, linewidth = 2, style = plot.style_linebr)L_be_PT_line = plot(strategy.position_size > 0 and BSLE > 0 ? L_be_PT : na, "L BE PT", color.blue, linewidth = 2, style = plot.style_linebr)S_be_PT_line = plot(strategy.position_size < 0 and BSLE > 0 ? S_be_PT : na, "S BE PT", color.blue, linewidth = 2, style = plot.style_linebr)fill(L_PT_line, entry_line, color = color.new(color.green,90))fill(S_PT_line, entry_line, color = color.new(color.green,90))fill(L_SL_line, entry_line, color = color.new(color.red,90))fill(S_SL_line, entry_line, color = color.new(color.red,90))// ---------------------------------- strategy setup ------------------------------------------------------var L_entry_trigger1 = falsevar S_entry_trigger1 = falseL_entry_trigger1 := ema_bull and close < ema1 and k < 20 and strategy.position_size == 0S_entry_trigger1 := ema_bear and close > ema1 and k > 80 and strategy.position_size == 0L_entry1 = L_entry_trigger1[1] and stoch_crossup and recent_low > previous_lowS_entry1 = S_entry_trigger1[1] and stoch_crossdown and recent_high < previous_high//debuggingplot(L_entry_trigger1[1]?1:0, "L Entry Trigger")plot(stoch_crossup?1:0, "Stoch Cross Up")plot(recent_low > previous_low?1:0, "Higher low")plot(S_entry_trigger1[1]?1:0, "S Entry Trigger")plot(stoch_crossdown?1:0, "Stoch Cross down")plot(recent_high < previous_high?1:0, "Lower high")if L_entry1    strategy.entry("Long", strategy.long)if S_entry1    strategy.entry("Short", strategy.short)strategy.exit("Exit Long", "Long", limit = L_PT, stop = L_SL, comment_profit = "Exit Long, PT hit", comment_loss = "Exit Long, SL hit")strategy.exit("Exit Short", "Short", limit = S_PT, stop = S_SL, comment_profit = "Exit Short, PT hit", comment_loss = "Exit Short, SL hit")//resetting triggersL_entry_trigger1 := L_entry_trigger1[1] ? L_entry1 or ema_bear or S_entry1 ? false : true : L_entry_trigger1S_entry_trigger1 := S_entry_trigger1[1] ? S_entry1 or ema_bull or L_entry1 ? false : true : S_entry_trigger1//Trigger zonesbgcolor(L_entry_trigger1 ? color.new(color.green ,90) : na)bgcolor(S_entry_trigger1 ? color.new(color.red,90) : na)