Pine Script v5 · Strategy
EMA Stoch Strategy For ProfitView
A Pine Script v5 strategy built on RSI (close, 0), SMA or Stoch (1) and SMA (k, 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 0.1% commission. 22 settings; defaults include Take Profit (%) [0 = Disabled] 0.0, Stop Loss (%) [0 = Disabled] 0.0 and Stochastic Length 14.
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 EMA Stoch Strategy For ProfitView repaint?
- Yes
- At least one pattern in the source can repaint: intrabar recalculation.
- How did EMA Stoch Strategy For ProfitView do on BTCUSDT 1D with default settings?
- −69.78%
- From 26 Jan 2024 to 21 Oct 2026, over 5 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- What alerts does EMA Stoch Strategy For ProfitView have?
- 3
- pv_alert_long + "(" + exsym + "acc=" + pv_acc + tpsl_str + ",mylev=" + str.tostring(pv_lev) + ")"; pv_alert_short + "(" + exsym + "acc=" + pv_acc + tpsl_str + ",mylev=" + str.tostring(pv_lev) + ")"; pv_alert_cancel + "(" + exsym + "acc=" + pv_acc + ")".
- Does EMA Stoch Strategy For ProfitView 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: 5 before, 5 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 EMA Stoch Strategy For ProfitView use a stop loss?
- Yes
- strategy.exit sets a stop on line 62, 75.
BTCUSDT · 1D · default settings
- EMA
- Entry Price
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- −69.78%
- −$697.78
- Buy and hold
- +102.5%
- same period
- Closed trades
- 5
- 1 won · 4 lost
- Profitable
- 20.0%
- of closed trades
- Profit factor
- 0.06
- gross profit ÷ gross loss
- Max drawdown
- 80.63%
- −$806.29
One run with the author's default settings, $1,000 starting capital, commission as the script sets it. A long position was still open at the last bar. 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
Every trade uses all the equity
default_qty_value is 100% of equity.
-
Note
2 settings have no label
In the settings dialog src (line 12), src1 (line 22) show 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.
| Setting | Default | Type and range | Feeds |
|---|---|---|---|
| TP / SL | |||
| Take Profit (%) [0 = Disabled] | 0.0 | float · min 0 · step .25 | profit_abs ProfitTarget is_tpsl_hit tpsl_str Profit Price |
| Stop Loss (%) [0 = Disabled] | 0.0 | float · min 0 · step .25 | stop_abs LossTarget is_tpsl_hit tpsl_str Stop Price |
| Stochastic | |||
| Stochastic Length | 14 | int · min 1 | k |
| K Smoothing | 1 | int · min 1 | k |
| D Smoothing | 3 | int · min 1 | d |
| RSI Length [0 = Disabled]If enabled, use Stoch Rsi. If disabled, use plain Stoch | 0 | int · min 0 | rsi1 k |
| Src (no label in the script) | close | source | rsi1 |
| EMA | |||
| Length EMA | 200 | int | ema1 |
| Src1 (no label in the script) | close | source | ema1 |
| Signal Options | |||
| Stoch below/cross this value for Long signals | 20 | int | long1 long2 long3 |
| Stoch above/cross this value for Short signals | 80 | int | short1 short2 short3 |
| Long Signal Type | Stoch Below Value | string · options ['Stoch Below Value' , 'K&D Cross Below Value' , 'Stoch CrossUp the Value'] | long1 long2 long3 |
| Short Signal Type | Stoch Above Value | string · options ['Stoch Above Value' , 'K&D Cross Above Value' , 'Stoch CrossDown the Value'] | short1 short2 short3 |
| Backtesting | |||
| Backtesting Start Time | timestamp("01 Jan 2014 00:00 +0000") | time | timeCond |
| Backtesting End Time | timestamp("01 Jan 2100 23:59 +0000") | time | timeCond |
| PV Settings | |||
| Exchange | deribit-testnet | string | exsym |
| Symbol | btc-perpetual | string | exsym |
| Account | | string | alert |
| PV Alert Name Longs | | string | alert |
| PV Alert Name Shorts | | string | alert |
| PV Alert Name TP/SL | | string | alert |
| LeverageOptional parameter for PV use. Does not affect backtest. Add leverage=_mylev to your PV order entry line if you want to specify it | 0.0 | float · min 0.0 · step 0.1 | alert |
What it calculates
- RSISrc (close), RSI Length [0 = Disabled] (0)
rsi1 · line 13 - SMA / Stochta.stoch(rsi1, rsi1, rsi1, lenghtStoch), K Smoothing (1)
k · line 14 - SMAk, D Smoothing (3)
d · line 15 - EMASrc1 (close), Length EMA (200)
ema1 · line 23 - Crossk, d · chosen by Long Signal Type
long2 · line 29 - Crossoverk, Stoch below/cross this value for Long signals (20) · chosen by Long Signal Type
long3 · line 30 - Crossk, d · chosen by Short Signal Type
short2 · line 34 - Crossunderk, Stoch above/cross this value for Short signals (80) · chosen by Short Signal Type
short3 · line 35
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.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open Long long | ((long1 or long2 or long3) and not is_long) | On | 61 |
| Exit Exit Long (TP/SL) stop and limit | ((long1 or long2 or long3) and not is_long) | On | 62 |
| Open Short short | ((short1 or short2 or short3) and not is_short) | On | 74 |
| Exit Exit Short (TP/SL) stop and limit | ((short1 or short2 or short3) and not is_short) | On | 75 |
Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.
Alerts
| Alert | Call | Message | Line |
|---|---|---|---|
| (no title) | alert | pv_alert_long + "(" + exsym + "acc=" + pv_acc + tpsl_str + ",mylev=" + str.tostring(pv_lev) + ")" | 71 |
| (no title) | alert | pv_alert_short + "(" + exsym + "acc=" + pv_acc + tpsl_str + ",mylev=" + str.tostring(pv_lev) + ")" | 84 |
| (no title) | alert | pv_alert_cancel + "(" + exsym + "acc=" + pv_acc + ")" | 87 |
Does it repaint?
Yes
At least one pattern in the source can repaint; it is marked Check below.
- ClearHigher-timeframe dataThe script requests no other symbol or timeframe.
- ClearFuture-bar referencesNo negative history offsets such as close[-1].
- CheckIntrabar recalculationcalc_on_every_tick = true. Live values can differ from history.
- ClearOrder timingprocess_orders_on_close = true: orders fill at the signal bar's close.
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.
| Market | Net | Buy and hold | Trades | Won | Profit factor | Max drawdown | Period |
|---|---|---|---|---|---|---|---|
| BTCUSDT 1D | −69.8% | +102.5% | 5 | 20% | 0.06 | 80.6% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | −25.1% | +5.5% | 3 | 0% | 0.00 | 30.9% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | −60.9% | +9.8% | 3 | 0% | 0.00 | 119.0% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +42.0% | +8.4% | 2 | 50% | 34.54 | 4.9% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | −55.5% | +16.7% | 5 | 20% | 0.12 | 92.8% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +12.1% | +21.5% | 4 | 50% | 1.61 | 25.5% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +3.0% | +148.3% | 4 | 50% | 1.19 | 23.2% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +24.6% | +17.1% | 2 | 100% | 197.92 | 4.8% | 8 May 2026 – 21 Oct 2026 |
Backtests are simulations on historical data and are not investment advice.
The trades
By market direction
| At entry, last 90 bars | Trades | Won | P&L |
|---|---|---|---|
| Rising market | 2 | 0% | −$74.77 |
| Sideways market | 1 | 0% | −$590.52 |
| Falling market | 2 | 50% | −$32.20 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
73.9%
The 95th percentile of the worst drawdown when the same 5 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 69.7% to 73.9%; the tick is what actually happened, 73.9%. Order luck alone moves it this much.
All 5 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| short | 14 Sep 2024 59,993.00 | 28 Dec 2024 95,300.00 | 105 | −$590.52 |
| long | 28 Dec 2024 95,300.00 | 18 Apr 2025 84,474.70 | 111 | −$47.42 |
| short | 18 Apr 2025 84,474.70 | 5 Jun 2025 101,509.00 | 48 | −$73.81 |
| long | 5 Jun 2025 101,509.00 | 4 Dec 2025 92,078.10 | 182 | −$27.34 |
| short | 4 Dec 2025 92,078.10 | 11 Sep 2026 77,225.70 | 281 | $41.61 |
Similar scripts
Indicators and strategies built from the same calculations, run on BTCUSDT 1D with their own defaults so they can be compared directly.
| Script | Shares | Type | Net | Trades | Max drawdown |
|---|---|---|---|---|---|
| EMA Stoch Strategy For ProfitView this page | — | v5 strategy | −69.8% | 5 | 80.6% |
| RSI Mean Reversion Bot Strategy by Solutions1978 | rsi ema stoch sma | v4 strategy | No trades on this market | ||
| Moving Average Crossover Strategy by Decam9 | sma ema rsi cross | v5 strategy | +0.0% | 75 | 4.3% |
| Momentum Trading By Mahfuz Azim by mahfuzazim_TA | sma ema rsi cross | v3 strategy | +76,395.0% | 18 | 11,732.8% |
| MACD, RSI, & RVOL Strategy by BobBarker42069 | rsi ema sma | v4 strategy | +32.6% | 1 | 1.5% |
| IFR2 - RSI2 by jocker.soad | rsi sma ema | v4 strategy | No trades on this market | ||
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.
- 5 settings use the untyped input() (line 12, 21, 22, 26, 31). 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.
Same 5 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 12: input() → input.source()
- Line 21: input() → input.int()
- Line 22: input() → input.source()
- Line 26: input() → input.int()
- Line 31: input() → input.int()
⋯lenghtRSI= input.int(0, "RSI Length [0 = Disabled]", tooltip="If enabled, use Stoch Rsi. If disabled, use plain Stoch", minval=0, inline="rsi",group='Stochastic') -src = input(close, title="", inline="rsi",group='Stochastic')+src = input.source(close, title="", inline="rsi",group='Stochastic')rsi1 = lenghtRSI > 0 ? ta.rsi(src, lenghtRSI) : na⋯// EMA-len1= input(200,title='Length EMA ',group='EMA', inline="ema")+len1= input.int(200,title='Length EMA ',group='EMA', inline="ema")-src1= input(close,title='',group='EMA', inline="ema")+src1= input.source(close,title='',group='EMA', inline="ema")ema1= ta.ema(src1,len1)⋯// Signals-LongVal= input(20,title='Stoch below/cross this value for Long signals',group='Signal Options')+LongVal= input.int(20,title='Stoch below/cross this value for Long signals',group='Signal Options')scegliLong= input.string('Stoch Below Value', options= ['Stoch Below Value' , 'K&D Cross Below Value' , 'Stoch CrossUp the Value'] , title='Long Signal Type')⋯long3= scegliLong == 'Stoch CrossUp the Value' ? ta.crossover(k,LongVal) and close > ema1 : na-shortVal= input(80,title='Stoch above/cross this value for Short signals',group='Signal Options')+shortVal= input.int(80,title='Stoch above/cross this value for Short signals',group='Signal Options')scegliShort= input.string('Stoch Above Value', options= ['Stoch Above Value' , 'K&D Cross Above Value' , 'Stoch CrossDown the Value'] , title='Short Signal Type' )⋯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: 5 before, 5 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.
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/-//@version=5+//@version=6strategy(title="EMA Stoch Strategy For ProfitView", overlay=true, calc_on_every_tick=true, process_orders_on_close=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_type=strategy.commission.percent, commission_value=0.1, initial_capital=1000)⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 40 ms | Yes 1,000 bars in 83 ms | Not measured |
| PineTS | Not tested | Not tested | Not 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///@version=5strategy(title="EMA Stoch Strategy For ProfitView", overlay=true, calc_on_every_tick=true, process_orders_on_close=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_type=strategy.commission.percent, commission_value=0.1, initial_capital=1000)// Take profit & stop lossTakeProfitPercent = input.float(defval = 0.0, title="Take Profit (%) [0 = Disabled]",minval = 0, step=.25,group='TP / SL')StopLossPercent = input.float(defval = 0.0, title="Stop Loss (%) [0 = Disabled]",minval = 0, step=.25,group='TP / SL')// StochlenghtStoch = input.int(14, "Stochastic Length", minval=1,group='Stochastic')smoothK = input.int(1, title="K Smoothing", minval=1,group='Stochastic')periodD = input.int(3, title="D Smoothing", minval=1,group='Stochastic')lenghtRSI= input.int(0, "RSI Length [0 = Disabled]", tooltip="If enabled, use Stoch Rsi. If disabled, use plain Stoch", minval=0, inline="rsi",group='Stochastic') src = input(close, title="", inline="rsi",group='Stochastic')rsi1 = lenghtRSI > 0 ? ta.rsi(src, lenghtRSI) : nak = lenghtRSI > 0 ? ta.sma(ta.stoch(rsi1, rsi1, rsi1, lenghtStoch), smoothK) : ta.sma(ta.stoch(close, high, low, lenghtStoch), smoothK)d = ta.sma(k, periodD)plot(k, title="K", color=color.new(#2962FF, 100))plot(d, title="D", color=color.new(#FF6D00, 100))bgcolor(color=color.from_gradient(k, 0, 100, color.new(#2962FF, 100), color.new(#2962FF, 90)), title="K BG")bgcolor(color=color.from_gradient(d, 0, 100, color.new(#FF6D00, 100), color.new(#FF6D00, 90)), title="D BG")// EMAlen1= input(200,title='Length EMA ',group='EMA', inline="ema")src1= input(close,title='',group='EMA', inline="ema")ema1= ta.ema(src1,len1)plot(ema1,title='EMA',color= color.blue ,linewidth=2)// SignalsLongVal= input(20,title='Stoch below/cross this value for Long signals',group='Signal Options')scegliLong= input.string('Stoch Below Value', options= ['Stoch Below Value' , 'K&D Cross Below Value' , 'Stoch CrossUp the Value'] , title='Long Signal Type')long1= scegliLong == 'Stoch Below Value' ? k < LongVal and d < LongVal and close > ema1 : nalong2= scegliLong == 'K&D Cross Below Value' ? ta.cross(k,d) and k < LongVal and d < LongVal and close > ema1 : nalong3= scegliLong == 'Stoch CrossUp the Value' ? ta.crossover(k,LongVal) and close > ema1 : nashortVal= input(80,title='Stoch above/cross this value for Short signals',group='Signal Options')scegliShort= input.string('Stoch Above Value', options= ['Stoch Above Value' , 'K&D Cross Above Value' , 'Stoch CrossDown the Value'] , title='Short Signal Type' )short1= scegliShort == 'Stoch Above Value' ? k > shortVal and d > shortVal and close < ema1 : nashort2= scegliShort == 'K&D Cross Above Value' ? ta.cross(k,d) and k > shortVal and d > shortVal and close < ema1 : nashort3= scegliShort == 'Stoch CrossDown the Value' ? ta.crossunder(k,shortVal) and close < ema1 : nai_startTime = input.time(defval = timestamp("01 Jan 2014 00:00 +0000"), title = "Backtesting Start Time", inline="timestart", group='Backtesting')i_endTime = input.time(defval = timestamp("01 Jan 2100 23:59 +0000"), title = "Backtesting End Time", inline="timeend", group='Backtesting')timeCond = (time > i_startTime) and (time < i_endTime)pv_ex = input.string("deribit-testnet", title="Exchange", group='PV Settings')pv_sym = input.string("btc-perpetual", title="Symbol", group='PV Settings')pv_acc = input.string("", title="Account", group='PV Settings')pv_alert_long = input.string("", title="PV Alert Name Longs", group='PV Settings')pv_alert_short = input.string("", title="PV Alert Name Shorts", group='PV Settings')pv_alert_cancel = input.string("", title="PV Alert Name TP/SL", group='PV Settings')pv_lev = input.float(0.0, title="Leverage", minval=0.0, step=0.1, tooltip="Optional parameter for PV use. Does not affect backtest. Add leverage=_mylev to your PV order entry line if you want to specify it", group='PV Settings')profit_abs = (close * (TakeProfitPercent / 100))stop_abs = (close * (StopLossPercent / 100))ProfitTarget = TakeProfitPercent > 0 ? profit_abs / syminfo.mintick : naLossTarget = StopLossPercent > 0 ? stop_abs / syminfo.mintick : na// Position entry and alertsvar entryprice = 0.0var profitprice = 0.0var stopprice = 0.0var is_long = falsevar is_short = falseis_tpsl_hit = (is_long and ((TakeProfitPercent > 0 and high > profitprice[1]) or (StopLossPercent > 0 and low < stopprice[1]))) or (is_short and ((TakeProfitPercent > 0 and low < profitprice[1]) or (StopLossPercent > 0 and high > stopprice[1])))exsym = pv_ex == "" ? "" : "ex=" + pv_ex + ","exsym := pv_sym == "" ? exsym : exsym + "sym=" + pv_sym + ","if timeCond and not is_tpsl_hit and barstate.isconfirmed if ((long1 or long2 or long3) and not is_long) strategy.entry("Long", strategy.long) strategy.exit("Exit Long (TP/SL)", from_entry = "Long" , profit = ProfitTarget, loss = LossTarget) entryprice := close profitprice := entryprice+profit_abs stopprice := entryprice-stop_abs is_long := true is_short := false tpsl_str = TakeProfitPercent > 0 ? ",mytp=" + str.tostring(profitprice) : "" tpsl_str := StopLossPercent > 0 ? tpsl_str + ",mysl=" + str.tostring(stopprice) : tpsl_str alert(pv_alert_long + "(" + exsym + "acc=" + pv_acc + tpsl_str + ",mylev=" + str.tostring(pv_lev) + ")", alert.freq_once_per_bar_close) if ((short1 or short2 or short3) and not is_short) strategy.entry("Short", strategy.short) strategy.exit("Exit Short (TP/SL)", from_entry = "Short", profit = ProfitTarget, loss = LossTarget) entryprice := close profitprice := entryprice-profit_abs stopprice := entryprice+stop_abs is_long := false is_short := true tpsl_str = TakeProfitPercent > 0 ? ",mytp=" + str.tostring(profitprice) : "" tpsl_str := StopLossPercent > 0 ? tpsl_str + ",mysl=" + str.tostring(stopprice) : tpsl_str alert(pv_alert_short + "(" + exsym + "acc=" + pv_acc + tpsl_str + ",mylev=" + str.tostring(pv_lev) + ")", alert.freq_once_per_bar_close) if (is_tpsl_hit) alert(pv_alert_cancel + "(" + exsym + "acc=" + pv_acc + ")", alert.freq_once_per_bar) is_long := false is_short := falseplot(entryprice, title="Entry Price", color=strategy.opentrades > 0 ? color.gray : color.new(color.gray, 100))plot(profitprice, title="Profit Price", color=strategy.opentrades > 0 and TakeProfitPercent > 0 ? color.green : color.new(color.green, 100))plot(stopprice, title="Stop Price", color=strategy.opentrades > 0 and StopLossPercent > 0? color.red : color.new(color.red, 100))