The idea
This is PtGambler's open-source strategy, published as "TradePro's 2 EMA + Stoch RSI + ATR Strategy". The script itself is named "2 EMA + Stoch RSI + ATR [Pt]". It splits the setup into a trend filter, a wait-for-extreme step, and a volatility stop. Two exponential averages (defaults 50 and 200) set the side: longs are only considered when the fast average is above the slow one, shorts when it is below. Once the side is right, the script still wants price back on the fast-average side of the pullback, and Stochastic RSI in oversold or overbought, before it arms a trigger zone. The actual order waits for a K/D cross plus a higher low (longs) or lower high (shorts) in K itself.
Both longs and shorts are allowed, but only one position at a time: entries require strategy.position_size == 0. Stops and targets are built from the ATR bands, with a default reward-to-risk of 2, and by default the stop is moved to the entry after price first travels 1R. The author's chart is BITSTAMP:BTCUSD, 15-minute. A backtest window is included; it defaults to 1 January 2011 through 31 December 2050, which is effectively unrestricted.

How the lines are built
- Both exponential averages use close, with default lengths 50 and 200. ema_bull is the fast average above the slow one; ema_bear is the opposite.
- Stochastic RSI is built in the usual way: a 14-period RSI of close, then a 14-period stochastic that uses that RSI for high, low, and close, then a 3-period average for K and a 3-period average of K for D.
- Swing points in K are confirmed with ta.pivothigh(k,1,1) and ta.pivotlow(k,1,1), so a high or low is only confirmed one bar later. recent_low / previous_low are the latest and prior confirmed K lows; the highs work the same way.
- The ATR bands take a moving average of true range (default 14-period EMA) and multiply it by 0.7. The upper band is high plus that value; the lower band is low minus it. Smoothing can be switched to RMA, SMA, or WMA.
- A long stop defaults to the lower ATR band, and the target is the entry reference plus that stop distance times the reward-to-risk multiple (default 2). Shorts use the upper band.
Entry rules
- Both sides are allowed by default, but a new order requires a flat book (strategy.position_size == 0).
- The long trigger zone turns on when the fast average is above the slow one, close is below the fast average, K is below 20, and the strategy is flat. Once armed, the zone stays on until a long is actually entered, the EMA regime turns bearish, or a short is entered. Later bars do not have to keep close under the fast average or K under 20.
- The long fires when the previous bar was already in that zone, K crosses above D on this bar, and the latest confirmed K low is higher than the prior one.
- Shorts are the mirror: the zone arms when the slow average is on top, close is above the fast average, and K is above 80. A short then needs the zone to have been on on the prior bar, K crossing below D, and a lower confirmed high in K.
- Entries are also gated by the backtest window, which defaults to 2011-01-01 through 2050-12-31.
Exits and position size
- Once in a trade, strategy.exit places both a limit target and a stop. A long uses L_PT and L_SL; a short uses S_PT and S_SL.
- While flat, the long stop is pre-computed as the lower ATR band, and the target is close plus the distance from close to that band, times RR (default 2). After a long is opened, L_PT stays at the value from that point and does not keep following the ATR band.
- "Move SL to breakeven when RR hit" is on by default. Next to it is an unlabeled input that defaults to 1.0: how many times the stop distance price must travel in favor before the stop is pulled to the entry price. A long looks at whether high has reached that breakeven trigger; a short looks at low.
- Orders default to 100% of equity, with initial_capital set to 10000. The source does not set commission or slippage, so the tester uses platform defaults.
Inputs (defaults in the source)
| Input | Default | What it does |
|---|---|---|
| Start Year / Month / Day | 2011 / 1 / 1 | Start of the backtest window. |
| Finish Year / Month / Day | 2050 / 12 / 31 | End of the backtest window. |
| EMA Length 1 / EMA Length 2 | 50 / 200 | Periods for the fast and slow exponential averages used as trend and pullback filters. |
| K / D | 3 / 3 | Smoothing length for K in the Stochastic RSI, and the further smoothing that creates D. |
| RSI Length / Stochastic Length | 14 / 14 | Period for the RSI, then for the stochastic of that RSI. |
| Length / Smoothing / Multiplier | 14 / EMA / 0.7 | True-range period, smoothing method, and multiplier for the ATR bands. |
| Source for upper / lower band | high / low | Price the upper band is added to, and the price the lower band is subtracted from. |
| Reward to Risk ratio (X times SL) | 2.0 | Target distance as a multiple of the stop distance. |
| Move SL to breakeven when RR hit | true | Whether the stop is moved to the entry after price reaches the breakeven trigger. |
| (Unlabeled number in Profit Target) | 1.0 | The breakeven trigger, as a multiple of the stop distance. |
Caveats
- The trigger zone is sticky: after it arms, later bars do not have to stay oversold or under the fast average. It keeps waiting for the cross and pivot conditions until the regime flips or a trade is taken.
- The higher-low and lower-high checks on K wait for a one-bar pivot confirmation, so the signal is one bar later than the intra-bar turning point.
- Once a trade is open, the take-profit stays at the level computed at entry and does not trail the later ATR band. Until the breakeven rule fires, the stop also stays at the L_SL / S_SL from that point.
- The breakeven checkbox and the unlabeled 1.0 input use two slightly different inline ids, so they may not appear on the same row in the settings panel. The meaning is still the breakeven multiple described above.
- The default size is a full 100% of equity. The author's chart is 15-minute; the same EMA, Stochastic RSI, and ATR settings will not have the same rhythm on a daily chart or another market.
Install it on TradingView
- Download the .pine file from Coinpred (a current membership is required; see the page) or check the original publication for a newer revision.
- Open the symbol and timeframe you want in TradingView, open the Pine Editor, paste the source, and add it to the chart.
- Start with the default 50 / 200 averages, Stochastic RSI, and 0.7 ATR bands so you can see the trigger zones and orders, then change the lengths, multiplier, and reward-to-risk for your market and timeframe.
- The source sizes orders at 100% of equity and sets initial capital to 10000. Commission and slippage may still be platform defaults. Live order routing has to be set separately.
- Crypto trades around the clock. The tester's timezone and session settings may differ from your venue by several hours.
About backtest figures
Source, license, and version
- Source: https://www.tradingview.com/script/BUsgoYjm-TradePro-s-2-EMA-Stoch-RSI-ATR-Strategy/
- Author: PtGambler (header © PtGambler)
- License: Mozilla Public License 2.0. Redistribution must keep the original copyright and license notices; if you modify the source file, the modified file must remain under MPL 2.0. Coinpred ships the unmodified source.
- Version: 3.0 in the publication record and pine-facade. scriptAccess is open_no_auth.



