NEWCard payments are live · from $18/month, USDT also acceptedSee plans
COINPRED / STRATEGY LIBRARY

BTC EMA and Stoch RSI: In a 50-above-200 trend, go long after an oversold pullback when K crosses D with a higher low; ATR stop, 2R target, stop can move to entry at 1R

PtGambler's open-source trend script (MPL 2.0), "2 EMA + Stoch RSI + ATR [Pt]" (page: "TradePro's 2 EMA + Stoch RSI + ATR Strategy"). Both sides on by default. A long arms when the 50 EMA is above the 200, close is under the fast EMA, and K is below 20, then enters on a K/D cross with a higher K low. ATR-band stop, default 2R target; stop can move to entry after 1R. Shorts are the mirror. Author chart: BITSTAMP:BTCUSD, 15-minute. Rules follow the source; this page invents no backtest figures.

Illustrated guidesPine Script®Included with monthly & annual plans
← All strategies
PtGambler · 3.0 · 2026-12-04 · Trend following
BTC EMA and Stoch RSI: In a 50-above-200 trend, go long after an oversold pullback when K crosses D with a higher low; ATR stop, 2R target, stop can move to entry at 1R

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.

Author chart of PtGambler 2 EMA + Stoch RSI + ATR on BITSTAMP:BTCUSD 15-minute
Author chart: BITSTAMP:BTCUSD, 15-minute, from the script's publication page. The image shows the two averages, ATR bands, and trade marks; it is only a visual example, not a live or backtest track record. / 作者展示:BITSTAMP:BTCUSD,15 分钟图,取自作者发布页主图。

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)

InputDefaultWhat it does
Start Year / Month / Day2011 / 1 / 1Start of the backtest window.
Finish Year / Month / Day2050 / 12 / 31End of the backtest window.
EMA Length 1 / EMA Length 250 / 200Periods for the fast and slow exponential averages used as trend and pullback filters.
K / D3 / 3Smoothing length for K in the Stochastic RSI, and the further smoothing that creates D.
RSI Length / Stochastic Length14 / 14Period for the RSI, then for the stochastic of that RSI.
Length / Smoothing / Multiplier14 / EMA / 0.7True-range period, smoothing method, and multiplier for the ATR bands.
Source for upper / lower bandhigh / lowPrice the upper band is added to, and the price the lower band is subtracted from.
Reward to Risk ratio (X times SL)2.0Target distance as a multiple of the stop distance.
Move SL to breakeven when RR hittrueWhether the stop is moved to the entry after price reaches the breakeven trigger.
(Unlabeled number in Profit Target)1.0The 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

  1. Download the .pine file from Coinpred (a current membership is required; see the page) or check the original publication for a newer revision.
  2. Open the symbol and timeframe you want in TradingView, open the Pine Editor, paste the source, and add it to the chart.
  3. 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.
  4. 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.
  5. 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.

Source, license and version

Licensed under MPL 2.0 per the source header, © PtGambler. Redistribution must keep the copyright and license notices; modified files must remain under MPL 2.0. Coinpred ships the unmodified source.

View original source ↗

Check the script license and your TradingView account features. Historical results do not guarantee future performance.

More strategies

All strategies →