Zeal Terminal Open in Zeal Terminal

Pine Script v5 · Strategy

Ema Scalp

A Pine Script v5 strategy built on EMA (close, 100). It has 8 order rules, 4 entries among them, and trades long and short with the default settings. Exits use a stop loss and a profit target. Each trade is one contract and pays no commission. 2 settings; defaults include Stop Loss % 0.8 and Take Profit % 1.0.

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 Scalp repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 16 of 16 trades.
How did Ema Scalp do on BTCUSDT 1D with default settings?
+2.39%
From 26 Jan 2024 to 21 Oct 2026, over 82 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Does Ema Scalp 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: 82 before, 13 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 Scalp use a stop loss?
Yes
strategy.exit sets a stop on line 62, 64, 66, 68.
Does Ema Scalp run in Zeal Terminal?
Yes
It compiles in 33 ms and runs 1,000 bars in 47 ms, in the browser.

BTCUSDT · 1D · default settings

  • Plot
  • Long Fixed SL
  • Short Fixed SL
  • Long Take Profit
  • Short Take Profit
  • 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 (2)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$1,023,880$2,025,273Equity from $1,000,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.39%
$23,877.50
Buy and hold
+102.5%
same period
Closed trades
82
44 won · 35 lost
Profitable
53.7%
of closed trades
Profit factor
1.51
gross profit ÷ gross loss
Max drawdown
1.22%
−$12,487.10

One run with the author's default settings, $1,000,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.

  • 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
Stop Loss %0.8float · step 0.1longStop shortStop
Take Profit %1.0float · step 0.1shortTake longTake

What it calculates

  • EMAclose, 100eg1 · line 6

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 datastopPerStop Loss %setting · 0.8takePerTake Profit %setting · 1.0eg1EMA→ eg1countbuycountbuyvaluecountsellcountsellvaluenew_counnbnew_counnbvaluenew_counsnew_counsvaluelongStop, shortStoplongStop · shortStop2 valuesshortTake, longTakeshortTake · longTake2 valueslonglongconditionshortshortconditionptrade_islongptrade_islongconditionptrade_isshortptrade_isshortconditionis_pos_closed, is_long, is_shortis_pos_closed · is_long…3 conditionsentry:enter longOpen enter longstrategy.entryentry:enter shortOpen enter shortstrategy.entryentry:El2Open El2strategy.entryentry:Es2Open Es2strategy.entryexit:Close Longexit Close Longstrategy.exitexit:Close Shortexit Close Shortstrategy.exitexit:Close Long2exit Close Long2strategy.exitexit:Close Short2exit Close Short2strategy.exitplot:7plotplotplot:70Long Fixed SLplotplot:71Short Fixed SLplotplot:72Long Take Profitplotplot:73Short Take Profitplot

Order rules

OrderFires whenBy defaultLine
Open enter long longlong and strategy.opentrades==0 and countbuy==1On23
Open enter short shortshort and strategy.opentrades==0 and countsell==1On25
Open El2 longlastTradeWasprofit and ptrade_islongOn49
Open Es2 shortlastTradeWasprofit and ptrade_isshortOn51
Exit Close Long stop and limitstrategy.position_size > 0On62
Exit Close Short stop and limitstrategy.position_size < 0On64
Exit Close Long2 stop and limitstrategy.position_size > 0On66
Exit Close Short2 stop and limitstrategy.position_size < 0On68

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.

16/16trades 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.4%+102.5%8254%1.511.2%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+0.2%+5.5%6746%1.080.7%8 May 2026 – 21 Oct 2026
ETHUSDT 1D−0.0%+9.8%7638%0.880.1%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+0.0%+8.4%5250%1.420.0%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+0.0%+16.7%10548%1.080.0%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+0.0%+21.5%7152%1.380.0%8 May 2026 – 21 Oct 2026
BNBUSDT 1D+0.0%+148.3%7139%1.090.0%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+0.0%+17.1%7949%1.290.0%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 market30%−$1,843.04
Sideways market7356%$23,452.10
Falling market650%$2,268.48

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

How bad could the drawdown be?

1.7%

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

0%2%
All 82 trades
SideEntryExitBarsP&L
long5 May 2024 63,892.006 May 2024 63,380.901−$511.14
short22 Jun 2024 64,143.6023 Jun 2024 63,502.101$641.44
short24 Jun 2024 63,210.0025 Jun 2024 60,293.301$2,916.71
short26 Jun 2024 61,806.0027 Jun 2024 60,865.001$941.03
short28 Jun 2024 61,706.5029 Jun 2024 60,427.801$1,278.62
short30 Jun 2024 60,986.701 Jul 2024 62,772.001−$1,785.33
long16 Jul 2024 64,724.1017 Jul 2024 65,371.301$647.25
long18 Jul 2024 64,088.0019 Jul 2024 63,575.301−$512.71
short3 Aug 2024 61,498.304 Aug 2024 60,698.001$800.35
short5 Aug 2024 58,161.006 Aug 2024 54,018.801$4,142.18
short7 Aug 2024 56,022.008 Aug 2024 55,133.801$888.24
short9 Aug 2024 61,686.0010 Aug 2024 60,838.001$848.01
short11 Aug 2024 60,923.5012 Aug 2024 58,712.601$2,210.92
short13 Aug 2024 59,346.6014 Aug 2024 60,587.201−$1,240.52
long24 Aug 2024 64,037.2025 Aug 2024 64,677.601$640.38
long26 Aug 2024 64,220.0027 Aug 2024 62,834.001−$1,385.99
short28 Aug 2024 59,415.0029 Aug 2024 58,820.801$594.15
short30 Aug 2024 59,359.0031 Aug 2024 58,765.401$593.59
short1 Sep 2024 58,974.002 Sep 2024 57,301.801$1,672.23
short3 Sep 2024 59,132.104 Sep 2024 57,487.701$1,644.38
short5 Sep 2024 57,970.906 Sep 2024 56,180.001$1,790.90
short7 Sep 2024 53,963.008 Sep 2024 54,394.701−$431.71
long19 Sep 2024 61,760.0020 Sep 2024 62,948.001$1,188.02
long21 Sep 2024 63,201.1022 Sep 2024 63,833.101$632.02
long23 Sep 2024 63,578.8024 Sep 2024 63,070.101−$508.64
short2 Oct 2024 60,804.903 Oct 2024 60,196.901$608.05
short4 Oct 2024 60,752.705 Oct 2024 62,086.001−$1,333.28
long6 Oct 2024 62,058.007 Oct 2024 62,819.901$761.90
long8 Oct 2024 62,224.009 Oct 2024 61,726.201−$497.80
short10 Oct 2024 60,636.0011 Oct 2024 61,121.101−$485.09
long12 Oct 2024 62,540.0013 Oct 2024 63,206.201$666.24
long14 Oct 2024 62,870.0015 Oct 2024 66,084.001$3,213.98
long16 Oct 2024 67,074.1017 Oct 2024 67,744.901$670.75
long18 Oct 2024 67,421.8019 Oct 2024 68,428.001$1,006.21
long20 Oct 2024 68,378.0021 Oct 2024 69,061.801$683.78
long22 Oct 2024 67,377.5023 Oct 2024 66,838.501−$539.02
short25 Feb 2025 91,552.9026 Feb 2025 88,680.401$2,872.49
short27 Feb 2025 84,250.1028 Feb 2025 84,924.101−$674.01
long3 Mar 2025 94,270.004 Mar 2025 86,221.201−$8,048.83
short5 Mar 2025 87,282.006 Mar 2025 90,606.001−$3,324.02
long22 Apr 2025 87,516.2023 Apr 2025 93,443.001$5,926.77
long24 Apr 2025 93,691.1025 Apr 2025 92,941.501−$749.53
short26 Aug 2025 110,112.0027 Aug 2025 111,763.001−$1,651.24
long28 Aug 2025 111,262.0029 Aug 2025 112,567.001$1,304.89
short30 Aug 2025 108,377.0030 Aug 2025 108,377.000$0.00
long30 Aug 2025 108,377.0031 Aug 2025 109,461.001$1,083.78
short1 Sep 2025 108,246.001 Sep 2025 108,246.000$0.00
long1 Sep 2025 108,246.002 Sep 2025 109,329.001$1,082.47
long3 Sep 2025 111,240.004 Sep 2025 110,350.001−$889.93
short5 Sep 2025 110,731.008 Sep 2025 111,617.003−$885.85
long9 Sep 2025 112,065.0010 Sep 2025 111,169.001−$896.53
short26 Sep 2025 108,994.0028 Sep 2025 109,866.002−$871.96
long29 Sep 2025 112,164.0030 Sep 2025 114,312.001$2,148.01
long1 Oct 2025 114,049.002 Oct 2025 118,595.001$4,546.05
long3 Oct 2025 120,529.004 Oct 2025 122,232.001$1,702.86
long5 Oct 2025 122,391.006 Oct 2025 123,615.001$1,223.91
long7 Oct 2025 124,659.008 Oct 2025 121,333.001−$3,325.58
short11 Oct 2025 112,774.0012 Oct 2025 110,644.001$2,130.09
long13 Oct 2025 114,959.0013 Oct 2025 114,959.000$0.00
short13 Oct 2025 114,959.0014 Oct 2025 113,809.001$1,149.59
short15 Oct 2025 113,028.0016 Oct 2025 110,763.001$2,264.85
short17 Oct 2025 108,194.0018 Oct 2025 106,432.001$1,762.59
short19 Oct 2025 107,185.0020 Oct 2025 108,643.001−$1,457.77
long27 Oct 2025 114,559.0028 Oct 2025 113,643.001−$916.48
short30 Oct 2025 110,021.0031 Oct 2025 108,323.001$1,698.43
short1 Nov 2025 109,608.002 Nov 2025 110,485.001−$876.87
long15 Jan 2026 96,951.8016 Jan 2026 95,604.801−$1,346.97
short17 Jan 2026 95,550.9018 Jan 2026 94,595.401$955.51
short19 Jan 2026 93,673.1020 Jan 2026 92,631.001$1,042.15
short21 Jan 2026 88,427.7022 Jan 2026 89,454.701−$1,027.07
long18 Apr 2026 77,072.0019 Apr 2026 75,691.801−$1,380.25
short20 Apr 2026 73,801.8021 Apr 2026 75,841.001−$2,039.17
long22 Apr 2026 76,336.1023 Apr 2026 78,178.201$1,842.08
long24 Apr 2026 78,257.5025 Apr 2026 77,437.101−$820.35
short20 May 2026 76,834.4021 May 2026 77,552.201−$717.88
long22 May 2026 77,615.5023 May 2026 75,539.501−$2,076.02
short24 May 2026 76,752.0025 May 2026 77,366.001−$614.02
long26 May 2026 77,322.0027 May 2026 75,930.001−$1,392.00
short28 May 2026 74,449.3029 May 2026 73,617.501$831.79
short30 May 2026 73,460.8031 May 2026 74,048.501−$587.69
long20 Aug 2026 69,334.8021 Aug 2026 73,027.001$3,692.24
long22 Aug 2026 78,338.0023 Aug 2026 77,074.901−$1,263.09

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 Scalp this page—v5 strategy+2.4%821.2%
EMA Slope AyE by fajardoarelysemav4 strategyNo trades on this market
ROoT by realisticDove62527emav5 strategy−4.7%2259.4%
sachin5986 by mohitesachin78emav4 strategy+32.1%3517.6%
sonu1997 by Sonu1997emav4 strategy+960.7%21,103.8%
Moving Average Crossover by Muh4mm4demav4 strategy+19,990.1%301,274.2%

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.

  • No v6-only features. v6 is not needed to run this script.

Clean v5

Verified

Nothing to change.

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: 82 before, 13 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.

⋯// © Shauryam_or-//@version=5+//@version=6strategy('Ema Scalp', overlay=true)⋯

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 33 msYes 1,000 bars in 47 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/// © Shauryam_or//@version=5strategy('Ema Scalp', overlay=true)// Moving Averages to get some example trades generatedeg1 = ta.ema(close, 100)plot(eg1,color=color.aqua)long = close>eg1short = close<eg1var countbuy=0if long    countbuy:=countbuy+1if strategy.position_size<0     countbuy:=0var countsell=0if short    countsell:=countsell+1if strategy.position_size>0     countsell:=0////////////////////////////////// stratgey startedif long and strategy.opentrades==0 and countbuy==1  // open first long when close>ema     strategy.entry("enter long", strategy.long)if short and strategy.opentrades==0 and countsell==1 // open first short when close<ema    strategy.entry("enter short", strategy.short)// checking last trade is long or shortis_pos_closed = (strategy.position_size[1] != 0 and strategy.position_size == 0) or ((strategy.position_size[1] * strategy.position_size) < 0)is_long = strategy.position_size > 0is_short = strategy.position_size < 0ptrade_islong=is_pos_closed and is_long[1]ptrade_isshort=is_pos_closed and is_short[1]// checking is last trade is profitvar lastTradeWasprofit = falseif (strategy.wintrades[0] > strategy.wintrades[1])       // last trade was a profit    lastTradeWasprofit := trueif  (strategy.losstrades[0] > strategy.losstrades[1])      // unsuccessful trade, reset    lastTradeWasprofit := false// if last trade is a long trade and loss and close>ema open 2nd trade long sidenew_counnb=0new_couns=0if   lastTradeWasprofit and ptrade_islong    new_counnb:=new_counnb+1    if   lastTradeWasprofit and ptrade_isshort    new_couns:=new_couns+1if   lastTradeWasprofit and ptrade_islong      strategy.entry("El2",strategy.long,comment ="long")if   lastTradeWasprofit and ptrade_isshort    strategy.entry("Es2",strategy.short,comment ="short")//exit in percentage // User Options to Change Inputs (%)stopPer = input.float(0.8,step=0.1, title='Stop Loss %') / 100takePer = input.float(1.0,step=0.1, title='Take Profit %') / 100// Determine where you've entered and in what directionlongStop  =strategy.position_avg_price * (1 - stopPer)shortStop =strategy.position_avg_price * (1 + stopPer)shortTake =strategy.position_avg_price * (1 - takePer)longTake  =strategy.position_avg_price * (1 + takePer)if strategy.position_size > 0    strategy.exit(id='Close Long',from_entry = "enter long", stop=longStop, limit=longTake)if strategy.position_size < 0    strategy.exit(id='Close Short',from_entry = "enter short", stop=shortStop, limit=shortTake)if strategy.position_size > 0    strategy.exit(id='Close Long2',from_entry = "El2", stop=longStop, limit=longTake)if strategy.position_size < 0    strategy.exit(id='Close Short2',from_entry = "Es2", stop=shortStop, limit=shortTake)//PLOT FIXED SLTP LINEplot(strategy.position_size > 0 ? longStop : na, style=plot.style_linebr, color=color.new(color.red, 0), linewidth=1, title='Long Fixed SL')plot(strategy.position_size < 0 ? shortStop : na, style=plot.style_linebr, color=color.new(color.red, 0), linewidth=1, title='Short Fixed SL')plot(strategy.position_size > 0 ? longTake : na, style=plot.style_linebr, color=color.new(color.green, 0), linewidth=1, title='Long Take Profit')plot(strategy.position_size < 0 ? shortTake : na, style=plot.style_linebr, color=color.new(color.green, 0), linewidth=1, title='Short Take Profit')