Pine Script v5 · Strategy
MA Cross Strategy
A Pine Script v5 strategy built on SMA (close, 10). It has 3 order rules, 2 entries among them, and trades long and short with the default settings. Exits wait for a signal; there is no stop loss. Each trade is one contract and pays 0.05% commission. 3 settings; defaults include Fast 10 and Slow 30.
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 MA Cross Strategy repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 11 of 11 trades.
- How did MA Cross Strategy do on BTCUSDT 1D with default settings?
- −439.77%
- From 26 Jan 2024 to 21 Oct 2026, over 40 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Does MA Cross Strategy 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: 40 before, 41 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 MA Cross Strategy use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
- Does MA Cross Strategy run in Zeal Terminal?
- Yes
- It compiles in 10 ms and runs 1,000 bars in 20 ms, in the browser.
BTCUSDT · 1D · default settings
- Fast
- Slow
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- −439.77%
- −$43,977.50
- Buy and hold
- +102.5%
- same period
- Closed trades
- 40
- 10 won · 30 lost
- Profitable
- 25.0%
- of closed trades
- Profit factor
- 0.74
- gross profit ÷ gross loss
- Max drawdown
- 541.19%
- −$54,119.30
One run with the author's default settings, $10,000 starting capital, commission as the script sets it. A short 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.
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 |
|---|---|---|---|
| Fast | 10 | int · min 1 | maFast |
| Slow | 30 | int · min 1 | maSlow |
| Trade the short side | true | bool | entry Short close Long line 24 |
What it calculates
- SMAclose, Fast (10)
maFast · line 14 - SMAclose, Slow (30)
maSlow · line 15
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 | ta.crossover(maFast, maSlow) | On | 21 |
| Open Short short | allowShorts | On “Trade the short side” | 25 |
| Close Long | allowShorts | On “Trade the short side” | 27 |
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 | −439.8% | +102.5% | 40 | 25% | 0.74 | 541.2% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | −97.2% | +5.5% | 39 | 31% | 0.78 | 104.9% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +14.2% | +9.8% | 36 | 36% | 1.24 | 19.4% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +0.2% | +8.4% | 40 | 30% | 1.01 | 6.1% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +0.8% | +16.7% | 34 | 44% | 1.25 | 1.8% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +0.4% | +21.5% | 35 | 40% | 1.79 | 0.2% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | −0.5% | +148.3% | 36 | 22% | 0.96 | 9.0% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | −0.5% | +17.1% | 43 | 37% | 0.87 | 1.4% | 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 | 12 | 17% | −$31,175.90 |
| Sideways market | 18 | 28% | −$9,554.08 |
| Falling market | 10 | 30% | −$3,206.38 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
22,987.6%
The 95th percentile of the worst drawdown when the same 40 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 105.3% to 22,987.6%; the tick is what actually happened, 501.6%. Order luck alone moves it this much.
All 40 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| short | 17 Apr 2024 63,793.40 | 19 May 2024 66,915.20 | 32 | −$3,187.17 |
| long | 19 May 2024 66,915.20 | 16 Jun 2024 66,228.20 | 28 | −$753.54 |
| short | 16 Jun 2024 66,228.20 | 20 Jul 2024 66,660.00 | 34 | −$498.22 |
| long | 20 Jul 2024 66,660.00 | 7 Aug 2024 56,022.00 | 18 | −$10,699.40 |
| short | 7 Aug 2024 56,022.00 | 27 Aug 2024 62,834.00 | 20 | −$6,871.45 |
| long | 27 Aug 2024 62,834.00 | 5 Sep 2024 57,970.90 | 9 | −$4,923.52 |
| short | 5 Sep 2024 57,970.90 | 20 Sep 2024 62,948.00 | 15 | −$5,037.58 |
| long | 20 Sep 2024 62,948.00 | 10 Oct 2024 60,636.00 | 20 | −$2,373.80 |
| short | 10 Oct 2024 60,636.00 | 16 Oct 2024 67,074.10 | 6 | −$6,502.01 |
| long | 16 Oct 2024 67,074.10 | 27 Dec 2024 95,791.60 | 72 | $28,636.00 |
| short | 27 Dec 2024 95,791.60 | 18 Jan 2025 104,077.00 | 22 | −$8,385.82 |
| long | 18 Jan 2025 104,077.00 | 8 Feb 2025 96,506.80 | 21 | −$7,670.98 |
| short | 8 Feb 2025 96,506.80 | 28 Mar 2025 87,232.00 | 48 | $9,182.90 |
| long | 28 Mar 2025 87,232.00 | 4 Apr 2025 83,213.10 | 7 | −$4,104.16 |
| short | 4 Apr 2025 83,213.10 | 19 Apr 2025 84,474.70 | 15 | −$1,345.47 |
| long | 19 Apr 2025 84,474.70 | 7 Jun 2025 104,288.00 | 49 | $19,719.30 |
| short | 7 Jun 2025 104,288.00 | 16 Jun 2025 105,594.00 | 9 | −$1,410.55 |
| long | 16 Jun 2025 105,594.00 | 20 Jun 2025 104,659.00 | 4 | −$1,040.58 |
| short | 20 Jun 2025 104,659.00 | 1 Jul 2025 107,147.00 | 11 | −$2,593.84 |
| long | 1 Jul 2025 107,147.00 | 5 Aug 2025 115,055.00 | 35 | $7,797.40 |
| short | 5 Aug 2025 115,055.00 | 14 Aug 2025 123,306.00 | 9 | −$8,370.61 |
| long | 14 Aug 2025 123,306.00 | 23 Aug 2025 116,936.00 | 9 | −$6,490.58 |
| short | 23 Aug 2025 116,936.00 | 15 Sep 2025 115,268.00 | 23 | $1,551.87 |
| long | 15 Sep 2025 115,268.00 | 29 Sep 2025 112,164.00 | 14 | −$3,217.79 |
| short | 29 Sep 2025 112,164.00 | 4 Oct 2025 122,232.00 | 5 | −$10,185.50 |
| long | 4 Oct 2025 122,232.00 | 17 Oct 2025 108,194.00 | 13 | −$14,153.20 |
| short | 17 Oct 2025 108,194.00 | 12 Dec 2025 92,513.40 | 56 | $15,580.50 |
| long | 12 Dec 2025 92,513.40 | 19 Dec 2025 85,516.40 | 7 | −$7,086.00 |
| short | 19 Dec 2025 85,516.40 | 6 Jan 2026 93,859.70 | 18 | −$8,433.01 |
| long | 6 Jan 2026 93,859.70 | 26 Jan 2026 86,670.40 | 20 | −$7,279.64 |
| short | 26 Jan 2026 86,670.40 | 7 Mar 2026 68,114.00 | 40 | $18,478.90 |
| long | 7 Mar 2026 68,114.00 | 29 Mar 2026 66,377.00 | 22 | −$1,804.25 |
| short | 29 Mar 2026 66,377.00 | 12 Apr 2026 73,043.20 | 14 | −$6,735.85 |
| long | 12 Apr 2026 73,043.20 | 22 May 2026 77,615.50 | 40 | $4,497.01 |
| short | 22 May 2026 77,615.50 | 11 Jul 2026 64,161.70 | 50 | $13,382.90 |
| long | 11 Jul 2026 64,161.70 | 3 Aug 2026 63,570.00 | 23 | −$655.60 |
| short | 3 Aug 2026 63,570.00 | 21 Aug 2026 73,027.00 | 18 | −$9,525.33 |
| long | 21 Aug 2026 73,027.00 | 18 Sep 2026 76,417.00 | 28 | $3,315.25 |
| short | 18 Sep 2026 76,417.00 | 22 Sep 2026 86,620.00 | 4 | −$10,284.50 |
| long | 22 Sep 2026 86,620.00 | 16 Oct 2026 82,245.90 | 24 | −$4,458.53 |
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 |
|---|---|---|---|---|---|
| MA Cross Strategy this page | — | v5 strategy | −439.8% | 40 | 541.2% |
| Follow the Crypto Shorts by xtradernet | sma | v4 strategy | No trades on this market | ||
| buy down and sell high trend 200 sma and ma cross by willi130503 | sma | v4 strategy | No trades on this market | ||
| Mayer Multiple Strategy by xtradernet | sma | v4 strategy | No trades on this market | ||
| Moving Average Cross Strategy early Closing by Geduldtrader | sma | v4 strategy | +73.8% | 20 | 151.5% |
| MFI Simple Strategy by OztheWoz | sma | v5 strategy | −0.2% | 28 | 3.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: 40 before, 41 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.
⋯// © Zeal Terminal-//@version=5+//@version=6strategy("MA Cross Strategy", overlay = true, initial_capital = 10000,⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 10 ms | Yes 1,000 bars in 20 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
Written by Zeal Terminal and published under the Mozilla Public License 2.0.
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/// © Zeal Terminal//@version=5strategy("MA Cross Strategy", overlay = true, initial_capital = 10000, commission_type = strategy.commission.percent, commission_value = 0.05, slippage = 1) // Not investment advice. fast = input.int(10, "Fast", minval = 1)slow = input.int(30, "Slow", minval = 1)allowShorts = input.bool(true, "Trade the short side") maFast = ta.sma(close, fast)maSlow = ta.sma(close, slow) plot(maFast, "Fast", color = color.aqua)plot(maSlow, "Slow", color = color.orange) if ta.crossover(maFast, maSlow) strategy.entry("Long", strategy.long) if ta.crossunder(maFast, maSlow) if allowShorts strategy.entry("Short", strategy.short) else strategy.close("Long")