Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

[cache_that_pass] 1m 15m Function - Weighted Standard Deviation

A Pine Script v4 strategy with no technical-analysis calculation. It has 4 order rules, 2 entries among them, and trades long and short with the default settings. Exits use a stop loss and a profit target. Each trade commits 20% of equity and pays 0.075% commission. 3 settings; defaults include Len 20, Stop Loss % 3.11 and Take Profit % 7.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 [cache_that_pass] 1m 15m Function - Weighted Standard Deviation repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 30 of 30 trades.
How did [cache_that_pass] 1m 15m Function - Weighted Standard Deviation do on BTCUSDT 1D with default settings?
−5.25%
From 26 Jan 2024 to 21 Oct 2026, over 100 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Can [cache_that_pass] 1m 15m Function - Weighted Standard Deviation 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 [cache_that_pass] 1m 15m Function - Weighted Standard Deviation use a stop loss?
Yes
strategy.exit sets a stop on line 100, 103.
Does [cache_that_pass] 1m 15m Function - Weighted Standard Deviation run in Zeal Terminal?
Yes
It compiles in 66 ms and runs 1,000 bars in 242 ms, in the browser.

BTCUSDT · 1D · default settings

  • Plot
  • Plot
  • Plot
  • 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 (3)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$9,544$20,253Equity from $10,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
−5.25%
−$524.79
Buy and hold
+102.5%
same period
Closed trades
100
34 won · 66 lost
Profitable
34.0%
of closed trades
Profit factor
0.89
gross profit ÷ gross loss
Max drawdown
10.64%
−$1,063.83

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

  • Note

    1 setting has no label

    In the settings dialog len (line 56) shows an empty name. The labels on this page come from the variable names.

  • 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 sum → math.sum, pow → math.pow, sqrt → math.sqrt, tostring → str.tostring.

v4 → v5

Verified

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

  • Line 3: //@version=4 → //@version=5
  • Line 12: sum → math.sum
  • Line 13: sum → math.sum
  • Line 17: pow → math.pow
  • Line 20: sqrt → math.sqrt
  • Line 22: sqrt → math.sqrt
15 more edits
  • Line 46: pow → math.pow
  • Line 48: sqrt → math.sqrt
  • Line 50: sqrt → math.sqrt
  • Line 81: tostring → str.tostring
  • Line 81: tostring → str.tostring
  • Line 81: tostring → str.tostring
  • Line 81: tostring → str.tostring
  • Line 81: tostring → str.tostring
  • Line 82: tostring → str.tostring
  • Line 82: tostring → str.tostring
  • Line 82: tostring → str.tostring
  • Line 82: tostring → str.tostring
  • Line 82: tostring → str.tostring
  • Line 92: input(type = input.float) → input.float()
  • Line 93: input(type = input.float) → input.float()
⋯// © rumpypumpydumpy   © cache_that_pass-//@version=4+//@version=5strategy("[cache_that_pass] 1m 15m Function - Weighted Standard Deviation", overlay=true, pyramiding=0, default_qty_type=strategy.percent_of_equity, default_qty_value=20, initial_capital=10000, commission_type=strategy.commission.percent, commission_value=0.075)⋯    _xw = _src * _weight-    _sum_weight = sum(_weight, _n)+    _sum_weight = math.sum(_weight, _n)-    _mean = sum(_xw, _n) / _sum_weight+    _mean = math.sum(_xw, _n) / _sum_weight    float _sqerror_sum = 0⋯    for _i = 0 to _n - 1-        _sqerror_sum := _sqerror_sum + pow(_mean - _src[_i], 2) * _weight[_i]+        _sqerror_sum := _sqerror_sum + math.pow(_mean - _src[_i], 2) * _weight[_i]        _nonzero_n := _weight[_i] != 0 ? _nonzero_n + 1 : _nonzero_n    _variance = _sqerror_sum / ((_nonzero_n - 1) * _sum_weight / _nonzero_n)-    _dev = sqrt(_variance)+    _dev = math.sqrt(_variance)    _mse = _sqerror_sum / _sum_weight-    _rmse = sqrt(_mse)+    _rmse = math.sqrt(_mse)    [_mean, _variance, _dev, _mse, _rmse]⋯        for _j = 0 to _n - 1-            _sqerror_sum := _sqerror_sum + pow(_mean - array.get(_a_src, _j), 2) * array.get(_a_weight, _j)+            _sqerror_sum := _sqerror_sum + math.pow(_mean - array.get(_a_src, _j), 2) * array.get(_a_weight, _j)        _variance := _sqerror_sum / ((_nonzero_n - 1) * _sum_weight / _nonzero_n)-        _dev := sqrt(_variance)+        _dev := math.sqrt(_variance)        _mse := _sqerror_sum / _sum_weight-        _rmse := sqrt(_mse)+        _rmse := math.sqrt(_mse)    [_mean, _variance, _dev, _mse, _rmse]⋯// ------------------------------------------------------------------------------series_text = "Mean : " + tostring(m) + "\nVariance : " + tostring(v) + "\nSD : " + tostring(d) + "\nMSE : " + tostring(mse) +  "\nRMSE : " + tostring(rmse)+series_text = "Mean : " + str.tostring(m) + "\nVariance : " + str.tostring(v) + "\nSD : " + str.tostring(d) + "\nMSE : " + str.tostring(mse) +  "\nRMSE : " + str.tostring(rmse)-array_text = "Mean : " + tostring(a_m) + "\nVariance : " + tostring(a_v) + "\nSD : " + tostring(a_d) + "\nMSE : " + tostring(a_mse) +  "\nRMSE : " + tostring(a_rmse)+array_text = "Mean : " + str.tostring(a_m) + "\nVariance : " + str.tostring(a_v) + "\nSD : " + str.tostring(a_d) + "\nMSE : " + str.tostring(a_mse) +  "\nRMSE : " + str.tostring(a_rmse)debug_text = "Volume weighted from time series : \n" + series_text + "\n\nLinearly weighted from arrays : \n" + array_text⋯// User Options to Change Inputs (%)-stopPer = input(3.11, title='Stop Loss %', type=input.float) / 100+stopPer = input.float(3.11, title='Stop Loss %') / 100-takePer = input(7.50, title='Take Profit %', type=input.float) / 100+takePer = input.float(7.50, title='Take Profit %') / 100// Determine where you've entered and in what direction⋯

Clean v5

VerifiedDownload the v5 script

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

  • Line 56: input() → input.int()
⋯// ------------------------------------------------------------------------------len = input(20)+len = input.int(20)// -----------------------------------------------------------------------------⋯

Does it run in Pine Script v6?

Yes

Same 100 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. Both versions were run on Zeal Terminal's engine, and the results are identical. It differs from the v5 version by 1 edit.

Download the v6 script

⋯// © rumpypumpydumpy   © cache_that_pass-//@version=5+//@version=6strategy("[cache_that_pass] 1m 15m Function - Weighted Standard Deviation", overlay=true, pyramiding=0, default_qty_type=strategy.percent_of_equity, default_qty_value=20, initial_capital=10000, commission_type=strategy.commission.percent, commission_value=0.075)⋯

Settings

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

SettingDefaultType and rangeFeeds
Len (no label in the script)20intm v d mse rmse a_m a_v a_d a_mse a_rmse line 71 line 74
Stop Loss %3.11floatlongStop shortStop
Take Profit %7.50floatshortTake longTake

What it calculates

No technical-analysis calculation: the script works on prices and settings directly.

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.

volumevolumeprice dataclosecloseprice datalenLensetting · 20stopPerStop Loss %setting · 3.11takePerTake Profit %setting · 7.50lowlowprice datahighhighprice data_xw, _a_xw_xw · _a_xw2 values_sum_weight_sum_weightvalue_mean_meanvalue_sqerror_sum_sqerror_sumvalue_nonzero_n_nonzero_nvalue_variance_variancevalue_dev_devvalue_mse_msevalue_rmse_rmsevaluem, v, d, mse, rmsem · v +35 valuesa_m, a_v, a_d, a_mse, a_rmsea_m · a_v +35 valuesseries_textseries_textvaluearray_textarray_textvaluedebug_textdebug_textvaluelongStop, shortStoplongStop · shortStop2 valuesshortTake, longTakeshortTake · longTake2 valuesentry:LEOpen LEstrategy.entryentry:SEOpen SEstrategy.entryexit:Close Longexit Close Longstrategy.exitexit:Close Shortexit Close Shortstrategy.exitplot:61plotplotplot:62plotplotplot:63plotplotplot:77plotplotplot:78plotplotplot:79plotplot

Order rules

OrderFires whenBy defaultLine
Open LE longlow <= (m - d * 2)On88
Open SE shorthigh >= (m + d * 2)On90
Exit Close Long stop and limitstrategy.position_size > 0On100
Exit Close Short stop and limitstrategy.position_size < 0On103

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.

30/30trades 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−5.2%+102.5%10034%0.8910.6%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+2.6%+5.5%5864%1.232.4%8 May 2026 – 21 Oct 2026
ETHUSDT 1D−7.7%+9.8%10532%0.8611.9%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h−0.4%+8.4%5754%0.975.2%8 May 2026 – 21 Oct 2026
SOLUSDT 1D−15.4%+16.7%12328%0.7520.9%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h−2.6%+21.5%7446%0.904.9%8 May 2026 – 21 Oct 2026
BNBUSDT 1D+2.8%+148.3%10138%1.068.0%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h−0.4%+17.1%5756%0.973.8%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 market3633%−$332.04
Sideways market3928%−$590.47
Falling market2544%$399.14

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

How bad could the drawdown be?

17.2%

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

0%20%
All 100 trades
SideEntryExitBarsP&L
short28 Feb 2024 57,037.3029 Feb 2024 62,432.101−$192.16
short1 Mar 2024 61,131.003 Mar 2024 63,032.202−$63.95
short9 Apr 2024 71,620.0012 Apr 2024 66,248.503$143.24
long13 Apr 2024 67,116.5014 Apr 2024 63,924.501−$96.87
long15 Apr 2024 65,661.9016 Apr 2024 63,420.001−$69.69
long17 Apr 2024 63,793.4018 Apr 2024 61,277.401−$79.48
long20 Apr 2024 63,818.0029 Apr 2024 61,833.309−$62.77
long1 May 2024 60,672.002 May 2024 58,365.001−$75.61
long3 May 2024 59,060.604 May 2024 63,490.201$139.48
short16 May 2024 66,206.5020 May 2024 68,265.504−$62.87
short21 May 2024 71,446.6011 Jun 2024 66,088.1021$140.82
long12 Jun 2024 67,314.2014 Jun 2024 65,220.802−$63.28
long15 Jun 2024 66,044.0021 Jun 2024 63,990.006−$62.87
long25 Jun 2024 60,293.304 Jul 2024 58,418.209−$62.46
long6 Jul 2024 56,628.808 Jul 2024 54,867.602−$62.05
short16 Jul 2024 64,724.1019 Jul 2024 66,737.003−$61.74
short20 Jul 2024 66,660.0027 Jul 2024 68,733.107−$61.34
long3 Aug 2024 61,498.304 Aug 2024 59,585.701−$60.85
long5 Aug 2024 58,161.006 Aug 2024 54,018.801−$134.85
short24 Aug 2024 64,037.2027 Aug 2024 59,234.403$134.52
long5 Sep 2024 57,970.906 Sep 2024 56,168.001−$60.45
long7 Sep 2024 53,963.009 Sep 2024 58,010.202$135.40
short20 Sep 2024 62,948.0026 Sep 2024 64,905.706−$61.03
long11 Oct 2024 60,326.4014 Oct 2024 64,850.903$136.49
short16 Oct 2024 67,074.1020 Oct 2024 69,160.104−$61.52
short30 Oct 2024 72,736.404 Nov 2024 67,281.205$137.80
short11 Nov 2024 80,370.0012 Nov 2024 88,648.001−$198.79
short6 Dec 2024 96,945.607 Dec 2024 99,960.601−$60.72
short10 Dec 2024 97,276.5011 Dec 2024 100,302.001−$60.32
short12 Dec 2024 101,125.0015 Dec 2024 104,270.003−$59.93
short16 Dec 2024 104,464.0017 Dec 2024 107,713.001−$59.54
short18 Dec 2024 106,134.0019 Dec 2024 98,173.701$133.37
long21 Dec 2024 97,805.4022 Dec 2024 94,763.701−$59.94
long24 Dec 2024 94,881.5030 Dec 2024 91,930.606−$59.55
short7 Jan 2025 102,236.008 Jan 2025 94,567.901$133.57
long14 Jan 2025 94,536.1017 Jan 2025 101,626.003$135.33
short18 Jan 2025 104,077.0020 Jan 2025 107,314.002−$61.00
short21 Jan 2025 102,260.0022 Jan 2025 106,144.001−$73.39
long3 Feb 2025 97,700.6012 Feb 2025 94,662.109−$60.03
long24 Feb 2025 96,258.0025 Feb 2025 91,552.901−$92.17
long26 Feb 2025 88,680.4027 Feb 2025 84,250.101−$93.19
long1 Mar 2025 84,349.902 Mar 2025 90,676.201$131.74
long11 Mar 2025 78,595.9012 Mar 2025 84,490.601$133.68
short3 Apr 2025 82,516.307 Apr 2025 78,430.004$88.75
long7 Apr 2025 78,430.009 Apr 2025 75,990.802−$60.75
long10 Apr 2025 82,615.2011 Apr 2025 79,607.301−$70.17
short22 Apr 2025 87,516.2023 Apr 2025 93,443.001−$127.35
short24 Apr 2025 93,691.101 May 2025 96,604.907−$59.14
short9 May 2025 103,262.0018 May 2025 106,473.009−$58.76
long6 Jun 2025 101,509.009 Jun 2025 109,122.003$131.42
long23 Jun 2025 100,964.0030 Jun 2025 108,536.007$133.35
short3 Jul 2025 108,850.0010 Jul 2025 112,235.007−$60.10
short11 Jul 2025 116,010.0014 Jul 2025 119,618.003−$59.71
short15 Jul 2025 119,841.0031 Jul 2025 117,840.0016$27.65
long31 Jul 2025 117,840.001 Aug 2025 114,175.001−$59.42
long2 Aug 2025 113,298.0011 Aug 2025 121,795.009$133.08
short12 Aug 2025 118,686.0013 Aug 2025 122,377.001−$59.98
short14 Aug 2025 123,306.0019 Aug 2025 114,058.005$134.36
long25 Aug 2025 113,494.0026 Aug 2025 109,964.001−$60.38
long27 Aug 2025 111,763.0029 Aug 2025 108,287.002−$59.99
short12 Sep 2025 115,483.0026 Sep 2025 108,994.0014$100.11
long26 Sep 2025 108,994.001 Oct 2025 117,169.005$135.85
short4 Oct 2025 122,232.006 Oct 2025 126,034.002−$61.22
long11 Oct 2025 112,774.0016 Oct 2025 109,267.005−$60.73
long18 Oct 2025 106,432.0026 Oct 2025 114,414.008$136.03
long5 Nov 2025 101,497.0013 Nov 2025 98,340.708−$61.22
long19 Nov 2025 92,960.8020 Nov 2025 90,069.701−$60.83
long22 Nov 2025 85,129.4027 Nov 2025 91,514.105$136.24
short10 Dec 2025 92,678.8015 Dec 2025 85,727.905$138.45
long16 Dec 2025 86,432.103 Jan 2026 89,995.1018$75.81
short3 Jan 2026 89,995.105 Jan 2026 92,794.002−$62.81
short6 Jan 2026 93,859.7014 Jan 2026 96,778.808−$62.39
short15 Jan 2026 96,951.8020 Jan 2026 89,680.405$139.76
long22 Jan 2026 89,454.7025 Jan 2026 86,672.703−$62.81
long31 Jan 2026 84,260.501 Feb 2026 78,741.101−$128.25
long26 Feb 2026 67,988.0027 Feb 2026 65,873.601−$61.56
long1 Mar 2026 66,973.304 Mar 2026 71,996.303$137.89
short5 Mar 2026 72,666.807 Mar 2026 67,216.802$140.13
short14 Mar 2026 70,930.0015 Mar 2026 73,135.901−$63.06
short17 Mar 2026 74,884.7019 Mar 2026 69,268.302$141.26
long28 Mar 2026 66,407.307 Apr 2026 71,387.8010$143.12
short8 Apr 2026 71,924.2013 Apr 2026 74,161.105−$64.50
short14 Apr 2026 74,418.0017 Apr 2026 76,732.403−$64.08
short18 Apr 2026 77,072.0022 Apr 2026 79,468.904−$63.67
short23 Apr 2026 78,178.204 May 2026 80,609.6011−$63.25
short5 May 2026 79,861.006 May 2026 82,344.701−$62.84
short7 May 2026 81,447.0020 May 2026 76,834.4013$105.59
long20 May 2026 76,834.4023 May 2026 74,444.803−$63.04
long24 May 2026 76,752.0027 May 2026 74,365.003−$62.62
long29 May 2026 73,617.501 Jun 2026 71,328.003−$62.21
long2 Jun 2026 71,408.903 Jun 2026 66,760.801−$126.24
long4 Jun 2026 64,142.805 Jun 2026 62,147.901−$60.98
long25 Jun 2026 61,078.0026 Jun 2026 59,178.501−$60.59
long27 Jun 2026 60,097.3030 Jun 2026 58,228.203−$60.19
short22 Jul 2026 66,556.104 Aug 2026 63,520.0013$81.05
long4 Aug 2026 63,520.0019 Aug 2026 68,284.0015$136.03
short20 Aug 2026 69,334.8021 Aug 2026 73,027.001−$102.95
short22 Aug 2026 78,338.0025 Aug 2026 80,774.403−$60.63
long12 Sep 2026 77,225.7021 Sep 2026 83,017.609$135.60
short22 Sep 2026 86,620.009 Oct 2026 81,754.5017$102.50

Similar scripts

No other indicator or strategy here shares enough of its calculations.

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 66 msYes 1,000 bars in 242 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/// © rumpypumpydumpy   © cache_that_pass//@version=4strategy("[cache_that_pass] 1m 15m Function - Weighted Standard Deviation", overlay=true, pyramiding=0, default_qty_type=strategy.percent_of_equity, default_qty_value=20, initial_capital=10000, commission_type=strategy.commission.percent, commission_value=0.075)f_weighted_sd_from_series(_src, _weight, _n) => //{//  @function: Calculates weighted mean, variance, standard deviation, MSE and RMSE from time series variables//  @parameters://      _src: time series variable of sample values//      _weight: time series of corresponding weight values.//      _n : number of samples    _xw = _src * _weight    _sum_weight = sum(_weight, _n)    _mean = sum(_xw, _n) / _sum_weight    float _sqerror_sum = 0    int _nonzero_n = 0    for _i = 0 to _n - 1        _sqerror_sum := _sqerror_sum + pow(_mean - _src[_i], 2) * _weight[_i]        _nonzero_n := _weight[_i] != 0 ? _nonzero_n + 1 : _nonzero_n    _variance = _sqerror_sum / ((_nonzero_n - 1) * _sum_weight / _nonzero_n)    _dev = sqrt(_variance)    _mse = _sqerror_sum / _sum_weight    _rmse = sqrt(_mse)    [_mean, _variance, _dev, _mse, _rmse]//}// -----------------------------------------------------------------------------f_weighted_sd_from_arrays(_a_src, _a_weight, _n) => //{//  @function: Calculates weighted mean, variance, standard deviation, MSE and RMSE from arrays//  Expects index 0 of the arrays to be the most recent sample and weight values!//  @parameters://      _a_src: array of sample values//      _a_weight: array of corresponding weight values.//      _n : number of samples    float _mean = na, float _variance = na, float _dev = na, float _mse = na    float _rmse = na, float _sqerror_sum = na, float _sum_weight = na    float[] _a_xw = array.new_float(_n)    int _nonzero_n = 0    if array.size(_a_src) >= _n        _sum_weight := 0        _sqerror_sum := 0        for _i = 0 to _n - 1            array.set(_a_xw, _i, array.get(_a_src, _i) * array.get(_a_weight, _i))            _sum_weight := _sum_weight + array.get(_a_weight, _i)            _nonzero_n := array.get(_a_weight, _i) != 0 ? _nonzero_n + 1 : _nonzero_n        _mean := array.sum(_a_xw) / _sum_weight        for _j = 0 to _n - 1            _sqerror_sum := _sqerror_sum + pow(_mean - array.get(_a_src, _j), 2) * array.get(_a_weight, _j)        _variance := _sqerror_sum / ((_nonzero_n - 1) * _sum_weight / _nonzero_n)        _dev := sqrt(_variance)        _mse := _sqerror_sum / _sum_weight        _rmse := sqrt(_mse)    [_mean, _variance, _dev, _mse, _rmse]//}// -----------------------------------------------------------------------------// Example usage : // -----------------------------------------------------------------------------len = input(20)// -----------------------------------------------------------------------------// From series :// -----------------------------------------------------------------------------[m, v, d, mse, rmse] = f_weighted_sd_from_series(close, volume, len)plot(m, color = color.blue)plot(m + d * 2, color = color.blue)plot(m - d * 2, color = color.blue)// -----------------------------------------------------------------------------// -----------------------------------------------------------------------------// From arrays : // -----------------------------------------------------------------------------var float[] a_src = array.new_float()var float[] a_weight = array.new_float()if barstate.isfirst    for i = 1 to len        array.unshift(a_weight, i)array.unshift(a_src, close)if array.size(a_src) > len    array.pop(a_src)[a_m, a_v, a_d, a_mse, a_rmse] = f_weighted_sd_from_arrays(a_src, a_weight, len)plot(a_m, color = color.orange)plot(a_m + a_d * 2, color = color.orange)plot(a_m - a_d * 2, color = color.orange)// -----------------------------------------------------------------------------series_text = "Mean : " + tostring(m) + "\nVariance : " + tostring(v) + "\nSD : " + tostring(d) + "\nMSE : " + tostring(mse) +  "\nRMSE : " + tostring(rmse)array_text = "Mean : " + tostring(a_m) + "\nVariance : " + tostring(a_v) + "\nSD : " + tostring(a_d) + "\nMSE : " + tostring(a_mse) +  "\nRMSE : " + tostring(a_rmse)debug_text = "Volume weighted from time series : \n" + series_text + "\n\nLinearly weighted from arrays : \n" + array_text//debug = label.new(x = bar_index, y = close, text = debug_text, style = label.style_label_left)//.delete(debug[1])//test strategyif low <= (m - d * 2)    strategy.entry("LE", strategy.long)if high >= (m + d * 2)    strategy.entry("SE", strategy.short)// User Options to Change Inputs (%)stopPer = input(3.11, title='Stop Loss %', type=input.float) / 100takePer = input(7.50, title='Take Profit %', type=input.float) / 100// Determine where you've entered and in what directionlongStop = strategy.position_avg_price * (1 - stopPer)shortStop = strategy.position_avg_price * (1 + stopPer)shortTake = strategy.position_avg_price * (1 - takePer)longTake = strategy.position_avg_price * (1 + takePer)if strategy.position_size > 0     strategy.exit(id="Close Long", stop=longStop, limit=longTake)//    strategy.close("LE", when = (longStop) or (longTake), qty_percent = 100)if strategy.position_size < 0     strategy.exit(id="Close Short", stop=shortStop, limit=shortTake)//    strategy.close("SE", when = (shortStop) or (shortTake), qty_percent = 100)