Pine Script v4 · Strategy
4X EMA and volume strategy
A Pine Script v4 strategy built on EMA (close, 13) and SMA or Change (14). It has 4 order rules, 2 entries among them, and trades long only with the default settings. Exits wait for a signal; there is no stop loss. Each trade commits 100% of equity and pays 0.1% commission. 8 settings; defaults include Ema1l 13, Ema2l 21 and Ema3l 50.
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 4X EMA and volume strategy repaint?
- No
- No repainting patterns were found in the source. The live replay was not measured: it had no trades to compare.
- How did 4X EMA and volume strategy do on BTCUSDT 1D with default settings?
- +1.81%
- From 26 Jan 2024 to 21 Oct 2026, over 3 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Can 4X EMA and volume strategy be converted to Pine Script v5?
- Yes
- The upgrade takes 1 step, from v4; each was run before and after on the same candles with identical results, and the v5 script can be downloaded below.
- Does 4X EMA and volume strategy use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
- Does 4X EMA and volume strategy run in Zeal Terminal?
- Yes
- It compiles in 14 ms and runs 1,000 bars in 32 ms, in the browser.
BTCUSDT · 1D · default settings
- EMA
- EMA
- EMA
- EMA
- SMA
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- +1.81%
- $18.06
- Buy and hold
- +102.5%
- same period
- Closed trades
- 3
- 2 won · 1 lost
- Profitable
- 66.7%
- of closed trades
- Profit factor
- 1.14
- gross profit ÷ gross loss
- Max drawdown
- 25.76%
- −$257.60
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
No stop loss
Every exit waits for a signal. Nothing limits a losing trade before the exit condition fires.
-
Check
Every trade uses all the equity
default_qty_value is 100% of equity.
-
Note
7 settings have no label
In the settings dialog ema1l (line 6), ema2l (line 7), ema3l (line 8), ema4l (line 9), length (line 19), option1 (line 22), option2 (line 23) 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.
-
Note
Uses an argument v6 removed
when = on line 25, 26, 29, 30. The upgraded version below moves each call inside an if block.
Upgrade and export
Written in Pine Script v4. The upgrade to v5 takes 1 step, one per version, each applied to the result of the one before. A last clean-v5 pass then types the settings and moves when = into if blocks, which v6 requires. Every step runs before and after on the same candles in Zeal Terminal's engine; a step whose results differ is shown but not offered as a download. Upgrades preserve behaviour: bugs are fixed in the Review, never silently here.
- Upgrading to v5 renames ema → ta.ema, crossover → ta.crossover, crossunder → ta.crossunder, sma → ta.sma, change → ta.change.
- 4 strategy calls use the when = argument (line 25, 26, 29, 30). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
v4 → v5
VerifiedSame 3 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 3: //@version=4 → //@version=5
- Line 10: ema → ta.ema
- Line 11: ema → ta.ema
- Line 12: ema → ta.ema
- Line 13: ema → ta.ema
- Line 15: crossover → ta.crossover
7 more edits
- Line 15: crossover → ta.crossover
- Line 17: crossunder → ta.crossunder
- Line 17: crossunder → ta.crossunder
- Line 21: sma → ta.sma
- Line 21: change → ta.change
- Line 25: strategy.entry(…, 1) → strategy.entry(…, strategy.long)
- Line 29: strategy.entry(…, 1) → strategy.entry(…, strategy.long)
⋯// © SoftKill21-//@version=4+//@version=5strategy("4x ema + volume", overlay=true,initial_capital = 1000, default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_type=strategy.commission.percent , commission_value=0.1 )⋯ema4l=input(180)-ema1=ema(close,ema1l)+ema1=ta.ema(close,ema1l)-ema2=ema(close,ema2l)+ema2=ta.ema(close,ema2l)-ema3=ema(close,ema3l)+ema3=ta.ema(close,ema3l)-ema4=ema(close,ema4l)+ema4=ta.ema(close,ema4l)long1 = close > ema1 and ema1 > ema2 and ema2> ema3 and ema3 > ema4-long2 = crossover(ema1,ema2) and crossover(ema1,ema3)+long2 = ta.crossover(ema1,ema2) and ta.crossover(ema1,ema3)short1 = close < ema1 and ema1 < ema2 and ema2< ema3 and ema3 < ema4-short2= crossunder(ema1,ema2) and crossunder(ema1,ema3)+short2= ta.crossunder(ema1,ema2) and ta.crossunder(ema1,ema3)//eom⋯div = input(10000, title="Divisor", minval=1)-eom = sma(div * change(hl2) * (high - low) / volume, length)+eom = ta.sma(div * ta.change(hl2) * (high - low) / volume, length)option1=input(true)⋯if(option1)- strategy.entry("long",1,when=long1 and eom>0)+ strategy.entry("long",strategy.long,when=long1 and eom>0) strategy.close("long",when=short1 and eom<0)⋯if(option2)- strategy.entry("long",1,when=long2 and eom>0)+ strategy.entry("long",strategy.long,when=long2 and eom>0) strategy.close("long",when=short2 and eom<0)Same 3 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 6: input() → input.int()
- Line 7: input() → input.int()
- Line 8: input() → input.int()
- Line 9: input() → input.int()
- Line 19: input() → input.int()
- Line 20: input() → input.int()
6 more edits
- Line 22: input() → input.bool()
- Line 23: input() → input.bool()
- Line 25: when = long1 and eom>0 → if block
- Line 26: when = short1 and eom<0 → if block
- Line 29: when = long2 and eom>0 → if block
- Line 30: when = short2 and eom<0 → if block
⋯//ema x 4-ema1l=input(13)+ema1l=input.int(13)-ema2l=input(21)+ema2l=input.int(21)-ema3l=input(50)+ema3l=input.int(50)-ema4l=input(180)+ema4l=input.int(180)ema1=ta.ema(close,ema1l)⋯//eom-length = input(14, minval=1)+length = input.int(14, minval=1)-div = input(10000, title="Divisor", minval=1)+div = input.int(10000, title="Divisor", minval=1)eom = ta.sma(div * ta.change(hl2) * (high - low) / volume, length)-option1=input(true)+option1=input.bool(true)-option2=input(false)+option2=input.bool(false)if(option1)- strategy.entry("long",strategy.long,when=long1 and eom>0)+ if long1 and eom>0+ strategy.entry("long",strategy.long)- strategy.close("long",when=short1 and eom<0)+ if short1 and eom<0+ strategy.close("long") if(option2)- strategy.entry("long",strategy.long,when=long2 and eom>0)+ if long2 and eom>0+ strategy.entry("long",strategy.long)- strategy.close("long",when=short2 and eom<0)+ if short2 and eom<0+ strategy.close("long")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: 3 before, 4 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.
⋯// © SoftKill21-//@version=5+//@version=6strategy("4x ema + volume", overlay=true,initial_capital = 1000, default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_type=strategy.commission.percent , commission_value=0.1 )⋯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 |
|---|---|---|---|
| Ema1l (no label in the script) | 13 | int | ema1 |
| Ema2l (no label in the script) | 21 | int | ema2 |
| Ema3l (no label in the script) | 50 | int | ema3 |
| Ema4l (no label in the script) | 180 | int | ema4 |
| Length (no label in the script) | 14 | int · min 1 | eom |
| Divisor | 10000 | int · min 1 | eom |
| Option1 (no label in the script) | true | bool | entry long close long line 24 |
| Option2 (no label in the script) | false | bool | entry long close long line 28 |
What it calculates
- EMA (
ema,ta.emain v5)close, Ema1l (13)ema1 · line 10 - EMA (
ema,ta.emain v5)close, Ema2l (21)ema2 · line 11 - EMA (
ema,ta.emain v5)close, Ema3l (50)ema3 · line 12 - EMA (
ema,ta.emain v5)close, Ema4l (180)ema4 · line 13 - SMA / Change (
sma,ta.smain v5)div * change(hl2) * (high - low) / volume, Length (14)eom · line 21
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 and eom>0 | On | 25 |
| Close long | short1 and eom<0 | On | 26 |
| Open long long | long2 and eom>0 | On | 29 |
| Close long | short2 and eom<0 | On | 30 |
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.
- 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 | +1.8% | +102.5% | 3 | 67% | 1.14 | 25.8% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +12.2% | +5.5% | 3 | 33% | 3.24 | 6.4% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | −18.2% | +9.8% | 2 | 50% | 0.23 | 37.5% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +36.2% | +8.4% | 1 | 100% | — | 2.5% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | −53.7% | +16.7% | 3 | 0% | 0.00 | 57.3% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +28.8% | +21.5% | 2 | 50% | 4.40 | 11.2% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +12.3% | +148.3% | 2 | 50% | 4.63 | 12.2% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +24.2% | +17.1% | 1 | 100% | — | 2.1% | 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 | 0 | — | $0.00 |
| Sideways market | 3 | 67% | $19.08 |
| Falling market | 0 | — | $0.00 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
12.9%
The 95th percentile of the worst drawdown when the same 3 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 12.9% to 12.9%; the tick is what actually happened, 12.9%. Order luck alone moves it this much.
All 3 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 24 Jul 2024 65,936.00 | 16 Aug 2024 57,541.10 | 23 | −$129.06 |
| long | 15 Oct 2024 66,084.00 | 9 Apr 2025 76,322.40 | 176 | $132.93 |
| long | 25 Apr 2025 93,980.50 | 16 Nov 2025 95,596.20 | 205 | $15.22 |
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 |
|---|---|---|---|---|---|
| 4X EMA and volume strategy this page | — | v4 strategy | +1.8% | 3 | 25.8% |
| MACD Long Strat by TheGrindToday | ema sma | v4 strategy | +24.0% | 79 | 20.1% |
| Stock trending strategy by exlux99 | ema sma | v4 strategy | +35.3% | 21 | 14.7% |
| 4-Hour Stochastic EMA Trend by slymnturkoglu | ema sma | v4 strategy | No trades on this market | ||
| Simple Momentum Strategy Based on SMA, EMA and Volume by slip_stream | sma ema | v4 strategy | +7.4% | 18 | 27.4% |
| BTC WaveTrend R-R=1-1.5 by TrendCrypto2022 | ema sma | v5 strategy | +0.2% | 28 | 2.7% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 14 ms | With a workaround 1,000 bars in 32 ms | Not measured |
| PineTS | No v5 and v6 only | — | Not measured |
Zeal Terminal's engine currently reads an order side written as 1 as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (lines 25, 29) so the engine trades the way the script says.
“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. PineTS runs Pine Script v5 and v6 only.
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/// © SoftKill21//@version=4strategy("4x ema + volume", overlay=true,initial_capital = 1000, default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_type=strategy.commission.percent , commission_value=0.1 )//ema x 4ema1l=input(13)ema2l=input(21)ema3l=input(50)ema4l=input(180)ema1=ema(close,ema1l)ema2=ema(close,ema2l)ema3=ema(close,ema3l)ema4=ema(close,ema4l)long1 = close > ema1 and ema1 > ema2 and ema2> ema3 and ema3 > ema4long2 = crossover(ema1,ema2) and crossover(ema1,ema3)short1 = close < ema1 and ema1 < ema2 and ema2< ema3 and ema3 < ema4short2= crossunder(ema1,ema2) and crossunder(ema1,ema3)//eomlength = input(14, minval=1)div = input(10000, title="Divisor", minval=1)eom = sma(div * change(hl2) * (high - low) / volume, length)option1=input(true)option2=input(false)if(option1) strategy.entry("long",1,when=long1 and eom>0) strategy.close("long",when=short1 and eom<0) if(option2) strategy.entry("long",1,when=long2 and eom>0) strategy.close("long",when=short2 and eom<0)