Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

P-Signal Strategy (BTCUSD Multi Frame)

A Pine Script v4 strategy built on Stdev (ser, int), SMA (ser, int) and SMA or Change (nIntr_D). It has 6 order rules, 3 entries 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. 3 settings; defaults include Number of D Bars 9, Number of W Bars 4 and Number of M Bars 6.

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 P-Signal Strategy (BTCUSD Multi Frame) repaint?
Yes
At least one pattern in the source can repaint: intrabar recalculation.
How did P-Signal Strategy (BTCUSD Multi Frame) do on BTCUSDT 1D with default settings?
+30.79%
From 26 Jan 2024 to 21 Oct 2026, over 46 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Can P-Signal Strategy (BTCUSD Multi Frame) 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 P-Signal Strategy (BTCUSD Multi Frame) use a stop loss?
No
Every exit waits for a signal; nothing limits a losing trade before it fires.
Does P-Signal Strategy (BTCUSD Multi Frame) run in Zeal Terminal?
Yes
It compiles in 28 ms and runs 1,000 bars in 54 ms, in the browser.

BTCUSDT · 1D · default settings

  • HLine
  • HLine
  • Plot
  • Plot
  • Winning trade
  • Losing trade
  • Equity
  • Buy and hold
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOctHLine$137,694$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. 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. The live re-run is not offered here: the script requests BINANCE:BTCUSDT W, BINANCE:BTCUSDT M, which this page cannot load in your browser.
Net profit
+30.79%
$30,789.30
Buy and hold
+102.5%
same period
Closed trades
46
22 won · 24 lost
Profitable
47.8%
of closed trades
Profit factor
1.20
gross profit ÷ gross loss
Max drawdown
48.57%
−$84,702.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.

  • 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 abs → math.abs, exp → math.exp, stdev → ta.stdev, sma → ta.sma, sqrt → math.sqrt, change → ta.change, sign → math.sign, security → request.security.

v4 → v5

VerifiedDownload the v5 script

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

  • Line 4: //@version=4 → //@version=5
  • Line 8: input(type = input.integer) → input.int()
  • Line 9: input(type = input.integer) → input.int()
  • Line 10: input(type = input.integer) → input.int()
  • Line 19: abs → math.abs
  • Line 20: exp → math.exp
14 more edits
  • Line 26: stdev → ta.stdev
  • Line 27: sma → ta.sma
  • Line 28: sqrt → math.sqrt
  • Line 30: sma → ta.sma
  • Line 30: change → ta.change
  • Line 31: sign → math.sign
  • Line 32: sma → ta.sma
  • Line 32: security → request.security
  • Line 32: change → ta.change
  • Line 33: sign → math.sign
  • Line 34: sma → ta.sma
  • Line 34: security → request.security
  • Line 34: change → ta.change
  • Line 35: sign → math.sign
⋯// P-Signal Strategy © Kharevsky-// @version=4+// @version=5// **********************************************************************************************************⋯// Parameters and const of P-Signal.-nPoints_D = input(title = "Number of D Bars", type = input.integer, defval = 9, minval = 4, maxval = 100, group = "Parameters of observation.")+nPoints_D = input.int(title = "Number of D Bars", defval = 9, minval = 4, maxval = 100, group = "Parameters of observation.")-nPoints_W = input(title = "Number of W Bars", type = input.integer, defval = 4, minval = 4, maxval = 100, group = "Parameters of observation.")+nPoints_W = input.int(title = "Number of W Bars", defval = 4, minval = 4, maxval = 100, group = "Parameters of observation.")-nPoints_M = input(title = "Number of M Bars", type = input.integer, defval = 6, minval = 4, maxval = 100, group = "Parameters of observation.")+nPoints_M = input.int(title = "Number of M Bars", defval = 6, minval = 4, maxval = 100, group = "Parameters of observation.")int nIntr_D = nPoints_D - 1⋯fErf(x) =>-    nT = 1.0/(1.0 + 0.5*abs(x))+    nT = 1.0/(1.0 + 0.5*math.abs(x))-    nAns = 1.0 - nT*exp(-x*x - 1.26551223 + +    nAns = 1.0 - nT*math.exp(-x*x - 1.26551223 +      nT*( 1.00002368 + nT*( 0.37409196 + nT*( 0.09678418 + ⋯fPSignal(ser, int) => -    nStDev = stdev(ser, int)+    nStDev = ta.stdev(ser, int)-    nSma = sma(ser, int)+    nSma = ta.sma(ser, int)-    fErf(nStDev > 0 ? nSma/nStDev/sqrt(2) : 1.0)+    fErf(nStDev > 0 ? nSma/nStDev/math.sqrt(2) : 1.0)// Strategy.-float nPSignal_D = sma(fPSignal(change(ohlc4), nIntr_D), nIntr_D)+float nPSignal_D = ta.sma(fPSignal(ta.change(ohlc4), nIntr_D), nIntr_D)-float ndPSignal_D = sign(nPSignal_D[0] - nPSignal_D[1])+float ndPSignal_D = math.sign(nPSignal_D[0] - nPSignal_D[1])-float nPSignal_W = sma(security(syminfo.tickerid, "W",fPSignal(change(ohlc4), nIntr_W)), nIntr_W)+float nPSignal_W = ta.sma(request.security(syminfo.tickerid, "W",fPSignal(ta.change(ohlc4), nIntr_W)), nIntr_W)-float ndPSignal_W = sign(nPSignal_W[0] - nPSignal_W[1])+float ndPSignal_W = math.sign(nPSignal_W[0] - nPSignal_W[1])-float nPSignal_M = sma(security(syminfo.tickerid, "M",fPSignal(change(ohlc4), nIntr_M)), nIntr_M)+float nPSignal_M = ta.sma(request.security(syminfo.tickerid, "M",fPSignal(ta.change(ohlc4), nIntr_M)), nIntr_M)-float ndPSignal_M = sign(nPSignal_M[0] - nPSignal_M[1])+float ndPSignal_M = math.sign(nPSignal_M[0] - nPSignal_M[1])// ... Day⋯

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: 46 before, 29 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.

⋯// P-Signal Strategy © Kharevsky-// @version=5+// @version=6// **********************************************************************************************************⋯

Settings

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

SettingDefaultType and rangeFeeds
Parameters of observation.
Number of D Bars9int (written input.integer) · min 4 · max 100nIntr_D
Number of W Bars4int (written input.integer) · min 4 · max 100nIntr_W
Number of M Bars6int (written input.integer) · min 4 · max 100nIntr_M

What it calculates

  • Stdev (stdev, ta.stdev in v5)ser, intnStDev · line 26
  • SMA (sma, ta.sma in v5)ser, intnSma · line 27
  • SMA / Change (sma, ta.sma in v5)fPSignal(change(ohlc4), nIntr_D), nIntr_DnPSignal_D · line 30
  • SMA / Change (sma, ta.sma in v5)security(syminfo.tickerid, "W",fPSignal(change(ohlc4), nIntr_W)), nIntr_WnPSignal_W · line 32
  • SMA / Change (sma, ta.sma in v5)security(syminfo.tickerid, "M",fPSignal(change(ohlc4), nIntr_M)), nIntr_MnPSignal_M · line 34

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.

ohlc4ohlc4price datanPoints_DNumber of D Barssetting · 9nPoints_WNumber of W Barssetting · 4nPoints_MNumber of M Barssetting · 6nStDevStdev→ nStDevnSmaSMA→ nSmanPSignal_DSMA / Change→ nPSignal_DnPSignal_WSMA / Change→ nPSignal_WnPSignal_MSMA / Change→ nPSignal_MnIntr_DnIntr_DvaluenIntr_WnIntr_WvaluenIntr_MnIntr_MvaluenTnTvaluenAnsnAnsvaluendPSignal_DndPSignal_DvaluendPSignal_WndPSignal_WvaluendPSignal_MndPSignal_Mvalueentry:long_DOpen long_Dstrategy.entryclose:long_DClose long_Dstrategy.closeentry:long_WOpen long_Wstrategy.entryclose:long_WClose long_Wstrategy.closeentry:long_MOpen long_Mstrategy.entryclose:long_MClose long_Mstrategy.closehline:58hlinehlinehline:59hlinehlineplot:60plotplotplot:61plotplot

Order rules

OrderFires whenBy defaultLine
Open long_D long(nPSignal_D < 0 and ndPSignal_D > 0 and bDValveOpen)On38
Close long_D(nPSignal_D > 0 and ndPSignal_D < 0)On41
Open long_W long(nPSignal_W < 0 and ndPSignal_W > 0 and bWValveOpen)On45
Close long_W(nPSignal_W > 0 and ndPSignal_W < 0)On48
Open long_M long(nPSignal_M < 0 and ndPSignal_M > 0 and bMValveOpen)On52
Close long_M(nPSignal_M > 0 and ndPSignal_M < 0)On55

Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.

Does it repaint?

Yes

At least one pattern in the source can repaint; it is marked Check below.

5/12trades 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. On 0 of them the position changed while the bar was forming before it settled. Anyone watching live sees those changes; once the bar closes it matches history.
  • ClearHigher-timeframe data2 security call(s), none with lookahead on.
  • ClearFuture-bar referencesNo negative history offsets such as close[-1].
  • CheckIntrabar recalculationuses varip. Live values can differ from history.
  • 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+30.8%+102.5%4648%1.2048.6%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+15.3%+5.5%3352%1.5024.4%8 May 2026 – 21 Oct 2026
ETHUSDT 1D−1.4%+9.8%4349%0.874.9%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+0.7%+8.4%3951%1.391.2%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+0.1%+16.7%4648%1.220.2%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+0.0%+21.5%3540%1.470.0%8 May 2026 – 21 Oct 2026
BNBUSDT 1D+0.6%+148.3%5246%1.490.7%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+0.3%+17.1%3168%2.230.2%8 May 2026 – 21 Oct 2026

Higher-timeframe data for request.security(): BINANCE:BTCUSDT W (Binance BTCUSDT 1w), BINANCE:BTCUSDT M (Binance BTCUSDT 1M), fetched from Binance's public market data for each market.

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

The trades

By market direction

At entry, last 90 barsTradesWonP&L
Rising market1354%$7,667.48
Sideways market2544%$9,839.46
Falling market850%$13,282.40

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

How bad could the drawdown be?

46.8%

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

0%54%
All 46 trades
SideEntryExitBarsP&L
long5 Feb 2024 42,582.904 Mar 2024 63,114.0028$20,531.10
long26 Mar 2024 69,880.003 Apr 2024 65,464.008−$4,416.01
long11 Apr 2024 70,631.1015 Apr 2024 65,661.904−$4,969.23
long22 Apr 2024 64,941.2030 Apr 2024 63,866.008−$1,075.15
long29 Apr 2024 63,118.6013 May 2024 61,484.0014−$1,634.62
long7 May 2024 63,165.2025 May 2024 68,550.0018$5,384.81
long16 May 2024 66,206.503 Jun 2024 67,765.6018$1,559.11
long6 Jun 2024 71,108.0012 Jun 2024 67,314.206−$3,793.77
long23 Jun 2024 64,262.0024 Jul 2024 65,936.0031$1,673.99
long15 Jul 2024 60,797.905 Aug 2024 58,161.0021−$2,636.91
long11 Aug 2024 60,923.5018 Aug 2024 59,492.007−$1,431.52
long26 Aug 2024 64,220.009 Sep 2024 54,869.9014−$9,350.04
long10 Sep 2024 57,042.0023 Sep 2024 63,578.8013$6,536.75
long23 Sep 2024 63,578.807 Oct 2024 62,819.9014−$758.85
long1 Oct 2024 63,327.6024 Oct 2024 66,668.6023$3,341.05
long10 Oct 2024 60,636.0012 Jan 2025 94,600.0094$33,964.00
long29 Dec 2024 95,300.0026 Jan 2025 104,747.0028$9,446.86
long13 Jan 2025 94,545.1027 Jan 2025 102,620.0014$8,074.94
long17 Jan 2025 99,987.301 Mar 2025 84,349.9043−$15,637.40
long11 Feb 2025 97,430.8028 Mar 2025 87,232.0045−$10,198.80
long24 Feb 2025 96,258.0024 Apr 2025 93,691.1059−$2,566.93
long11 Apr 2025 79,607.3026 May 2025 109,004.0045$29,396.90
long8 Jun 2025 105,552.0017 Jun 2025 106,795.009$1,242.38
long26 Jun 2025 107,341.005 Jul 2025 107,984.009$643.66
long30 Jun 2025 108,357.0028 Jul 2025 119,416.0028$11,058.60
long28 Jul 2025 119,416.0018 Aug 2025 117,405.0021−$2,010.55
long18 Aug 2025 117,405.0025 Aug 2025 113,494.007−$3,911.42
long28 Aug 2025 111,262.0020 Sep 2025 115,632.0023$4,370.38
long15 Sep 2025 115,268.0029 Sep 2025 112,164.0014−$3,104.05
long1 Oct 2025 114,049.0011 Oct 2025 112,774.0010−$1,274.45
long20 Oct 2025 108,643.002 Nov 2025 110,098.0013$1,455.33
long3 Nov 2025 110,541.007 Dec 2025 89,236.8034−$21,303.90
long12 Nov 2025 103,059.0022 Dec 2025 88,658.9040−$14,400.10
long23 Dec 2025 88,620.8031 Dec 2025 88,485.508−$135.29
long5 Jan 2026 91,529.7026 Jan 2026 86,670.4021−$4,859.38
long30 Jan 2026 84,650.2012 Mar 2026 70,191.9041−$14,458.30
long16 Feb 2026 68,832.6030 Mar 2026 66,010.9042−$2,821.66
long31 Mar 2026 66,797.4016 Apr 2026 74,810.0016$8,012.61
long13 Apr 2026 70,741.604 May 2026 78,568.6021$7,827.02
long1 May 2026 76,346.6022 Jun 2026 63,312.0052−$13,034.60
long26 May 2026 77,322.0013 Jul 2026 63,780.0048−$13,542.00
long8 Jun 2026 63,332.003 Aug 2026 63,570.0056$238.00
long3 Jul 2026 61,560.0014 Aug 2026 63,490.9042$1,930.86
long6 Aug 2026 64,665.2029 Aug 2026 77,845.9023$13,180.60
long20 Aug 2026 69,334.8014 Sep 2026 76,842.0025$7,507.23
long24 Aug 2026 77,734.0028 Sep 2026 84,472.0035$6,738.01

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
P-Signal Strategy (BTCUSD Multi Frame) this page—v4 strategy+30.8%4648.6%
Double Bollinger Binary Options by Trade_by_DBsma stdevv5 strategyNo trades on this market
Improved Bollinger Swing Strategy Stock Nasdaq by exlux99sma stdevv4 strategy−20.4%722.3%
I11L Long Put-Call Ratio Inversion by I11Lsma stdevv5 strategyNo trades on this market
P-Signal Strategy by Kharevskystdev smav4 strategy−9.7%2934.6%
P-Signal Strategy & Alert by Kharevskystdev smav4 strategy−9.7%2934.6%

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 28 msWith a workaround 1,000 bars in 54 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/// P-Signal Strategy © Kharevsky// @version=4// **********************************************************************************************************strategy("P-Signal Strategy:", precision = 3, pyramiding = 3)// Parameters and const of P-Signal.nPoints_D = input(title = "Number of D Bars", type = input.integer, defval = 9, minval = 4, maxval = 100, group = "Parameters of observation.")nPoints_W = input(title = "Number of W Bars", type = input.integer, defval = 4, minval = 4, maxval = 100, group = "Parameters of observation.")nPoints_M = input(title = "Number of M Bars", type = input.integer, defval = 6, minval = 4, maxval = 100, group = "Parameters of observation.")int nIntr_D = nPoints_D - 1int nIntr_W = nPoints_W - 1int nIntr_M = nPoints_M - 1varip bool bDValveOpen = truevarip bool bWValveOpen = truevarip bool bMValveOpen = true// Horner's method for Gauss & P-Signal functions.fErf(x) =>    nT = 1.0/(1.0 + 0.5*abs(x))    nAns = 1.0 - nT*exp(-x*x - 1.26551223 +      nT*( 1.00002368 + nT*( 0.37409196 + nT*( 0.09678418 +      nT*(-0.18628806 + nT*( 0.27886807 + nT*(-1.13520398 +      nT*( 1.48851587 + nT*(-0.82215223 + nT*( 0.17087277 ))))))))))    x >= 0 ? nAns : -nAnsfPSignal(ser, int) =>     nStDev = stdev(ser, int)    nSma = sma(ser, int)    fErf(nStDev > 0 ? nSma/nStDev/sqrt(2) : 1.0)// Strategy.float nPSignal_D = sma(fPSignal(change(ohlc4), nIntr_D), nIntr_D)float ndPSignal_D = sign(nPSignal_D[0] - nPSignal_D[1])float nPSignal_W = sma(security(syminfo.tickerid, "W",fPSignal(change(ohlc4), nIntr_W)), nIntr_W)float ndPSignal_W = sign(nPSignal_W[0] - nPSignal_W[1])float nPSignal_M = sma(security(syminfo.tickerid, "M",fPSignal(change(ohlc4), nIntr_M)), nIntr_M)float ndPSignal_M = sign(nPSignal_M[0] - nPSignal_M[1])// ... Dayif(nPSignal_D < 0 and ndPSignal_D > 0 and bDValveOpen)    strategy.entry("long_D", strategy.long, 1)     bDValveOpen := falseif(nPSignal_D > 0 and ndPSignal_D < 0)    strategy.close("long_D")    bDValveOpen := true// ... Weekif(nPSignal_W < 0 and ndPSignal_W > 0 and bWValveOpen)    strategy.entry("long_W", strategy.long, 1)     bWValveOpen := falseif(nPSignal_W > 0 and ndPSignal_W < 0)    strategy.close("long_W")    bWValveOpen := true// ... Monthif(nPSignal_M < 0 and ndPSignal_M > 0 and bMValveOpen)    strategy.entry("long_M", strategy.long, 1)     bMValveOpen := falseif(nPSignal_M > 0 and ndPSignal_M < 0)    strategy.close("long_M")    bMValveOpen := true// Plotting. hline(+1.0, color = color.new(color.orange,70), linestyle = hline.style_dotted)hline(-1.0, color = color.new(color.orange,70), linestyle = hline.style_dotted)plot(nPSignal_D, color = color.blue, style = plot.style_line)plot(strategy.position_size, color = color.white, style = plot.style_cross)// The end.