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
- 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.
| Setting | Default | Type and range | Feeds |
|---|---|---|---|
| Stop Loss % | 0.8 | float · step 0.1 | longStop shortStop |
| Take Profit % | 1.0 | float · step 0.1 | shortTake longTake |
What it calculates
- EMAclose, 100
eg1 · 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.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open enter long long | long and strategy.opentrades==0 and countbuy==1 | On | 23 |
| Open enter short short | short and strategy.opentrades==0 and countsell==1 | On | 25 |
| Open El2 long | lastTradeWasprofit and ptrade_islong | On | 49 |
| Open Es2 short | lastTradeWasprofit and ptrade_isshort | On | 51 |
| Exit Close Long stop and limit | strategy.position_size > 0 | On | 62 |
| Exit Close Short stop and limit | strategy.position_size < 0 | On | 64 |
| Exit Close Long2 stop and limit | strategy.position_size > 0 | On | 66 |
| Exit Close Short2 stop and limit | strategy.position_size < 0 | On | 68 |
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.
- 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.
| Market | Net | Buy and hold | Trades | Won | Profit factor | Max drawdown | Period |
|---|---|---|---|---|---|---|---|
| BTCUSDT 1D | +2.4% | +102.5% | 82 | 54% | 1.51 | 1.2% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +0.2% | +5.5% | 67 | 46% | 1.08 | 0.7% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | −0.0% | +9.8% | 76 | 38% | 0.88 | 0.1% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +0.0% | +8.4% | 52 | 50% | 1.42 | 0.0% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +0.0% | +16.7% | 105 | 48% | 1.08 | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +0.0% | +21.5% | 71 | 52% | 1.38 | 0.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +0.0% | +148.3% | 71 | 39% | 1.09 | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +0.0% | +17.1% | 79 | 49% | 1.29 | 0.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 bars | Trades | Won | P&L |
|---|---|---|---|
| Rising market | 3 | 0% | −$1,843.04 |
| Sideways market | 73 | 56% | $23,452.10 |
| Falling market | 6 | 50% | $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.
All 82 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 5 May 2024 63,892.00 | 6 May 2024 63,380.90 | 1 | −$511.14 |
| short | 22 Jun 2024 64,143.60 | 23 Jun 2024 63,502.10 | 1 | $641.44 |
| short | 24 Jun 2024 63,210.00 | 25 Jun 2024 60,293.30 | 1 | $2,916.71 |
| short | 26 Jun 2024 61,806.00 | 27 Jun 2024 60,865.00 | 1 | $941.03 |
| short | 28 Jun 2024 61,706.50 | 29 Jun 2024 60,427.80 | 1 | $1,278.62 |
| short | 30 Jun 2024 60,986.70 | 1 Jul 2024 62,772.00 | 1 | −$1,785.33 |
| long | 16 Jul 2024 64,724.10 | 17 Jul 2024 65,371.30 | 1 | $647.25 |
| long | 18 Jul 2024 64,088.00 | 19 Jul 2024 63,575.30 | 1 | −$512.71 |
| short | 3 Aug 2024 61,498.30 | 4 Aug 2024 60,698.00 | 1 | $800.35 |
| short | 5 Aug 2024 58,161.00 | 6 Aug 2024 54,018.80 | 1 | $4,142.18 |
| short | 7 Aug 2024 56,022.00 | 8 Aug 2024 55,133.80 | 1 | $888.24 |
| short | 9 Aug 2024 61,686.00 | 10 Aug 2024 60,838.00 | 1 | $848.01 |
| short | 11 Aug 2024 60,923.50 | 12 Aug 2024 58,712.60 | 1 | $2,210.92 |
| short | 13 Aug 2024 59,346.60 | 14 Aug 2024 60,587.20 | 1 | −$1,240.52 |
| long | 24 Aug 2024 64,037.20 | 25 Aug 2024 64,677.60 | 1 | $640.38 |
| long | 26 Aug 2024 64,220.00 | 27 Aug 2024 62,834.00 | 1 | −$1,385.99 |
| short | 28 Aug 2024 59,415.00 | 29 Aug 2024 58,820.80 | 1 | $594.15 |
| short | 30 Aug 2024 59,359.00 | 31 Aug 2024 58,765.40 | 1 | $593.59 |
| short | 1 Sep 2024 58,974.00 | 2 Sep 2024 57,301.80 | 1 | $1,672.23 |
| short | 3 Sep 2024 59,132.10 | 4 Sep 2024 57,487.70 | 1 | $1,644.38 |
| short | 5 Sep 2024 57,970.90 | 6 Sep 2024 56,180.00 | 1 | $1,790.90 |
| short | 7 Sep 2024 53,963.00 | 8 Sep 2024 54,394.70 | 1 | −$431.71 |
| long | 19 Sep 2024 61,760.00 | 20 Sep 2024 62,948.00 | 1 | $1,188.02 |
| long | 21 Sep 2024 63,201.10 | 22 Sep 2024 63,833.10 | 1 | $632.02 |
| long | 23 Sep 2024 63,578.80 | 24 Sep 2024 63,070.10 | 1 | −$508.64 |
| short | 2 Oct 2024 60,804.90 | 3 Oct 2024 60,196.90 | 1 | $608.05 |
| short | 4 Oct 2024 60,752.70 | 5 Oct 2024 62,086.00 | 1 | −$1,333.28 |
| long | 6 Oct 2024 62,058.00 | 7 Oct 2024 62,819.90 | 1 | $761.90 |
| long | 8 Oct 2024 62,224.00 | 9 Oct 2024 61,726.20 | 1 | −$497.80 |
| short | 10 Oct 2024 60,636.00 | 11 Oct 2024 61,121.10 | 1 | −$485.09 |
| long | 12 Oct 2024 62,540.00 | 13 Oct 2024 63,206.20 | 1 | $666.24 |
| long | 14 Oct 2024 62,870.00 | 15 Oct 2024 66,084.00 | 1 | $3,213.98 |
| long | 16 Oct 2024 67,074.10 | 17 Oct 2024 67,744.90 | 1 | $670.75 |
| long | 18 Oct 2024 67,421.80 | 19 Oct 2024 68,428.00 | 1 | $1,006.21 |
| long | 20 Oct 2024 68,378.00 | 21 Oct 2024 69,061.80 | 1 | $683.78 |
| long | 22 Oct 2024 67,377.50 | 23 Oct 2024 66,838.50 | 1 | −$539.02 |
| short | 25 Feb 2025 91,552.90 | 26 Feb 2025 88,680.40 | 1 | $2,872.49 |
| short | 27 Feb 2025 84,250.10 | 28 Feb 2025 84,924.10 | 1 | −$674.01 |
| long | 3 Mar 2025 94,270.00 | 4 Mar 2025 86,221.20 | 1 | −$8,048.83 |
| short | 5 Mar 2025 87,282.00 | 6 Mar 2025 90,606.00 | 1 | −$3,324.02 |
| long | 22 Apr 2025 87,516.20 | 23 Apr 2025 93,443.00 | 1 | $5,926.77 |
| long | 24 Apr 2025 93,691.10 | 25 Apr 2025 92,941.50 | 1 | −$749.53 |
| short | 26 Aug 2025 110,112.00 | 27 Aug 2025 111,763.00 | 1 | −$1,651.24 |
| long | 28 Aug 2025 111,262.00 | 29 Aug 2025 112,567.00 | 1 | $1,304.89 |
| short | 30 Aug 2025 108,377.00 | 30 Aug 2025 108,377.00 | 0 | $0.00 |
| long | 30 Aug 2025 108,377.00 | 31 Aug 2025 109,461.00 | 1 | $1,083.78 |
| short | 1 Sep 2025 108,246.00 | 1 Sep 2025 108,246.00 | 0 | $0.00 |
| long | 1 Sep 2025 108,246.00 | 2 Sep 2025 109,329.00 | 1 | $1,082.47 |
| long | 3 Sep 2025 111,240.00 | 4 Sep 2025 110,350.00 | 1 | −$889.93 |
| short | 5 Sep 2025 110,731.00 | 8 Sep 2025 111,617.00 | 3 | −$885.85 |
| long | 9 Sep 2025 112,065.00 | 10 Sep 2025 111,169.00 | 1 | −$896.53 |
| short | 26 Sep 2025 108,994.00 | 28 Sep 2025 109,866.00 | 2 | −$871.96 |
| long | 29 Sep 2025 112,164.00 | 30 Sep 2025 114,312.00 | 1 | $2,148.01 |
| long | 1 Oct 2025 114,049.00 | 2 Oct 2025 118,595.00 | 1 | $4,546.05 |
| long | 3 Oct 2025 120,529.00 | 4 Oct 2025 122,232.00 | 1 | $1,702.86 |
| long | 5 Oct 2025 122,391.00 | 6 Oct 2025 123,615.00 | 1 | $1,223.91 |
| long | 7 Oct 2025 124,659.00 | 8 Oct 2025 121,333.00 | 1 | −$3,325.58 |
| short | 11 Oct 2025 112,774.00 | 12 Oct 2025 110,644.00 | 1 | $2,130.09 |
| long | 13 Oct 2025 114,959.00 | 13 Oct 2025 114,959.00 | 0 | $0.00 |
| short | 13 Oct 2025 114,959.00 | 14 Oct 2025 113,809.00 | 1 | $1,149.59 |
| short | 15 Oct 2025 113,028.00 | 16 Oct 2025 110,763.00 | 1 | $2,264.85 |
| short | 17 Oct 2025 108,194.00 | 18 Oct 2025 106,432.00 | 1 | $1,762.59 |
| short | 19 Oct 2025 107,185.00 | 20 Oct 2025 108,643.00 | 1 | −$1,457.77 |
| long | 27 Oct 2025 114,559.00 | 28 Oct 2025 113,643.00 | 1 | −$916.48 |
| short | 30 Oct 2025 110,021.00 | 31 Oct 2025 108,323.00 | 1 | $1,698.43 |
| short | 1 Nov 2025 109,608.00 | 2 Nov 2025 110,485.00 | 1 | −$876.87 |
| long | 15 Jan 2026 96,951.80 | 16 Jan 2026 95,604.80 | 1 | −$1,346.97 |
| short | 17 Jan 2026 95,550.90 | 18 Jan 2026 94,595.40 | 1 | $955.51 |
| short | 19 Jan 2026 93,673.10 | 20 Jan 2026 92,631.00 | 1 | $1,042.15 |
| short | 21 Jan 2026 88,427.70 | 22 Jan 2026 89,454.70 | 1 | −$1,027.07 |
| long | 18 Apr 2026 77,072.00 | 19 Apr 2026 75,691.80 | 1 | −$1,380.25 |
| short | 20 Apr 2026 73,801.80 | 21 Apr 2026 75,841.00 | 1 | −$2,039.17 |
| long | 22 Apr 2026 76,336.10 | 23 Apr 2026 78,178.20 | 1 | $1,842.08 |
| long | 24 Apr 2026 78,257.50 | 25 Apr 2026 77,437.10 | 1 | −$820.35 |
| short | 20 May 2026 76,834.40 | 21 May 2026 77,552.20 | 1 | −$717.88 |
| long | 22 May 2026 77,615.50 | 23 May 2026 75,539.50 | 1 | −$2,076.02 |
| short | 24 May 2026 76,752.00 | 25 May 2026 77,366.00 | 1 | −$614.02 |
| long | 26 May 2026 77,322.00 | 27 May 2026 75,930.00 | 1 | −$1,392.00 |
| short | 28 May 2026 74,449.30 | 29 May 2026 73,617.50 | 1 | $831.79 |
| short | 30 May 2026 73,460.80 | 31 May 2026 74,048.50 | 1 | −$587.69 |
| long | 20 Aug 2026 69,334.80 | 21 Aug 2026 73,027.00 | 1 | $3,692.24 |
| long | 22 Aug 2026 78,338.00 | 23 Aug 2026 77,074.90 | 1 | −$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.
| Script | Shares | Type | Net | Trades | Max drawdown |
|---|---|---|---|---|---|
| Ema Scalp this page | — | v5 strategy | +2.4% | 82 | 1.2% |
| EMA Slope AyE by fajardoarelys | ema | v4 strategy | No trades on this market | ||
| ROoT by realisticDove62527 | ema | v5 strategy | −4.7% | 225 | 9.4% |
| sachin5986 by mohitesachin78 | ema | v4 strategy | +32.1% | 35 | 17.6% |
| sonu1997 by Sonu1997 | ema | v4 strategy | +960.7% | 2 | 1,103.8% |
| Moving Average Crossover by Muh4mm4d | ema | v4 strategy | +19,990.1% | 30 | 1,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
VerifiedNothing 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
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 33 ms | Yes 1,000 bars in 47 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/// © 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')