Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

Backtest Signal To Noise

A Pine Script v4 strategy built on SMA (StN, 7). It has 3 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. 3 settings; defaults include Days 21 and Smooth 7.

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

BTCUSDT · 1D · default settings

  • StN
  • Smooth
  • 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 (3)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOctStN$98,672$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
+1.70%
$1,700.54
Buy and hold
+102.5%
same period
Closed trades
57
21 won · 36 lost
Profitable
36.8%
of closed trades
Profit factor
1.01
gross profit ÷ gross loss
Max drawdown
35.18%
−$41,232.50

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.

  • Note

    Uses iff(), which v5 removed line 24

    iff() on line 24, 25, 26, 27. v5 writes it as the ternary c ? a : b.

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 log → math.log, sma → ta.sma.

v4 → v5

Verified

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

  • Line 1: //@version=4 → //@version=5
  • Line 17: log → math.log
  • Line 19: input(type = input.integer) → input.int()
  • Line 20: input(type = input.integer) → input.int()
  • Line 23: sma → ta.sma
  • Line 24: iff(c, a, b) → (c ? a : b)
3 more edits
  • Line 25: iff(c, a, b) → (c ? a : b)
  • Line 26: iff(c, a, b) → (c ? a : b)
  • Line 27: iff(c, a, b) → (c ? a : b)
-//@version=4+//@version=5////////////////////////////////////////////////////////////⋯        StN := StN + (1/close[i])/length-    StN := -10*log(StN)+    StN := -10*math.log(StN)strategy(title="Backtest Signal To Noise ", shorttitle="StoN", overlay=false)-length = input(title="Days", type=input.integer, defval=21, minval=2)+length = input.int(title="Days", defval=21, minval=2)-Smooth =  input(title="Smooth", type=input.integer, defval=7, minval=2)+Smooth =  input.int(title="Smooth", defval=7, minval=2)reverse = input(false, title="Trade reverse")StN = SignalToNoise(length)-SMAStN = sma(StN, Smooth)+SMAStN = ta.sma(StN, Smooth)-pos = iff(SMAStN[1] > StN[1] , -1,-       iff(SMAStN[1] < StN[1], 1, 0)) +pos = (SMAStN[1] > StN[1] ? -1 : (SMAStN[1] < StN[1] ? 1 : 0)) -possig = iff(reverse and pos == 1, -1,-          iff(reverse and pos == -1 , 1, pos))     +possig = (reverse and pos == 1 ? -1 : (reverse and pos == -1 ? 1 : pos))     if (possig == 1) ⋯

Clean v5

VerifiedDownload the v5 script

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

  • Line 21: input() → input.bool()
⋯Smooth =  input.int(title="Smooth", defval=7, minval=2)-reverse = input(false, title="Trade reverse")+reverse = input.bool(false, title="Trade reverse")StN = SignalToNoise(length)⋯

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: 57 before, 186 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=6////////////////////////////////////////////////////////////⋯

Settings

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

SettingDefaultType and rangeFeeds
Days21int (written input.integer) · min 2StN line 15
Smooth7int (written input.integer) · min 2SMAStN
Trade reversefalseboolpossig

What it calculates

  • SMA (sma, ta.sma in v5)StN, Smooth (7)SMAStN · 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.

SmoothSmoothsetting · 7lengthDayssetting · 21SMAStNSMA→ SMAStNStNStNvaluepossigpossigconditionposposconditionentry:LongOpen Longstrategy.entryentry:ShortOpen Shortstrategy.entryclose_all:close_all strategy.close_allbarcolor:34barcolorbarcolorplot:35StNplotplot:36Smoothplot

Order rules

OrderFires whenBy defaultLine
Open Long long(possig == 1)On29
Open Short short(possig == -1)On31
Close (possig == 0)On33

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.

19/19trades 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+1.7%+102.5%5737%1.0135.2%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h−12.5%+5.5%5028%0.7621.3%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+0.1%+9.8%4743%1.023.6%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h−0.3%+8.4%5737%0.820.8%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+0.4%+16.7%4945%2.640.1%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+0.0%+21.5%4635%1.500.0%8 May 2026 – 21 Oct 2026
BNBUSDT 1D+0.5%+148.3%4333%1.440.7%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h−0.1%+17.1%4637%0.770.2%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 market1947%−$5,038.39
Sideways market2035%$19,563.70
Falling market1828%−$12,824.80

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

How bad could the drawdown be?

58.8%

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

0%68%
All 57 trades
SideEntryExitBarsP&L
long23 Feb 2024 51,288.405 Apr 2024 68,487.8042$17,199.40
short5 Apr 2024 68,487.8010 Apr 2024 69,146.005−$658.20
long10 Apr 2024 69,146.0018 Apr 2024 61,277.408−$7,868.62
short18 Apr 2024 61,277.4020 May 2024 66,274.0032−$4,996.62
long20 May 2024 66,274.0014 Jun 2024 66,773.0025$499.01
short14 Jun 2024 66,773.0019 Jul 2024 63,987.9035$2,785.09
long19 Jul 2024 63,987.908 Aug 2024 55,133.8020−$8,854.16
short8 Aug 2024 55,133.8027 Aug 2024 62,834.0019−$7,700.24
long27 Aug 2024 62,834.003 Sep 2024 59,132.107−$3,701.88
short3 Sep 2024 59,132.1022 Sep 2024 63,349.0019−$4,216.85
long22 Sep 2024 63,349.0013 Oct 2024 63,206.2021−$142.74
short13 Oct 2024 63,206.2018 Oct 2024 67,421.805−$4,215.55
long18 Oct 2024 67,421.8026 Dec 2024 99,429.6069$32,007.80
short26 Dec 2024 99,429.6028 Dec 2024 94,299.002$5,130.58
long28 Dec 2024 94,299.0029 Dec 2024 95,300.001$1,000.97
short29 Dec 2024 95,300.0019 Jan 2025 104,556.0021−$9,256.23
long19 Jan 2025 104,556.009 Feb 2025 96,444.8021−$8,111.48
short9 Feb 2025 96,444.802 Apr 2025 85,158.4052$11,286.40
long2 Apr 2025 85,158.409 Apr 2025 76,322.407−$8,835.93
short9 Apr 2025 76,322.4022 Apr 2025 87,516.2013−$11,193.80
long22 Apr 2025 87,516.2011 Jun 2025 110,274.0050$22,758.20
short11 Jun 2025 110,274.0012 Jun 2025 108,645.001$1,629.26
long12 Jun 2025 108,645.0014 Jun 2025 106,067.002−$2,578.54
short14 Jun 2025 106,067.0028 Jun 2025 107,048.0014−$980.99
long28 Jun 2025 107,048.003 Jul 2025 108,850.005$1,802.01
short3 Jul 2025 108,850.006 Jul 2025 108,198.003$651.47
long6 Jul 2025 108,198.005 Aug 2025 115,055.0030$6,856.91
short5 Aug 2025 115,055.0015 Aug 2025 118,295.0010−$3,240.06
long15 Aug 2025 118,295.0020 Aug 2025 112,873.005−$5,422.14
short20 Aug 2025 112,873.0026 Aug 2025 110,112.006$2,760.97
long26 Aug 2025 110,112.0028 Aug 2025 111,262.002$1,150.03
short28 Aug 2025 111,262.0016 Sep 2025 115,350.0019−$4,087.70
long16 Sep 2025 115,350.0030 Sep 2025 114,312.0014−$1,037.74
short30 Sep 2025 114,312.002 Oct 2025 118,595.002−$4,283.02
long2 Oct 2025 118,595.0020 Oct 2025 108,643.0018−$9,952.22
short20 Oct 2025 108,643.0013 Dec 2025 90,268.4054$18,374.30
long13 Dec 2025 90,268.4020 Dec 2025 88,136.907−$2,131.48
short20 Dec 2025 88,136.907 Jan 2026 93,748.0018−$5,611.02
long7 Jan 2026 93,748.0027 Jan 2026 88,347.1020−$5,400.89
short27 Jan 2026 88,347.107 Mar 2026 68,114.0039$20,233.10
long7 Mar 2026 68,114.0011 Mar 2026 69,948.604$1,834.62
short11 Mar 2026 69,948.6013 Mar 2026 70,541.302−$592.70
long13 Mar 2026 70,541.3030 Mar 2026 66,010.9017−$4,530.41
short30 Mar 2026 66,010.9031 Mar 2026 66,797.401−$786.45
long31 Mar 2026 66,797.401 Apr 2026 68,284.501$1,487.11
short1 Apr 2026 68,284.5013 Apr 2026 70,741.6012−$2,457.07
long13 Apr 2026 70,741.6025 May 2026 77,065.0042$6,323.40
short25 May 2026 77,065.0017 Jul 2026 63,830.2053$13,234.80
long17 Jul 2026 63,830.204 Aug 2026 63,520.0018−$310.20
short4 Aug 2026 63,520.005 Aug 2026 64,106.601−$586.55
long5 Aug 2026 64,106.606 Aug 2026 64,665.201$558.69
short6 Aug 2026 64,665.209 Aug 2026 64,962.603−$297.36
long9 Aug 2026 64,962.6013 Aug 2026 63,480.004−$1,482.61
short13 Aug 2026 63,480.0022 Aug 2026 78,338.009−$14,858.00
long22 Aug 2026 78,338.0017 Sep 2026 76,206.0026−$2,132.03
short17 Sep 2026 76,206.0022 Sep 2026 86,620.005−$10,414.00
long22 Sep 2026 86,620.0015 Oct 2026 81,682.0023−$4,937.99

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
Backtest Signal To Noise this page—v4 strategy+1.7%5735.2%
Follow the Crypto Shorts by xtradernetsmav4 strategyNo trades on this market
buy down and sell high trend 200 sma and ma cross by willi130503smav4 strategyNo trades on this market
Mayer Multiple Strategy by xtradernetsmav4 strategyNo trades on this market
Moving Average Cross Strategy early Closing by Geduldtradersmav4 strategy+73.8%20151.5%
MFI Simple Strategy by OztheWozsmav5 strategy−0.2%283.2%

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 9 msYes 1,000 bars in 41 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.

//@version=4////////////////////////////////////////////////////////////// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/// © HPotter 05/01/2021// The signal-to-noise (S/N) ratio. // And Simple Moving Average.// Thank you for idea BlockchainYahoo//// WARNING:// - For purpose educate only// - This script to change bars colors. ////////////////////////////////////////////////////////////SignalToNoise(length) =>    StN = 0.0    for i = 1 to length-1        StN := StN + (1/close[i])/length    StN := -10*log(StN)strategy(title="Backtest Signal To Noise ", shorttitle="StoN", overlay=false)length = input(title="Days", type=input.integer, defval=21, minval=2)Smooth =  input(title="Smooth", type=input.integer, defval=7, minval=2)reverse = input(false, title="Trade reverse")StN = SignalToNoise(length)SMAStN = sma(StN, Smooth)pos = iff(SMAStN[1] > StN[1] , -1,       iff(SMAStN[1] < StN[1], 1, 0)) possig = iff(reverse and pos == 1, -1,          iff(reverse and pos == -1 , 1, pos))     if (possig == 1)     strategy.entry("Long", strategy.long)if (possig == -1)    strategy.entry("Short", strategy.short)  if (possig == 0)     strategy.close_all()barcolor(possig == -1 ? #b50404: possig == 1 ? #079605 : #0536b3 )plot(StN, title='StN' )plot(SMAStN, title='Smooth', color=#00ff00)