Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

percentrank strategy

A Pine Script v4 strategy built on Percentrank (close, 10). It has 4 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 no commission. 5 settings; defaults include Source close, lookback - Период сравнения 10 and scale offset - смещение шкалы 50.

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 percentrank strategy repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 21 of 21 trades.
How did percentrank strategy do on BTCUSDT 1D with default settings?
+45.01%
From 26 Jan 2024 to 21 Oct 2026, over 75 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Can percentrank 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 percentrank strategy use a stop loss?
No
Every exit waits for a signal; nothing limits a losing trade before it fires.
Does percentrank strategy run in Zeal Terminal?
Yes
It compiles in 12 ms and runs 1,000 bars in 24 ms, in the browser.

BTCUSDT · 1D · default settings

  • Plot
  • Plot
  • Plot
  • 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 (5)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOctPlot$143,621$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. Lines are what the script plots.
Net profit
+45.01%
$45,012.90
Buy and hold
+102.5%
same period
Closed trades
75
28 won · 47 lost
Profitable
37.3%
of closed trades
Profit factor
1.30
gross profit ÷ gross loss
Max drawdown
30.67%
−$34,802.40

One run with the author's default settings, $100,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.

  • 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 percentrank → ta.percentrank, crossunder → ta.crossunder, crossover → ta.crossover.

v4 → v5

Verified

Same 75 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.

  • Line 3: //@version=4 → //@version=5
  • Line 6: input(type = input.integer) → input.int()
  • Line 7: input(type = input.integer) → input.int()
  • Line 8: input(type = input.integer) → input.int()
  • Line 9: input(type = input.integer) → input.int()
  • Line 10: percentrank → ta.percentrank
4 more edits
  • Line 14: crossunder → ta.crossunder
  • Line 17: crossover → ta.crossover
  • Line 21: crossover → ta.crossover
  • Line 24: crossunder → ta.crossunder
⋯// © Alex_Dyuk-//@version=4+//@version=5strategy(title="percentrank", shorttitle="percentrank")src = input(close, title="Source")-len = input(title="lookback - Период сравнения", type=input.integer, defval=10, minval=2)+len = input.int(title="lookback - Период сравнения", defval=10, minval=2)-scale = input(title="scale offset - смещение шкалы", type=input.integer, defval=50, minval=0, maxval=100)+scale = input.int(title="scale offset - смещение шкалы", defval=50, minval=0, maxval=100)-level_1 = input(title="sygnal line 1", type=input.integer, defval=30)+level_1 = input.int(title="sygnal line 1", defval=30)-level_2 = input(title="sygnal line 2", type=input.integer, defval=-30)+level_2 = input.int(title="sygnal line 2", defval=-30)-prank = percentrank(src,len)-scale+prank = ta.percentrank(src,len)-scaleplot(prank, style = plot.style_columns)⋯plot(level_1, style = plot.style_line, color = color.green)-longCondition = (crossunder(level_1, prank) == true)+longCondition = (ta.crossunder(level_1, prank) == true)if (longCondition)    strategy.entry("Long", strategy.long)-longExitCondition = (crossover(level_2, prank) == true)+longExitCondition = (ta.crossover(level_2, prank) == true)if (longExitCondition)⋯    -shortCondition = (crossover(level_2, prank) == true)+shortCondition = (ta.crossover(level_2, prank) == true)if (shortCondition)    strategy.entry("Short", strategy.short)-shortexitCondition = (crossunder(level_1, prank) == true)+shortexitCondition = (ta.crossunder(level_1, prank) == true)if (shortexitCondition)⋯

Clean v5

VerifiedDownload the v5 script

Same 75 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.

  • Line 5: input() → input.source()
⋯strategy(title="percentrank", shorttitle="percentrank")-src = input(close, title="Source")+src = input.source(close, title="Source")len = input.int(title="lookback - Период сравнения", defval=10, minval=2)⋯

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: 75 before, 96 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.

⋯// © Alex_Dyuk-//@version=5+//@version=6strategy(title="percentrank", shorttitle="percentrank")⋯

Settings

Every input the script declares, with its default and what it feeds. Bounds are the ones the script enforces.

SettingDefaultType and rangeFeeds
Sourceclosesourceprank
lookback - Период сравнения10int (written input.integer) · min 2prank
scale offset - смещение шкалы50int (written input.integer) · min 0 · max 100prank
sygnal line 130int (written input.integer)longCondition shortexitCondition plot
sygnal line 2-30int (written input.integer)longExitCondition shortCondition plot

What it calculates

  • Percentrank (percentrank, ta.percentrank in v5)Source (close), lookback - Период сравнения (10)prank · line 10

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 datalenlookback - Период сравн…setting · 10scalescale offset - смещение…setting · 50level_1sygnal line 1setting · 30level_2sygnal line 2setting · -30prankPercentrank→ pranklongConditionlongConditionconditionlongExitConditionlongExitConditionconditionshortConditionshortConditionconditionshortexitConditionshortexitConditionconditionentry:LongOpen Longstrategy.entryclose:LongClose Longstrategy.closeentry:ShortOpen Shortstrategy.entryclose:ShortClose Shortstrategy.closeplot:11plotplotplot:12plotplotplot:13plotplot

Order rules

OrderFires whenBy defaultLine
Open Long long(longCondition)On16
Close Long(longExitCondition)On19
Open Short short(shortCondition)On23
Close Short(shortexitCondition)On26

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.

21/21trades 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+45.0%+102.5%7537%1.3030.7%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+6.8%+5.5%9431%1.1410.8%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+2.2%+9.8%7338%1.272.6%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h−0.2%+8.4%8826%0.900.9%8 May 2026 – 21 Oct 2026
SOLUSDT 1D−0.0%+16.7%7739%0.980.2%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+0.0%+21.5%7036%1.430.0%8 May 2026 – 21 Oct 2026
BNBUSDT 1D−0.4%+148.3%8533%0.770.7%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+0.2%+17.1%7639%1.620.1%8 May 2026 – 21 Oct 2026

Backtests are simulations on historical data and are not investment advice.

Settings heatmap

Two settings that feed the entry signal, moved around their defaults. The best in-sample pair (lookback - Период сравнения 10, scale offset - смещение шкалы 35) made +59.8% before 26 Dec 2025 and +38.3% after it, against +25.1% for the defaults. 22% of the 64 combinations made money in-sample and 45% out-of-sample.

Before 26 Dec 2025 · in-sample
scale offset - смещение шкалы ↓ · lookback - Период сравнения →567910121417
250%0%0%0%0%0%0%0%
300%0%0%0%0%0%0%0%
35−22%−35%−28%+24%+60%+26%−13%−66%
43−22%−18%−34%+16%+28%+44%−5%−25%
50−16%+20%−21%+18%+20%+31%−7%−12%
60+11%−1%+21%−24%+7%−20%+28%−13%
700%0%0%0%0%0%0%0%
850%0%0%0%0%0%0%0%
From 26 Dec 2025 · out-of-sample
scale offset - смещение шкалы ↓ · lookback - Период сравнения →567910121417
250%0%0%0%0%0%0%0%
300%0%0%0%0%0%0%0%
35−1%−12%+5%+27%+38%+39%+37%+32%
43−1%+16%+24%+33%+38%+37%+33%+37%
50+16%+13%+26%+35%+25%+28%+25%+29%
60+22%+13%+14%+3%+5%+5%+15%+18%
700%0%0%0%0%0%0%0%
850%0%0%0%0%0%0%0%

Net P&L of trades opened in each period, as a share of starting capital. marks the defaults and the best in-sample cell. Hover a cell for its trade count. Backtests are simulations on historical data and are not investment advice.

The trades

By market direction

At entry, last 90 barsTradesWonP&L
Rising market2726%−$25,301.10
Sideways market3546%$60,666.50
Falling market1338%$9,647.53

Rising and falling mean the market moved more than 15% over the 90 bars before entry.

How bad could the drawdown be?

41.0%

The 95th percentile of the worst drawdown when the same 75 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 19.6% to 41.0%; the tick is what actually happened, 28.3%. Order luck alone moves it this much.

0%47%
All 75 trades
SideEntryExitBarsP&L
long8 Feb 2024 44,349.6024 Feb 2024 50,744.2016$6,394.55
short24 Feb 2024 50,744.2027 Feb 2024 54,476.503−$3,732.33
long27 Feb 2024 54,476.5017 Mar 2024 65,300.6019$10,824.20
short17 Mar 2024 65,300.6026 Mar 2024 69,880.009−$4,579.36
long26 Mar 2024 69,880.003 Apr 2024 65,464.008−$4,416.01
short3 Apr 2024 65,464.009 Apr 2024 71,620.006−$6,156.01
long9 Apr 2024 71,620.0014 Apr 2024 63,924.505−$7,695.48
short14 Apr 2024 63,924.5023 Apr 2024 66,819.309−$2,894.80
long23 Apr 2024 66,819.3028 Apr 2024 63,462.005−$3,357.34
short28 Apr 2024 63,462.006 May 2024 64,012.008−$550.02
long6 May 2024 64,012.0030 May 2024 67,652.4024$3,640.41
short30 May 2024 67,652.405 Jun 2024 70,537.806−$2,885.42
long5 Jun 2024 70,537.8012 Jun 2024 67,314.207−$3,223.60
short12 Jun 2024 67,314.2014 Jul 2024 59,204.0032$8,110.22
long14 Jul 2024 59,204.001 Aug 2024 64,628.0018$5,424.00
short1 Aug 2024 64,628.0022 Aug 2024 61,156.0021$3,471.98
long22 Aug 2024 61,156.001 Sep 2024 58,974.0010−$2,182.03
short1 Sep 2024 58,974.0013 Sep 2024 58,132.3012$841.69
long13 Sep 2024 58,132.302 Oct 2024 60,804.9019$2,672.61
short2 Oct 2024 60,804.9012 Oct 2024 62,540.0010−$1,735.07
long12 Oct 2024 62,540.0026 Oct 2024 66,698.3014$4,158.33
short26 Oct 2024 66,698.3029 Oct 2024 69,962.203−$3,263.89
long29 Oct 2024 69,962.2022 Dec 2024 97,292.0054$27,329.80
short22 Dec 2024 97,292.005 Jan 2025 98,220.5014−$928.51
long5 Jan 2025 98,220.5010 Jan 2025 92,552.505−$5,668.02
short10 Jan 2025 92,552.5016 Jan 2025 100,497.006−$7,944.86
long16 Jan 2025 100,497.0028 Jan 2025 102,083.0012$1,585.48
short28 Jan 2025 102,083.0013 Feb 2025 97,870.0016$4,212.83
long13 Feb 2025 97,870.0017 Feb 2025 96,118.104−$1,751.88
short17 Feb 2025 96,118.1021 Feb 2025 98,305.004−$2,186.89
long21 Feb 2025 98,305.0025 Feb 2025 91,552.904−$6,752.13
short25 Feb 2025 91,552.9020 Mar 2025 86,845.9023$4,706.95
long20 Mar 2025 86,845.9030 Mar 2025 82,648.5010−$4,197.40
short30 Mar 2025 82,648.5013 Apr 2025 85,276.9014−$2,628.38
long13 Apr 2025 85,276.9030 May 2025 105,590.0047$20,312.80
short30 May 2025 105,590.009 Jun 2025 105,734.0010−$144.26
long9 Jun 2025 105,734.0018 Jun 2025 104,551.009−$1,182.84
short18 Jun 2025 104,551.0025 Jun 2025 106,083.007−$1,531.83
long25 Jun 2025 106,083.0021 Jul 2025 117,265.0026$11,182.10
short21 Jul 2025 117,265.0023 Jul 2025 119,954.002−$2,689.32
long23 Jul 2025 119,954.001 Aug 2025 115,764.009−$4,190.36
short1 Aug 2025 115,764.0011 Aug 2025 119,294.0010−$3,530.20
long11 Aug 2025 119,294.0019 Aug 2025 116,227.008−$3,067.22
short19 Aug 2025 116,227.009 Sep 2025 112,065.0021$4,161.82
long9 Sep 2025 112,065.0022 Sep 2025 115,232.0013$3,167.06
short22 Sep 2025 115,232.002 Oct 2025 118,595.0010−$3,362.70
long2 Oct 2025 118,595.0011 Oct 2025 112,774.009−$5,820.50
short11 Oct 2025 112,774.0025 Oct 2025 111,005.0014$1,769.59
long25 Oct 2025 111,005.004 Nov 2025 106,583.0010−$4,421.85
short4 Nov 2025 106,583.003 Dec 2025 91,277.9029$15,305.20
long3 Dec 2025 91,277.907 Dec 2025 89,236.804−$2,041.08
short7 Dec 2025 89,236.8010 Dec 2025 92,678.803−$3,442.01
long10 Dec 2025 92,678.8015 Dec 2025 88,172.205−$4,506.65
short15 Dec 2025 88,172.202 Jan 2026 88,839.1018−$666.89
long2 Jan 2026 88,839.1021 Jan 2026 88,427.7019−$411.39
short21 Jan 2026 88,427.703 Mar 2026 68,830.1041$19,597.60
long3 Mar 2026 68,830.1020 Mar 2026 69,930.0017$1,099.95
short20 Mar 2026 69,930.006 Apr 2026 69,034.2017$895.83
long6 Apr 2026 69,034.2030 Apr 2026 75,780.0024$6,745.82
short30 Apr 2026 75,780.003 May 2026 78,686.803−$2,906.84
long3 May 2026 78,686.8014 May 2026 79,313.6011$626.77
short14 May 2026 79,313.6014 Jun 2026 64,458.0031$14,855.60
long14 Jun 2026 64,458.0022 Jun 2026 63,312.008−$1,146.01
short22 Jun 2026 63,312.004 Jul 2026 62,583.3012$728.74
long4 Jul 2026 62,583.3014 Jul 2026 62,334.5010−$248.74
short14 Jul 2026 62,334.5015 Jul 2026 65,044.001−$2,709.47
long15 Jul 2026 65,044.0028 Jul 2026 63,755.9013−$1,288.13
short28 Jul 2026 63,755.908 Aug 2026 64,923.2011−$1,167.34
long8 Aug 2026 64,923.2013 Aug 2026 63,480.005−$1,443.21
short13 Aug 2026 63,480.0020 Aug 2026 69,334.807−$5,854.79
long20 Aug 2026 69,334.802 Sep 2026 77,439.0013$8,104.23
short2 Sep 2026 77,439.004 Sep 2026 81,270.402−$3,831.36
long4 Sep 2026 81,270.4011 Sep 2026 76,568.707−$4,701.64
short11 Sep 2026 76,568.7019 Sep 2026 80,883.908−$4,315.13
long19 Sep 2026 80,883.908 Oct 2026 83,321.8019$2,437.95

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
percentrank strategy this page—v4 strategy+45.0%7530.7%
Connors RSI by Zeal Terminalpercentrankv5 indicatorindicator

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 12 msYes 1,000 bars in 24 msNot measured
PineTSNo v5 and v6 only—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. 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/// © Alex_Dyuk//@version=4strategy(title="percentrank", shorttitle="percentrank")src = input(close, title="Source")len = input(title="lookback - Период сравнения", type=input.integer, defval=10, minval=2)scale = input(title="scale offset - смещение шкалы", type=input.integer, defval=50, minval=0, maxval=100)level_1 = input(title="sygnal line 1", type=input.integer, defval=30)level_2 = input(title="sygnal line 2", type=input.integer, defval=-30)prank = percentrank(src,len)-scaleplot(prank, style = plot.style_columns)plot(level_2, style = plot.style_line, color = color.red)plot(level_1, style = plot.style_line, color = color.green)longCondition = (crossunder(level_1, prank) == true)if (longCondition)    strategy.entry("Long", strategy.long)longExitCondition = (crossover(level_2, prank) == true)if (longExitCondition)    strategy.close("Long")    shortCondition = (crossover(level_2, prank) == true)if (shortCondition)    strategy.entry("Short", strategy.short)shortexitCondition = (crossunder(level_1, prank) == true)if (shortexitCondition)    strategy.close("Short")