Pine Script v4 · Strategy
Simple way to BEAT the market [STRATEGY]
A Pine Script v4 strategy built on Stdev (close / close[1], 10). 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 commits 100% of equity and pays no commission. 2 settings; defaults include Upper percentile filter (Do not trade above this number) 95 and Lookback period 100.
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 Simple way to BEAT the market [STRATEGY] repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 5 of 5 trades.
- How did Simple way to BEAT the market [STRATEGY] do on BTCUSDT 1D with default settings?
- +193.53%
- From 26 Jan 2024 to 21 Oct 2026, over 15 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Can Simple way to BEAT the market [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 Simple way to BEAT the market [STRATEGY] use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
- Does Simple way to BEAT the market [STRATEGY] run in Zeal Terminal?
- Yes
- It compiles in 6 ms and runs 1,000 bars in 32 ms, in the browser.
BTCUSDT · 1D · default settings
- Stdev
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- +193.53%
- $193,531.00
- Buy and hold
- +102.5%
- same period
- Closed trades
- 15
- 9 won · 6 lost
- Profitable
- 60.0%
- of closed trades
- Profit factor
- 2.28
- gross profit ÷ gross loss
- Max drawdown
- 39.17%
- −$141,552.00
One run with the author's default settings, $100,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
No commission
The backtest assumes free trading. Results on any real exchange will be lower.
-
Check
Every trade uses all the equity
default_qty_value is 100% of equity.
-
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 stdev → ta.stdev, log → math.log, sqrt → math.sqrt, percentile_nearest_rank → ta.percentile_nearest_rank.
Same 15 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 13: //@version=4 → //@version=5
- Line 15: input(type = input.integer) → input.int()
- Line 16: input(type = input.integer) → input.int()
- Line 19: stdev → ta.stdev
- Line 19: log → math.log
- Line 19: sqrt → math.sqrt
- Line 20: percentile_nearest_rank → ta.percentile_nearest_rank
⋯//-//@version=4+//@version=5strategy(title = "Simple way to beat the market [STRATEGY]", shorttitle = "Beat The Market [STRATEGY]", overlay=true, initial_capital=100000, default_qty_type=strategy.percent_of_equity, currency="USD", default_qty_value=100)-upperExtreme = input(title = "Upper percentile filter (Do not trade above this number)", type = input.integer, defval = 95)+upperExtreme = input.int(title = "Upper percentile filter (Do not trade above this number)", defval = 95)-lookbackPeriod = input(title = "Lookback period", type = input.integer, defval = 100)+lookbackPeriod = input.int(title = "Lookback period", defval = 100)annual = 365per = timeframe.isintraday or timeframe.isdaily and timeframe.multiplier == 1 ? 1 : 7-hv = lookbackPeriod * stdev(log(close / close[1]), 10) * sqrt(annual / per)+hv = lookbackPeriod * ta.stdev(math.log(close / close[1]), 10) * math.sqrt(annual / per)-filtered = hv >= percentile_nearest_rank(hv, 100, upperExtreme)+filtered = hv >= ta.percentile_nearest_rank(hv, 100, upperExtreme)if(not(filtered))⋯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: 15 before, 14 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=6strategy(title = "Simple way to beat the market [STRATEGY]", shorttitle = "Beat The Market [STRATEGY]", overlay=true, initial_capital=100000, default_qty_type=strategy.percent_of_equity, currency="USD", default_qty_value=100)⋯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 |
|---|---|---|---|
| Upper percentile filter (Do not trade above this number) | 95 | int (written input.integer) | filtered |
| Lookback period | 100 | int (written input.integer) | hv |
What it calculates
- Stdev (
stdev,ta.stdevin v5)log(close / close[1]), 10hv · line 19
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 | (not(filtered)) | On | 22 |
| Close LONG | (not(filtered)) | On | 24 |
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 | +193.5% | +102.5% | 15 | 60% | 2.28 | 39.2% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +3.1% | +5.5% | 16 | 56% | 1.11 | 20.2% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +68.3% | +9.8% | 11 | 55% | 1.33 | 59.1% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +2.1% | +8.4% | 13 | 54% | 1.05 | 27.7% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +54.9% | +16.7% | 19 | 63% | 1.14 | 71.9% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +9.0% | +21.5% | 19 | 53% | 1.21 | 25.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +209.0% | +148.3% | 11 | 82% | 2.30 | 42.4% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +1.3% | +17.1% | 15 | 53% | 1.04 | 22.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 | 10 | 60% | $136,499.00 |
| Falling market | 5 | 60% | $57,032.10 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
35.1%
The 95th percentile of the worst drawdown when the same 15 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 19.2% to 35.1%; the tick is what actually happened, 33.1%. Order luck alone moves it this much.
All 15 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 27 Jan 2024 41,823.50 | 9 Aug 2024 61,686.00 | 195 | $47,491.20 |
| long | 15 Aug 2024 58,683.40 | 3 Mar 2025 94,270.00 | 200 | $89,441.20 |
| long | 13 Mar 2025 83,680.10 | 23 Aug 2025 116,936.00 | 163 | $94,160.90 |
| long | 25 Aug 2025 113,494.00 | 27 Aug 2025 111,763.00 | 2 | −$5,047.98 |
| long | 28 Aug 2025 111,262.00 | 29 Aug 2025 112,567.00 | 1 | $3,823.89 |
| long | 1 Sep 2025 108,246.00 | 2 Oct 2025 118,595.00 | 31 | $31,536.30 |
| long | 3 Oct 2025 120,529.00 | 11 Oct 2025 112,774.00 | 8 | −$23,252.80 |
| long | 18 Oct 2025 106,432.00 | 20 Oct 2025 108,643.00 | 2 | $7,025.03 |
| long | 21 Oct 2025 110,532.00 | 6 Dec 2025 89,330.00 | 46 | −$66,211.30 |
| long | 7 Dec 2025 89,236.80 | 1 Feb 2026 78,741.10 | 56 | −$32,811.00 |
| long | 2 Feb 2026 76,968.20 | 3 Feb 2026 78,738.60 | 1 | $5,661.93 |
| long | 13 Feb 2026 66,272.20 | 14 Feb 2026 68,854.00 | 1 | $9,810.18 |
| long | 16 Feb 2026 68,832.60 | 12 Jun 2026 63,626.00 | 116 | −$19,789.90 |
| long | 13 Jun 2026 63,580.00 | 22 Aug 2026 78,338.00 | 70 | $56,134.70 |
| long | 27 Aug 2026 79,023.80 | 29 Aug 2026 77,845.90 | 2 | −$4,441.36 |
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 |
|---|---|---|---|---|---|
| Simple way to BEAT the market [STRATEGY] this page | — | v4 strategy | +193.5% | 15 | 39.2% |
| Crypto RSI with RVI Strategy by exlux99 | stdev | v4 strategy | +4.0% | 2 | 32.1% |
| Portfolio Performance - 2 Assets by Skywalking2874 | stdev | v5 strategy | No trades on this market | ||
| Historical Volatility by Zeal Terminal | stdev | v5 indicator | indicator | ||
| Double Bollinger Binary Options by Trade_by_DB | stdev | v5 strategy | No trades on this market | ||
| Improved Bollinger Swing Strategy Stock Nasdaq by exlux99 | stdev | v4 strategy | −20.4% | 7 | 22.3% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 6 ms | With a workaround 1,000 bars in 32 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.
// 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 script has been created to demonstrate the effectiveness of using market regime filters in your trading strategy, and how they can improve your returns and lower your drawdowns//// This strategy adds a simple filter (The historical volatility filter, which can be found on my trading profile) to a traditional buy and hold strategy of the index SPY. There are other filters// that could also be added included a long term moving average / percentile rank filter / ADX filter etc, to improve the returns further.//// Feel free to use some of the market filters in my trading profile to improve and refine your strategies further, or make a copy and play around with the code yourself. This is just // a simple example for demo purposes.////@version=4strategy(title = "Simple way to beat the market [STRATEGY]", shorttitle = "Beat The Market [STRATEGY]", overlay=true, initial_capital=100000, default_qty_type=strategy.percent_of_equity, currency="USD", default_qty_value=100)upperExtreme = input(title = "Upper percentile filter (Do not trade above this number)", type = input.integer, defval = 95)lookbackPeriod = input(title = "Lookback period", type = input.integer, defval = 100)annual = 365per = timeframe.isintraday or timeframe.isdaily and timeframe.multiplier == 1 ? 1 : 7hv = lookbackPeriod * stdev(log(close / close[1]), 10) * sqrt(annual / per)filtered = hv >= percentile_nearest_rank(hv, 100, upperExtreme)if(not(filtered)) strategy.entry("LONG", strategy.long)else strategy.close("LONG")