Zeal Terminal Open in Zeal Terminal

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
Prerendered with the defaults. Change anything and run it here. The script runs in your browser.
Settings (22)
0.0050,000100,000AprJulOct2025AprJulOct2026AprJulOct$332$2,025Equity from $1,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
−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.

SettingDefaultType and rangeFeeds
TP / SL
Take Profit (%) [0 = Disabled]0.0float · min 0 · step .25profit_abs ProfitTarget is_tpsl_hit tpsl_str Profit Price
Stop Loss (%) [0 = Disabled]0.0float · min 0 · step .25stop_abs LossTarget is_tpsl_hit tpsl_str Stop Price
Stochastic
Stochastic Length14int · min 1k
K Smoothing1int · min 1k
D Smoothing3int · min 1d
RSI Length [0 = Disabled]If enabled, use Stoch Rsi. If disabled, use plain Stoch0int · min 0rsi1 k
Src (no label in the script)closesourcersi1
EMA
Length EMA 200intema1
Src1 (no label in the script)closesourceema1
Signal Options
Stoch below/cross this value for Long signals20intlong1 long2 long3
Stoch above/cross this value for Short signals80intshort1 short2 short3
Long Signal TypeStoch Below Valuestring · options ['Stoch Below Value' , 'K&D Cross Below Value' , 'Stoch CrossUp the Value']long1 long2 long3
Short Signal TypeStoch Above Valuestring · options ['Stoch Above Value' , 'K&D Cross Above Value' , 'Stoch CrossDown the Value']short1 short2 short3
Backtesting
Backtesting Start Timetimestamp("01 Jan 2014 00:00 +0000")timetimeCond
Backtesting End Timetimestamp("01 Jan 2100 23:59 +0000")timetimeCond
PV Settings
Exchangederibit-testnetstringexsym
Symbolbtc-perpetualstringexsym
Accountstringalert
PV Alert Name Longsstringalert
PV Alert Name Shortsstringalert
PV Alert Name TP/SLstringalert
LeverageOptional parameter for PV use. Does not affect backtest. Add leverage=_mylev to your PV order entry line if you want to specify it0.0float · min 0.0 · step 0.1alert

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 Typelong2 · line 29
  • Crossoverk, Stoch below/cross this value for Long signals (20) · chosen by Long Signal Typelong3 · line 30
  • Crossk, d · chosen by Short Signal Typeshort2 · line 34
  • Crossunderk, Stoch above/cross this value for Short signals (80) · chosen by Short Signal Typeshort3 · 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.

closecloseprice datalenghtRSIRSI Length [0 = Disable…setting · 0lowlowprice datahighhighprice datalenghtStochStochastic Lengthsetting · 14smoothKK Smoothingsetting · 1periodDD Smoothingsetting · 3len1Length EMA setting · 200scegliLongLong Signal Typesetting · Stoch Below ValueLongValStoch below/cross this …setting · 20scegliShortShort Signal Typesetting · Stoch Above ValueshortValStoch above/cross this …setting · 80TakeProfitPercentTake Profit (%) [0 = Di…setting · 0.0StopLossPercentStop Loss (%) [0 = Disa…setting · 0.0pv_exExchangesetting · deribit-testnetpv_symSymbolsetting · btc-perpetualtimetimeprice datai_startTimeBacktesting Start Timesetting · timestamp("01 Jan 2…i_endTimeBacktesting End Timesetting · timestamp("01 Jan 2…pv_alert_longPV Alert Name Longssetting · pv_accAccountsetting · pv_levLeveragesetting · 0.0pv_alert_shortPV Alert Name Shortssetting · pv_alert_cancelPV Alert Name TP/SLsetting · rsi1RSI→ rsi1kSMA / Stoch→ kdSMA→ dema1EMA→ ema1long2Cross→ long2 · by Long Signal Typelong3Crossover→ long3 · by Long Signal Typeshort2Cross→ short2 · by Short Signal Ty…short3Crossunder→ short3 · by Short Signal Ty…long1long1valueshort1short1valueprofit_absprofit_absvaluestop_absstop_absvalueProfitTargetProfitTargetvalueLossTargetLossTargetvalueentrypriceentrypricevalueprofitpriceprofitpricevaluestoppricestoppricevalueexsymexsymvaluetpsl_strtpsl_strvaluetimeCondtimeCondconditionis_tpsl_hitis_tpsl_hitconditionentry:LongOpen Longstrategy.entryexit:Exit Long (TP/SL)exit Exit Long (TP/SL)strategy.exitentry:ShortOpen Shortstrategy.entryexit:Exit Short (TP/SL)exit Exit Short (TP/SL)strategy.exitplot:16Kplotplot:17Dplotbgcolor:18K BGbgcolorbgcolor:19D BGbgcolorplot:24EMAplotalert:71alertalertalert:84alertalertalert:87alertalertplot:90Entry Priceplotplot:91Profit Priceplotplot:92Stop Priceplot

Order rules

OrderFires whenBy defaultLine
Open Long long((long1 or long2 or long3) and not is_long)On61
Exit Exit Long (TP/SL) stop and limit((long1 or long2 or long3) and not is_long)On62
Open Short short((short1 or short2 or short3) and not is_short)On74
Exit Exit Short (TP/SL) stop and limit((short1 or short2 or short3) and not is_short)On75

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

Alerts

AlertCallMessageLine
(no title)alertpv_alert_long + "(" + exsym + "acc=" + pv_acc + tpsl_str + ",mylev=" + str.tostring(pv_lev) + ")"71
(no title)alertpv_alert_short + "(" + exsym + "acc=" + pv_acc + tpsl_str + ",mylev=" + str.tostring(pv_lev) + ")"84
(no title)alertpv_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.

Not measuredAn engine gap, not the scriptThe script acts only when barstate.isconfirmed is true, which Zeal Terminal's engine never reports during a live replay (it does not run a bar's closing update in live mode), so the replay cannot test this script. The answer comes from the checks on the source alone.
  • 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.

MarketNetBuy and holdTradesWonProfit factorMax drawdownPeriod
BTCUSDT 1D−69.8%+102.5%520%0.0680.6%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h−25.1%+5.5%30%0.0030.9%8 May 2026 – 21 Oct 2026
ETHUSDT 1D−60.9%+9.8%30%0.00119.0%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+42.0%+8.4%250%34.544.9%8 May 2026 – 21 Oct 2026
SOLUSDT 1D−55.5%+16.7%520%0.1292.8%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+12.1%+21.5%450%1.6125.5%8 May 2026 – 21 Oct 2026
BNBUSDT 1D+3.0%+148.3%450%1.1923.2%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+24.6%+17.1%2100%197.924.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 barsTradesWonP&L
Rising market20%−$74.77
Sideways market10%−$590.52
Falling market250%−$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.

0%85%
All 5 trades
SideEntryExitBarsP&L
short14 Sep 2024 59,993.0028 Dec 2024 95,300.00105−$590.52
long28 Dec 2024 95,300.0018 Apr 2025 84,474.70111−$47.42
short18 Apr 2025 84,474.705 Jun 2025 101,509.0048−$73.81
long5 Jun 2025 101,509.004 Dec 2025 92,078.10182−$27.34
short4 Dec 2025 92,078.1011 Sep 2026 77,225.70281$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.

ScriptSharesTypeNetTradesMax drawdown
EMA Stoch Strategy For ProfitView this page—v5 strategy−69.8%580.6%
RSI Mean Reversion Bot Strategy by Solutions1978rsi ema stoch smav4 strategyNo trades on this market
Moving Average Crossover Strategy by Decam9sma ema rsi crossv5 strategy+0.0%754.3%
Momentum Trading By Mahfuz Azim by mahfuzazim_TAsma ema rsi crossv3 strategy+76,395.0%1811,732.8%
MACD, RSI, & RVOL Strategy by BobBarker42069rsi ema smav4 strategy+32.6%11.5%
IFR2 - RSI2 by jocker.soadrsi sma emav4 strategyNo 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.

Clean v5

VerifiedDownload the v5 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

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 40 msYes 1,000 bars in 83 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///@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))