Pine Script v4 · Strategy
Jaws Mean Reversion [Strategy]
A Pine Script v4 strategy built on SMA (close, 2). It has 2 order rules, 1 entry among them, and trades long only with the default settings. Exits wait for a signal; there is no stop loss. Each trade is one contract and pays no commission. 4 settings; defaults include Source close, Small Moving Average 2 and Big Moving Average 8.
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 Jaws Mean Reversion [Strategy] repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 17 of 17 trades.
- How did Jaws Mean Reversion [Strategy] do on BTCUSDT 1D with default settings?
- +29.18%
- From 26 Jan 2024 to 21 Oct 2026, over 57 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Can Jaws Mean Reversion [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 Jaws Mean Reversion [Strategy] use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
- Does Jaws Mean Reversion [Strategy] run in Zeal Terminal?
- Yes
- It compiles in 9 ms and runs 1,000 bars in 15 ms, in the browser.
BTCUSDT · 1D · default settings
- SMA
- SMA
- SMA
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- +29.18%
- $29,175.00
- Buy and hold
- +102.5%
- same period
- Closed trades
- 57
- 40 won · 17 lost
- Profitable
- 70.2%
- of closed trades
- Profit factor
- 1.43
- gross profit ÷ gross loss
- Max drawdown
- 20.91%
- −$30,338.20
One run with the author's default settings, $100,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 stop loss
Every exit waits for a signal. Nothing limits a losing trade before the exit condition fires.
-
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.
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 sma → ta.sma, crossunder → ta.crossunder, crossover → ta.crossover.
v4 → v5
VerifiedSame 57 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 1: //@version=4 → //@version=5
- Line 19: sma → ta.sma
- Line 20: sma → ta.sma
- Line 21: sma → ta.sma
- Line 22: crossunder → ta.crossunder
- Line 24: crossover → ta.crossover
-// @version=4+// @version=5//⋯//Strategy calculation-smallMA = sma(source, smallMAPeriod)+smallMA = ta.sma(source, smallMAPeriod)-bigMA = sma(source, bigMAPeriod) +bigMA = ta.sma(source, bigMAPeriod) -buyMA = ((100 - percentBelowToBuy) / 100) * sma(source, bigMAPeriod)[0]+buyMA = ((100 - percentBelowToBuy) / 100) * ta.sma(source, bigMAPeriod)[0]-if(crossunder(smallMA, buyMA))+if(ta.crossunder(smallMA, buyMA)) strategy.entry("BUY", strategy.long)-if(crossover(smallMA, bigMA))+if(ta.crossover(smallMA, bigMA)) strategy.close("BUY")Same 57 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 14: input() → input.source()
- Line 15: input() → input.int()
- Line 16: input() → input.int()
- Line 17: input() → input.int()
⋯//Strategy inputs-source = input(title = "Source", defval = close)+source = input.source(title = "Source", defval = close)-smallMAPeriod = input(title = "Small Moving Average", defval = 2)+smallMAPeriod = input.int(title = "Small Moving Average", defval = 2)-bigMAPeriod = input(title = "Big Moving Average", defval = 8)+bigMAPeriod = input.int(title = "Big Moving Average", defval = 8)-percentBelowToBuy = input(title = "Percent below to buy %", defval = 1)+percentBelowToBuy = input.int(title = "Percent below to buy %", defval = 1)//Strategy calculation⋯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: 57 before, 46 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.
-// @version=5+// @version=6//⋯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 |
|---|---|---|---|
| Source | close | source | smallMA bigMA buyMA |
| Small Moving Average | 2 | int | smallMA |
| Big Moving Average | 8 | int | bigMA buyMA |
| Percent below to buy % | 1 | int | buyMA |
What it calculates
- SMA (
sma,ta.smain v5)Source (close), Small Moving Average (2)smallMA · line 19 - SMA (
sma,ta.smain v5)Source (close), Big Moving Average (8)bigMA · line 20 - SMA (
sma,ta.smain v5)Source (close), Big Moving Average (8)buyMA · 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 BUY long | (crossunder(smallMA, buyMA)) | On | 23 |
| Close BUY | (crossover(smallMA, bigMA)) | On | 25 |
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 | +29.2% | +102.5% | 57 | 70% | 1.43 | 20.9% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +1.8% | +5.5% | 30 | 70% | 1.11 | 14.4% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | −0.7% | +9.8% | 60 | 60% | 0.87 | 1.8% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +0.0% | +8.4% | 38 | 63% | 1.02 | 0.5% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | −0.1% | +16.7% | 63 | 52% | 0.70 | 0.1% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +0.0% | +21.5% | 45 | 76% | 1.40 | 0.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +0.4% | +148.3% | 53 | 68% | 1.56 | 0.3% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | −0.0% | +17.1% | 26 | 77% | 0.81 | 0.2% | 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 | 21 | 81% | $42,877.60 |
| Sideways market | 19 | 58% | −$9,639.37 |
| Falling market | 17 | 71% | −$4,063.28 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
23.1%
The 95th percentile of the worst drawdown when the same 57 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 10.6% to 23.1%; the tick is what actually happened, 16.2%. Order luck alone moves it this much.
All 57 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 24 Feb 2024 50,744.20 | 27 Feb 2024 54,476.50 | 3 | $3,732.33 |
| long | 17 Mar 2024 65,300.60 | 26 Mar 2024 69,880.00 | 9 | $4,579.36 |
| long | 3 Apr 2024 65,464.00 | 8 Apr 2024 69,360.40 | 5 | $3,896.39 |
| long | 13 Apr 2024 67,116.50 | 21 Apr 2024 64,940.60 | 8 | −$2,175.94 |
| long | 27 Apr 2024 63,770.00 | 5 May 2024 63,892.00 | 8 | $122.03 |
| long | 11 May 2024 60,800.00 | 14 May 2024 62,940.10 | 3 | $2,140.10 |
| long | 2 Jun 2024 67,766.80 | 4 Jun 2024 68,809.90 | 2 | $1,043.05 |
| long | 12 Jun 2024 67,314.20 | 1 Jul 2024 62,772.00 | 19 | −$4,542.22 |
| long | 5 Jul 2024 57,050.00 | 11 Jul 2024 57,725.80 | 6 | $675.83 |
| long | 26 Jul 2024 65,799.90 | 27 Jul 2024 67,908.00 | 1 | $2,108.05 |
| long | 1 Aug 2024 64,628.00 | 10 Aug 2024 60,838.00 | 9 | −$3,790.02 |
| long | 16 Aug 2024 57,541.10 | 19 Aug 2024 58,427.30 | 3 | $886.30 |
| long | 28 Aug 2024 59,415.00 | 11 Sep 2024 57,636.00 | 14 | −$1,779.01 |
| long | 2 Oct 2024 60,804.90 | 7 Oct 2024 62,819.90 | 5 | $2,014.99 |
| long | 11 Oct 2024 60,326.40 | 13 Oct 2024 63,206.20 | 2 | $2,879.83 |
| long | 24 Oct 2024 66,668.60 | 29 Oct 2024 69,962.20 | 5 | $3,293.56 |
| long | 4 Nov 2024 68,776.00 | 7 Nov 2024 75,572.00 | 3 | $6,796.00 |
| long | 27 Nov 2024 91,965.20 | 30 Nov 2024 97,460.00 | 3 | $5,494.84 |
| long | 11 Dec 2024 96,593.00 | 13 Dec 2024 100,004.00 | 2 | $3,411.29 |
| long | 20 Dec 2024 97,461.90 | 26 Dec 2024 99,429.60 | 6 | $1,967.75 |
| long | 28 Dec 2024 94,299.00 | 3 Jan 2025 96,984.80 | 6 | $2,685.76 |
| long | 9 Jan 2025 95,060.60 | 15 Jan 2025 96,560.90 | 6 | $1,500.24 |
| long | 28 Jan 2025 102,083.00 | 31 Jan 2025 104,723.00 | 3 | $2,640.11 |
| long | 2 Feb 2025 100,636.00 | 13 Feb 2025 97,870.00 | 11 | −$2,765.66 |
| long | 25 Feb 2025 91,552.90 | 3 Mar 2025 94,270.00 | 6 | $2,717.11 |
| long | 9 Mar 2025 86,222.50 | 16 Mar 2025 84,338.40 | 7 | −$1,884.02 |
| long | 30 Mar 2025 82,648.50 | 5 Apr 2025 83,889.90 | 6 | $1,241.34 |
| long | 7 Apr 2025 78,430.00 | 11 Apr 2025 79,607.30 | 4 | $1,177.30 |
| long | 30 May 2025 105,590.00 | 8 Jun 2025 105,552.00 | 9 | −$37.60 |
| long | 14 Jun 2025 106,067.00 | 25 Jun 2025 106,083.00 | 11 | $16.41 |
| long | 2 Aug 2025 113,298.00 | 8 Aug 2025 117,472.00 | 6 | $4,174.10 |
| long | 17 Aug 2025 117,381.00 | 24 Aug 2025 115,438.00 | 7 | −$1,942.60 |
| long | 26 Aug 2025 110,112.00 | 3 Sep 2025 111,240.00 | 8 | $1,128.03 |
| long | 23 Sep 2025 112,651.00 | 30 Sep 2025 114,312.00 | 7 | $1,660.98 |
| long | 11 Oct 2025 112,774.00 | 22 Oct 2025 108,298.00 | 11 | −$4,476.83 |
| long | 31 Oct 2025 108,323.00 | 11 Nov 2025 106,011.00 | 11 | −$2,311.74 |
| long | 14 Nov 2025 99,692.00 | 27 Nov 2025 90,484.00 | 13 | −$9,208.02 |
| long | 2 Dec 2025 86,286.00 | 4 Dec 2025 93,429.90 | 2 | $7,143.94 |
| long | 7 Dec 2025 89,236.80 | 9 Dec 2025 90,634.40 | 2 | $1,397.55 |
| long | 15 Dec 2025 88,172.20 | 21 Dec 2025 88,360.90 | 6 | $188.75 |
| long | 11 Jan 2026 90,504.70 | 14 Jan 2026 95,414.00 | 3 | $4,909.29 |
| long | 20 Jan 2026 92,631.00 | 29 Jan 2026 89,300.00 | 9 | −$3,330.99 |
| long | 30 Jan 2026 84,650.20 | 15 Feb 2026 69,822.90 | 16 | −$14,827.20 |
| long | 19 Feb 2026 66,461.00 | 23 Feb 2026 67,643.40 | 4 | $1,182.39 |
| long | 24 Feb 2026 64,656.00 | 27 Feb 2026 67,485.20 | 3 | $2,829.18 |
| long | 8 Mar 2026 67,262.90 | 11 Mar 2026 69,948.60 | 3 | $2,685.73 |
| long | 20 Mar 2026 69,930.00 | 25 Mar 2026 70,556.70 | 5 | $626.73 |
| long | 28 Mar 2026 66,407.30 | 2 Apr 2026 68,113.90 | 5 | $1,706.64 |
| long | 30 Apr 2026 75,780.00 | 2 May 2026 78,231.10 | 2 | $2,451.13 |
| long | 14 May 2026 79,313.60 | 26 May 2026 77,322.00 | 12 | −$1,991.60 |
| long | 28 May 2026 74,449.30 | 12 Jun 2026 63,626.00 | 15 | −$10,823.30 |
| long | 19 Jun 2026 62,958.00 | 3 Jul 2026 61,560.00 | 14 | −$1,398.01 |
| long | 26 Jul 2026 64,375.00 | 5 Aug 2026 64,106.60 | 10 | −$268.46 |
| long | 12 Aug 2026 63,600.00 | 18 Aug 2026 64,532.10 | 6 | $932.10 |
| long | 3 Sep 2026 77,340.00 | 4 Sep 2026 81,270.40 | 1 | $3,930.36 |
| long | 10 Sep 2026 78,306.40 | 19 Sep 2026 80,883.90 | 9 | $2,577.43 |
| long | 9 Oct 2026 81,754.50 | 20 Oct 2026 81,938.40 | 11 | $183.93 |
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 |
|---|---|---|---|---|---|
| Jaws Mean Reversion [Strategy] this page | — | v4 strategy | +29.2% | 57 | 20.9% |
| 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% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 9 ms | With a workaround 1,000 bars in 15 ms | Not measured |
| PineTS | No v5 and v6 only | — | Not measured |
The engine's host API cannot yet declare a chart's symbol and timeframe, so this page sets them on the engine directly for each market.
“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.
// @version=4//// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0///// @author Sunil Halai//// This very simple strategy is an implementation of PJ Sutherlands' Jaws Mean reversion algorithm. It simply buys when a small moving average period (e.g. 2) is below// a longer moving average period (e.g. 8) by a certain percentage, and closes when the small period average crosses over the longer moving average. // // If you are going to use this, you may wish to apply this to a range of investment assets, as the amount signals is low. Alternatively you may wish to tweak the settings to provide more// signals.strategy("Jaws Mean Reversion [Strategy]", overlay = true)//Strategy inputssource = input(title = "Source", defval = close)smallMAPeriod = input(title = "Small Moving Average", defval = 2)bigMAPeriod = input(title = "Big Moving Average", defval = 8)percentBelowToBuy = input(title = "Percent below to buy %", defval = 1)//Strategy calculationsmallMA = sma(source, smallMAPeriod)bigMA = sma(source, bigMAPeriod) buyMA = ((100 - percentBelowToBuy) / 100) * sma(source, bigMAPeriod)[0]if(crossunder(smallMA, buyMA)) strategy.entry("BUY", strategy.long)if(crossover(smallMA, bigMA)) strategy.close("BUY")