Zeal Terminal Open in Zeal Terminal

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
Prerendered with the defaults. Change anything and run it here. The script runs in your browser.
Settings (2)
0.0050,000100,000AprJulOct2025AprJulOct2026AprJulOct$317,854$202,527Equity from $100,000
Binance BTCUSDT 1D candles, 26 Jan 2024 to 21 Oct 2026, 1,000 bars, default settings. Triangles mark entries; circles mark exits. The script plots nothing itself; the lines and the lower pane are its own calculations, drawn for reference. 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.
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.

v4 → v5

VerifiedDownload the v5 script

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

Verified

Nothing 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.

SettingDefaultType and rangeFeeds
Upper percentile filter (Do not trade above this number)95int (written input.integer)filtered
Lookback period100int (written input.integer)hv

What it calculates

  • Stdev (stdev, ta.stdev in 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.

closecloseprice datalookbackPeriodLookback periodsetting · 100upperExtremeUpper percentile filter…setting · 95hvStdev→ hvperpervaluefilteredfilteredconditionentry:LONGOpen LONGstrategy.entryclose:LONGClose LONGstrategy.close

Order rules

OrderFires whenBy defaultLine
Open LONG long(not(filtered))On22
Close LONG(not(filtered))On24

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.

5/5trades identical when replayed liveThe last 300 bars, from 26 Dec 2025, were fed to the engine as live ticks, four per bar, and compared with the historical run. Orders are decided once per closed bar, so nothing can change mid-bar.
  • 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.

MarketNetBuy and holdTradesWonProfit factorMax drawdownPeriod
BTCUSDT 1D+193.5%+102.5%1560%2.2839.2%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+3.1%+5.5%1656%1.1120.2%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+68.3%+9.8%1155%1.3359.1%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+2.1%+8.4%1354%1.0527.7%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+54.9%+16.7%1963%1.1471.9%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+9.0%+21.5%1953%1.2125.0%8 May 2026 – 21 Oct 2026
BNBUSDT 1D+209.0%+148.3%1182%2.3042.4%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+1.3%+17.1%1553%1.0422.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 barsTradesWonP&L
Rising market0—$0.00
Sideways market1060%$136,499.00
Falling market560%$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.

0%40%
All 15 trades
SideEntryExitBarsP&L
long27 Jan 2024 41,823.509 Aug 2024 61,686.00195$47,491.20
long15 Aug 2024 58,683.403 Mar 2025 94,270.00200$89,441.20
long13 Mar 2025 83,680.1023 Aug 2025 116,936.00163$94,160.90
long25 Aug 2025 113,494.0027 Aug 2025 111,763.002−$5,047.98
long28 Aug 2025 111,262.0029 Aug 2025 112,567.001$3,823.89
long1 Sep 2025 108,246.002 Oct 2025 118,595.0031$31,536.30
long3 Oct 2025 120,529.0011 Oct 2025 112,774.008−$23,252.80
long18 Oct 2025 106,432.0020 Oct 2025 108,643.002$7,025.03
long21 Oct 2025 110,532.006 Dec 2025 89,330.0046−$66,211.30
long7 Dec 2025 89,236.801 Feb 2026 78,741.1056−$32,811.00
long2 Feb 2026 76,968.203 Feb 2026 78,738.601$5,661.93
long13 Feb 2026 66,272.2014 Feb 2026 68,854.001$9,810.18
long16 Feb 2026 68,832.6012 Jun 2026 63,626.00116−$19,789.90
long13 Jun 2026 63,580.0022 Aug 2026 78,338.0070$56,134.70
long27 Aug 2026 79,023.8029 Aug 2026 77,845.902−$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.

ScriptSharesTypeNetTradesMax drawdown
Simple way to BEAT the market [STRATEGY] this page—v4 strategy+193.5%1539.2%
Crypto RSI with RVI Strategy by exlux99stdevv4 strategy+4.0%232.1%
Portfolio Performance - 2 Assets by Skywalking2874stdevv5 strategyNo trades on this market
Historical Volatility by Zeal Terminalstdevv5 indicatorindicator
Double Bollinger Binary Options by Trade_by_DBstdevv5 strategyNo trades on this market
Improved Bollinger Swing Strategy Stock Nasdaq by exlux99stdevv4 strategy−20.4%722.3%

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 6 msWith a workaround 1,000 bars in 32 msNot measured
PineTSNo 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")