Pine Script v5 · Strategy
Short Selling EMA Cross (By Coinrule)
A Pine Script v5 strategy built on EMA (close, 20) and Crossunder (fastEMA, slowEMA). It has 2 order rules, 1 entry among them, and trades short only with the default settings. Exits use a stop loss and a profit target. Each trade commits 30% of equity and pays 0.1% commission. It has no settings.
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 Short Selling EMA Cross (By Coinrule) repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 2 of 2 trades.
- How did Short Selling EMA Cross (By Coinrule) do on BTCUSDT 1D with default settings?
- +5.27%
- From 26 Jan 2024 to 21 Oct 2026, over 6 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Does Short Selling EMA Cross (By Coinrule) run in Pine Script v6?
- Yes
- Same 6 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. Both versions were run on Zeal Terminal's engine, and the results are identical. The v6 script can be downloaded below.
- Does Short Selling EMA Cross (By Coinrule) use a stop loss?
- Yes
- strategy.exit sets a stop on line 17.
- Does Short Selling EMA Cross (By Coinrule) run in Zeal Terminal?
- Yes
- It compiles in 9 ms and runs 1,000 bars in 32 ms, in the browser.
BTCUSDT · 1D · default settings
- Plot
- Plot
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- +5.27%
- $526.84
- Buy and hold
- +102.5%
- same period
- Closed trades
- 6
- 5 won · 1 lost
- Profitable
- 83.3%
- of closed trades
- Profit factor
- 1.68
- gross profit ÷ gross loss
- Max drawdown
- 10.00%
- −$1,022.31
One run with the author's default settings, $10,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.
-
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.
The script declares no settings.
What it calculates
- EMAclose, 20
fastEMA · line 6 - EMAclose, 50
slowEMA · line 7 - CrossunderfastEMA, slowEMA
goShortCondition1 · line 9
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 short short | (goShortCondition1 and timePeriod and notInTrade) | On | 16 |
| Exit exit stop and limit | (goShortCondition1 and timePeriod and notInTrade) | On | 17 |
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 | +5.3% | +102.5% | 6 | 83% | 1.68 | 10.0% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | −5.3% | +5.5% | 1 | 0% | 0.00 | 8.6% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +12.1% | +9.8% | 7 | 86% | 2.65 | 10.4% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | −9.8% | +8.4% | 3 | 0% | 0.00 | 14.4% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +3.6% | +16.7% | 10 | 70% | 1.21 | 11.9% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | −11.6% | +21.5% | 4 | 25% | 0.15 | 13.9% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +9.3% | +148.3% | 6 | 83% | 2.47 | 5.5% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | −2.2% | +17.1% | 3 | 67% | 0.70 | 10.9% | 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 | 1 | 100% | $221.00 |
| Sideways market | 4 | 75% | $54.62 |
| Falling market | 1 | 100% | $251.22 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
7.6%
The 95th percentile of the worst drawdown when the same 6 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 7.6% to 7.6%; the tick is what actually happened, 7.6%. Order luck alone moves it this much.
All 6 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| short | 4 May 2024 62,882.00 | 4 Jul 2024 58,124.10 | 61 | $221.00 |
| short | 6 Aug 2024 54,018.80 | 15 Oct 2024 67,634.50 | 70 | −$779.00 |
| short | 18 Feb 2025 95,780.00 | 25 Feb 2025 87,588.60 | 7 | $236.59 |
| short | 30 Aug 2025 108,377.00 | 14 Nov 2025 95,246.00 | 76 | $346.01 |
| short | 21 Jan 2026 88,427.70 | 31 Jan 2026 80,864.30 | 10 | $251.22 |
| short | 1 Jun 2026 73,674.40 | 2 Jun 2026 67,528.00 | 1 | $251.02 |
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 |
|---|---|---|---|---|---|
| Short Selling EMA Cross (By Coinrule) this page | — | v5 strategy | +5.3% | 6 | 10.0% |
| 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?
Yes
Same 6 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. Both versions were run on Zeal Terminal's engine, and the results are identical. It differs from the v5 version by 1 edit.
⋯// © Coinrule-//@version=5+//@version=6strategy("Short Selling EMA Cross (By Coinrule)", overlay=true, initial_capital = 10000, default_qty_value = 30, default_qty_type = strategy.percent_of_equity, commission_type=strategy.commission.percent, commission_value=0.1)⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 9 ms | Yes 1,000 bars in 32 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/// © Coinrule//@version=5strategy("Short Selling EMA Cross (By Coinrule)", overlay=true, initial_capital = 10000, default_qty_value = 30, default_qty_type = strategy.percent_of_equity, commission_type=strategy.commission.percent, commission_value=0.1)// EMAs fastEMA = ta.ema(close, 20)slowEMA = ta.ema(close, 50)// ConditionsgoShortCondition1 = ta.crossunder(fastEMA, slowEMA)timePeriod = time >= timestamp(syminfo.timezone, 2021, 12, 1, 0, 0)notInTrade = strategy.position_size <= 0strategyDirection = strategy.direction.shortif (goShortCondition1 and timePeriod and notInTrade) stopLoss = high * 1.16 takeProfit = low * 0.92 strategy.entry("short", strategy.short) strategy.exit("exit","short", stop=stopLoss, limit=takeProfit) plot(fastEMA, color=color.blue)plot(slowEMA, color=color.yellow)