Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

P-Signal Strategy & Alert

A Pine Script v4 strategy built on Stdev (ser, int), SMA (ser, int) and SMA or Change (nIntr). 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. 1 setting; defaults include Number of Bars 9.

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 & Alert repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 7 of 7 trades.
How did P-Signal Strategy & Alert do on BTCUSDT 1D with default settings?
−9.68%
From 26 Jan 2024 to 21 Oct 2026, over 29 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Can P-Signal Strategy & Alert 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.
What alerts does P-Signal Strategy & Alert have?
2
"P-Signal strategy opened the long position: " + syminfo.tickerid + " " + timeframe.period; "P-Signal strategy closed the long position: " + syminfo.tickerid + " " + timeframe.period.
Does P-Signal Strategy & Alert use a stop loss?
No
Every exit waits for a signal; nothing limits a losing trade before it fires.

BTCUSDT · 1D · default settings

  • HLine
  • HLine
  • 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 (1)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOctHLine$93,407$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.
Net profit
−9.68%
−$9,677.06
Buy and hold
+102.5%
same period
Closed trades
29
14 won · 15 lost
Profitable
48.3%
of closed trades
Profit factor
0.87
gross profit ÷ gross loss
Max drawdown
34.60%
−$38,607.60

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.

  • Note

    Uses an argument v6 removed

    when = on line 25, 26. The upgraded version below moves each call inside an if block.

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.
  • 2 strategy calls use the when = argument (line 25, 26). It is deprecated in v5 and removed in v6, where each call moves inside an if block.

v4 → v5

Verified

Same 29 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 12: abs → math.abs
  • Line 13: exp → math.exp
  • Line 19: stdev → ta.stdev
  • Line 20: sma → ta.sma
4 more edits
  • Line 21: sqrt → math.sqrt
  • Line 23: sma → ta.sma
  • Line 23: change → ta.change
  • Line 24: sign → math.sign
⋯// P-Signal Strategy © Kharevsky-// @version=4+// @version=5// **********************************************************************************************************⋯// Parameters and const of P-Signal.-nPoints = input(title = "Number of Bars", type = input.integer, defval = 9, minval = 4, maxval = 100, group = "Parameters of observation.")+nPoints = input.int(title = "Number of Bars", defval = 9, minval = 4, maxval = 100, group = "Parameters of observation.")int nIntr = nPoints - 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)// Strat.-float nPSignal = sma(fPSignal(change(ohlc4), nIntr), nIntr)+float nPSignal = ta.sma(fPSignal(ta.change(ohlc4), nIntr), nIntr)-float ndPSignal = sign(nPSignal[0] - nPSignal[1])+float ndPSignal = math.sign(nPSignal[0] - nPSignal[1])strategy.entry("long", strategy.long, 1, when = nPSignal < 0 and ndPSignal > 0)⋯

Clean v5

VerifiedDownload the v5 script

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

  • Line 25: when = nPSignal < 0 and ndPSignal > 0 → if block
  • Line 26: when = nPSignal > 0 and ndPSignal < 0 → if block
⋯float ndPSignal = math.sign(nPSignal[0] - nPSignal[1])-strategy.entry("long", strategy.long, 1, when = nPSignal < 0 and ndPSignal > 0)+if nPSignal < 0 and ndPSignal > 0+    strategy.entry("long", strategy.long, 1)-strategy.close("long", when = nPSignal > 0 and ndPSignal < 0)+if nPSignal > 0 and ndPSignal < 0+    strategy.close("long")// Plotting. ⋯

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: 29 before, 21 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 Bars9int (written input.integer) · min 4 · max 100nIntr

What it calculates

  • Stdev (stdev, ta.stdev in v5)ser, intnStDev · line 19
  • SMA (sma, ta.sma in v5)ser, intnSma · line 20
  • SMA / Change (sma, ta.sma in v5)fPSignal(change(ohlc4), nIntr), nIntrnPSignal · line 23

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 datanPointsNumber of Barssetting · 9nStDevStdev→ nStDevnSmaSMA→ nSmanPSignalSMA / Change→ nPSignalnIntrnIntrvaluenTnTvaluenAnsnAnsvaluendPSignalndPSignalvalueentry:longOpen longstrategy.entryclose:longClose longstrategy.closehline:28hlinehlinehline:29hlinehlineplot:30plotplotplot:31plotplotalert:34alertalertalert:36alertalert

Order rules

OrderFires whenBy defaultLine
Open long longnPSignal < 0 and ndPSignal > 0On25
Close longnPSignal > 0 and ndPSignal < 0On26

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

Alerts

AlertCallMessageLine
(no title)alert"P-Signal strategy opened the long position: " + syminfo.tickerid + " " + timeframe.period34
(no title)alert"P-Signal strategy closed the long position: " + syminfo.tickerid + " " + timeframe.period36

Does it repaint?

No

No repainting patterns in the source, and the live replay matched history.

7/7trades 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−9.7%+102.5%2948%0.8734.6%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+7.7%+5.5%3155%1.537.9%8 May 2026 – 21 Oct 2026
ETHUSDT 1D−1.3%+9.8%3050%0.712.2%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+0.0%+8.4%3751%1.020.6%8 May 2026 – 21 Oct 2026
SOLUSDT 1D−0.1%+16.7%3142%0.830.2%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h−0.0%+21.5%3345%0.760.0%8 May 2026 – 21 Oct 2026
BNBUSDT 1D+0.1%+148.3%3554%1.130.3%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+0.2%+17.1%3067%3.050.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 market1145%−$2,274.90
Sideways market1354%−$6,183.55
Falling market540%−$1,218.61

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

How bad could the drawdown be?

43.9%

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

0%51%
All 29 trades
SideEntryExitBarsP&L
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
long7 May 2024 63,165.2013 May 2024 61,484.006−$1,681.18
long16 May 2024 66,206.5025 May 2024 68,550.009$2,343.48
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
long11 Aug 2024 60,923.5018 Aug 2024 59,492.007−$1,431.52
long10 Sep 2024 57,042.0023 Sep 2024 63,578.8013$6,536.75
long10 Oct 2024 60,636.0024 Oct 2024 66,668.6014$6,032.64
long29 Dec 2024 95,300.0012 Jan 2025 94,600.0014−$700.01
long17 Jan 2025 99,987.3026 Jan 2025 104,747.009$4,759.56
long11 Feb 2025 97,430.8028 Mar 2025 87,232.0045−$10,198.80
long11 Apr 2025 79,607.3024 Apr 2025 93,691.1013$14,083.80
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
long28 Jul 2025 119,416.0018 Aug 2025 117,405.0021−$2,010.55
long28 Aug 2025 111,262.0020 Sep 2025 115,632.0023$4,370.38
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
long12 Nov 2025 103,059.007 Dec 2025 89,236.8025−$13,822.20
long23 Dec 2025 88,620.8031 Dec 2025 88,485.508−$135.29
long30 Jan 2026 84,650.2012 Mar 2026 70,191.9041−$14,458.30
long31 Mar 2026 66,797.4016 Apr 2026 74,810.0016$8,012.61
long26 May 2026 77,322.0022 Jun 2026 63,312.0027−$14,010.00
long3 Jul 2026 61,560.0013 Jul 2026 63,780.0010$2,220.00
long6 Aug 2026 64,665.2014 Aug 2026 63,490.908−$1,174.38
long20 Aug 2026 69,334.8029 Aug 2026 77,845.909$8,511.10
long19 Sep 2026 80,883.9028 Sep 2026 84,472.009$3,588.15

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 & Alert this page—v4 strategy−9.7%2934.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%
Bollinger Stop Strategy by ROBO_Tradingsma stdevv5 strategy−32.0%4161.5%

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 15 msWith a workaround 1,000 bars in 34 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)// Parameters and const of P-Signal.nPoints = input(title = "Number of Bars", type = input.integer, defval = 9, minval = 4, maxval = 100, group = "Parameters of observation.")int nIntr = nPoints - 1// Horner's method for the error (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)// Strat.float nPSignal = sma(fPSignal(change(ohlc4), nIntr), nIntr)float ndPSignal = sign(nPSignal[0] - nPSignal[1])strategy.entry("long", strategy.long, 1, when = nPSignal < 0 and ndPSignal > 0)strategy.close("long", when = nPSignal > 0 and ndPSignal < 0)// 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, color = color.blue, style = plot.style_line)plot(strategy.position_size, color = color.white, style = plot.style_cross)// Alerts.if(strategy.position_size[0] > strategy.position_size[1])    alert("P-Signal strategy opened the long position: " + syminfo.tickerid + " " + timeframe.period, alert.freq_once_per_bar)if(strategy.position_size[0] < strategy.position_size[1])    alert("P-Signal strategy closed the long position: " + syminfo.tickerid + " " + timeframe.period, alert.freq_once_per_bar)// The end.