@alphacharts/indicators 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +95 -2
- package/dist/all-DeXJJd7D.js +21 -0
- package/dist/all-DeXJJd7D.js.map +1 -0
- package/dist/all.js +10 -0
- package/dist/all.js.map +1 -0
- package/dist/assets/worker-BrUuzTIJ.js +2 -0
- package/dist/assets/worker-BrUuzTIJ.js.map +1 -0
- package/dist/define-BPvQbaq9.js +472 -0
- package/dist/define-BPvQbaq9.js.map +1 -0
- package/dist/index.js +593 -0
- package/dist/index.js.map +1 -0
- package/dist/registry-CYZuqhXX.js +49 -0
- package/dist/registry-CYZuqhXX.js.map +1 -0
- package/dist/runner-DBP0M8z3.js +229 -0
- package/dist/runner-DBP0M8z3.js.map +1 -0
- package/dist/studies.js +1 -0
- package/dist/tv-volume-7hh6ajKt.js +3457 -0
- package/dist/tv-volume-7hh6ajKt.js.map +1 -0
- package/dist/types/all.d.ts +3 -0
- package/dist/types/chart/studies.d.ts +165 -0
- package/dist/types/define.d.ts +46 -0
- package/dist/types/engine/graph.d.ts +101 -0
- package/dist/types/engine/kernels.d.ts +9 -0
- package/dist/types/engine/study.d.ts +31 -0
- package/dist/types/index.d.ts +12 -0
- package/dist/types/registry.d.ts +7 -0
- package/dist/types/runner.d.ts +82 -0
- package/dist/types/studies/all.d.ts +2 -0
- package/dist/types/studies/cycle.d.ts +7 -0
- package/dist/types/studies/index.d.ts +13 -0
- package/dist/types/studies/ma.d.ts +26 -0
- package/dist/types/studies/math.d.ts +28 -0
- package/dist/types/studies/momentum.d.ts +30 -0
- package/dist/types/studies/overlap.d.ts +14 -0
- package/dist/types/studies/patterns.d.ts +62 -0
- package/dist/types/studies/price.d.ts +6 -0
- package/dist/types/studies/sar.d.ts +2 -0
- package/dist/types/studies/statistic.d.ts +9 -0
- package/dist/types/studies/tv-osc.d.ts +18 -0
- package/dist/types/studies/tv-trend.d.ts +20 -0
- package/dist/types/studies/tv-volume.d.ts +14 -0
- package/dist/types/studies/volatility.d.ts +3 -0
- package/dist/types/studies/volume.d.ts +3 -0
- package/dist/types/types.d.ts +133 -0
- package/dist/types/wasm.d.ts +2 -0
- package/dist/types/worker.d.ts +1 -0
- package/dist/worker.js +8 -0
- package/dist/worker.js.map +1 -0
- package/package.json +69 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Alphabench
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,96 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @alphacharts/indicators
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Technical studies for AlphaCharts: a typed study model, an incremental engine over the core's
|
|
4
|
+
columnar data, a Web Worker runner, chart integration through the core plugin API, and
|
|
5
|
+
210 studies (TA-Lib's catalogue plus TradingView's built-ins).
|
|
6
|
+
|
|
7
|
+
## Use
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { addStudy } from "@alphacharts/indicators";
|
|
11
|
+
import { rsi, macd, bbands } from "@alphacharts/indicators/studies"; // import only what you use
|
|
12
|
+
|
|
13
|
+
const bb = addStudy(chart, candles, bbands, { length: 20 }); // overlay on the candles' pane
|
|
14
|
+
const r = addStudy(chart, candles, rsi, { length: 14 }); // own pane
|
|
15
|
+
addStudy(chart, candles, "obv", {}, { volume: volumeSeries }); // by id: needs registerAllStudies()
|
|
16
|
+
r.setInputs({ length: 21 }); r.setVisible(false); r.remove(); // re-parameterise, hide, remove
|
|
17
|
+
chart.saveState(); chart.restoreState(saved); // studies are in the layout (installStudies(chart) first on a fresh chart)
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
`addStudy` throws on an unknown input, a value outside min/max/step type, or a source that lacks what the
|
|
21
|
+
study needs (volume, OHLC). `await study.ready()` resolves when the last computation is on the chart.
|
|
22
|
+
Subpaths: `.` (engine, runner, plugin), `./studies` (every study as a named export), `./all`
|
|
23
|
+
(`ALL_STUDIES`, `registerAllStudies`), `./worker` (worker entry). Studies are plain objects in group modules
|
|
24
|
+
(`src/studies/*.ts`), so a bundler keeps only those imported (one module per family rather than per study).
|
|
25
|
+
|
|
26
|
+
## How it works
|
|
27
|
+
|
|
28
|
+
- **Model** (`src/types.ts`): `StudyDef { id, name, family, inputs (int/float/bool/source/select with default, min, max,
|
|
29
|
+
step, options), needs, pane: overlay|new, columns, plots (line, histogram, area, band, fill, hline, markers, zigzag),
|
|
30
|
+
build }`. `build(graph, params)` declares nodes and returns the output columns.
|
|
31
|
+
- **Engine** (`src/engine/graph.ts`): every value lives in a Float64Array column; a node writes only bar `i` and reads
|
|
32
|
+
`<= i` of its inputs and `<= i-1` of its own columns. So one code path is the batch (`run(0, n)`), an appended bar
|
|
33
|
+
(`run(n, n+1)`) and a tick revision (re-`run(n-1, n)`): per-bar cost does not depend on the series length
|
|
34
|
+
(O(1) for recursive and running-sum nodes, O(period) for window scans), and a revision recomputes from committed
|
|
35
|
+
state. Warm-up is NaN; absent values never become 0 (except where TA-Lib defines 0, noted in the study's reference).
|
|
36
|
+
setData/prepend on the source recompute fully.
|
|
37
|
+
- **Runner** (`src/runner.ts`): `createRunner(ids)` gives a `WorkerRunner` (arrays transferred, chunks of 65,536
|
|
38
|
+
bars so a `cancel` is serviced within a chunk; protocol documented in the file header) or the `InlineRunner`
|
|
39
|
+
when Workers are unavailable. The worker returns every graph column; the main thread adopts them and keeps
|
|
40
|
+
streaming ticks. Studies not built in (defined at runtime) run inline (`canRun`).
|
|
41
|
+
- **Chart integration** (`src/chart/studies.ts`): one core series per drawn plot (pane = the source's for overlays,
|
|
42
|
+
the lowest free pane otherwise), the rest drawn on the overlay (fills, markers, ZigZag, lines shifted back in time
|
|
43
|
+
or joined across gaps; these do not take part in autoscale). Layout JSON is keyed by study instance id.
|
|
44
|
+
- **WASM** (`src/engine/kernels.ts`, `enableWasm()` from `src/wasm.ts`): optional batch kernels from `@alphacharts/wasm`
|
|
45
|
+
for running sum, variance/stddev, rolling highest/lowest (+ bars) and linear regression, the kernels that won at 1M
|
|
46
|
+
and 10M bars in its benchmark. They are bit-identical to the JS loops (test/wasm.test.ts runs every study both
|
|
47
|
+
ways). Not used: EMA/RMA/WMA (no win), chunked runs (worker), series under 4,096 bars.
|
|
48
|
+
|
|
49
|
+
## Verification
|
|
50
|
+
|
|
51
|
+
Run `pnpm -C packages/indicators test`.
|
|
52
|
+
- **TA-Lib** (`test/talib.test.ts`): fixtures generated offline by `scripts/gen_fixtures.py` (TA-Lib 0.8.2 in a
|
|
53
|
+
Python venv, see below) from `fixtures/cases/*.json` on a seeded 400-bar OHLCV set (`fixtures/dataset.json`;
|
|
54
|
+
3,000 bars of mixed candle shapes for the patterns). Compared at 1e-9 relative (+1e-12 absolute floor), NaN positions
|
|
55
|
+
must be identical; patterns are integers compared exactly. Case flags: `lead` (our study has valid values earlier
|
|
56
|
+
than TA-Lib's first output, e.g. MACD's line before its signal), `abs` (a value that is numerical noise around 0).
|
|
57
|
+
- **TradingView-only** studies: hand-computed fixtures with the arithmetic in the test comments, plus invariants
|
|
58
|
+
(`test/tv-*.test.ts`).
|
|
59
|
+
- **Incremental == batch** (`test/incremental.test.ts`): every study, seeded random appends with random last-bar
|
|
60
|
+
revisions, exact equality.
|
|
61
|
+
- Runner protocol, worker/inline parity and cancellation: `test/runner.test.ts`. Browser: `bench/tests/indicators.spec.ts`.
|
|
62
|
+
|
|
63
|
+
Where a study is not TA-Lib's arithmetic it says so in its `reference` field. Known differences:
|
|
64
|
+
MACD/APO/PPO seed like TA-Lib (fast EMA at the slow EMA's first bar), TradingView seeds at bar 0 (gap < 1e-9 after
|
|
65
|
+
~150 bars); `cmo` defaults to TradingView's window-sum form (`method: "wilder"` is TA-Lib's); the linear regression
|
|
66
|
+
studies are TA-Lib's (checked against numpy polyfit); `ht-trendmode` reports TA-Lib's 0 inside its warm-up;
|
|
67
|
+
`mavp` (TA-Lib's moving average with a per-bar period series) is not implemented: it needs a second input series.
|
|
68
|
+
Not checked against TradingView itself (no access): the TradingView-only studies follow the definitions cited in their
|
|
69
|
+
`reference` field; pivot formulas, Klinger, Schaff, the Relative Volatility form and Fractals tie rules were written
|
|
70
|
+
from memory of TradingView's scripts and are verified only by the hand-computed tests.
|
|
71
|
+
|
|
72
|
+
## Studies (210)
|
|
73
|
+
|
|
74
|
+
- **Overlap (TA-Lib + MAs, bands, SAR)** (17): `sma`, `ema`, `wma`, `dema`, `tema`, `trima`, `kama`, `t3`, `ma`, `bbands`, `bbpb`, `bbw`, `midpoint`, `midprice`, `mama`, `sar`, `sarext`
|
|
75
|
+
- **Momentum (TA-Lib)** (30): `rsi`, `cmo`, `mom`, `roc`, `rocp`, `rocr`, `rocr100`, `trix`, `apo`, `ppo`, `macd`, `macdfix`, `macdext`, `stoch`, `stochf`, `stochrsi`, `willr`, `cci`, `bop`, `mfi`, `ultosc`, `aroon`, `aroonosc`, `adx`, `adxr`, `dx`, `plus-di`, `minus-di`, `plus-dm`, `minus-dm`
|
|
76
|
+
- **Volume (TA-Lib)** (3): `ad`, `adosc`, `obv`
|
|
77
|
+
- **Volatility (TA-Lib)** (3): `trange`, `atr`, `natr`
|
|
78
|
+
- **Price transforms (TA-Lib)** (4): `avgprice`, `medprice`, `typprice`, `wclprice`
|
|
79
|
+
- **Statistics (TA-Lib)** (9): `linearreg`, `linearreg-slope`, `linearreg-intercept`, `linearreg-angle`, `tsf`, `stddev`, `var`, `correl`, `beta`
|
|
80
|
+
- **Math transforms and operators (TA-Lib)** (26): `acos`, `asin`, `atan`, `ceil`, `cos`, `cosh`, `exp`, `floor`, `ln`, `log10`, `sin`, `sinh`, `sqrt`, `tan`, `tanh`, `add`, `sub`, `mult`, `div`, `max`, `min`, `sum`, `maxindex`, `minindex`, `minmax`, `minmaxindex`
|
|
81
|
+
- **Cycle / Hilbert (TA-Lib)** (6): `ht-dcperiod`, `ht-dcphase`, `ht-phasor`, `ht-sine`, `ht-trendline`, `ht-trendmode`
|
|
82
|
+
- **TradingView-only** (51): `smma`, `vwma`, `hma`, `alma`, `lsma`, `mcginley`, `ma-ribbon`, `ma-cross`, `envelopes`, `keltner`, `donchian`, `price-channel`, `chande-kroll-stop`, `linreg-channel`, `median`, `ichimoku`, `supertrend`, `alligator`, `fractals`, `zigzag`, `fisher`, `kst`, `tsi`, `vortex`, `coppock`, `connors-rsi`, `choppiness`, `rvi-vigor`, `rvi-volatility`, `smi-ergodic`, `rank-corr`, `bull-bear-power`, `awesome`, `accelerator`, `mass-index`, `dpo`, `schaff-tc`, `stoch-tv`, `volume`, `volume-osc`, `pvt`, `net-volume`, `elder-force`, `eom`, `chaikin-mf`, `klinger`, `vwap`, `anchored-vwap`, `pivot-points`, `hist-vol`, `adr`
|
|
83
|
+
- **Candlestick patterns (TA-Lib CDL*)** (61): `cdl-<name>` for every TA-Lib pattern, e.g. `cdl-2crows`, `cdl-3blackcrows`, `cdl-3inside`, `cdl-3linestrike`, `cdl-3outside`, ...
|
|
84
|
+
|
|
85
|
+
## Regenerating the TA-Lib fixtures
|
|
86
|
+
|
|
87
|
+
Only needed when a case changes. From `packages/indicators`:
|
|
88
|
+
|
|
89
|
+
```
|
|
90
|
+
python -m venv .venv && . .venv/bin/activate
|
|
91
|
+
pip install TA-Lib numpy # TA-Lib needs the C library (brew install ta-lib)
|
|
92
|
+
pnpm fixtures # python scripts/gen_fixtures.py [group ...]
|
|
93
|
+
python scripts/gen_cdl_dataset.py # only to rebuild fixtures/dataset-cdl.json
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
The fixtures are TA-Lib's output (BSD licence), see `NOTICE` at the repository root.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { $n as e, M as t, Mn as n, Mr as r, Q as i, ar as a, cn as o, d as s, dr as c, fn as l, hr as u, ni as d, un as f } from "./tv-volume-7hh6ajKt.js";
|
|
2
|
+
//#region src/studies/all.ts
|
|
3
|
+
var p = (e) => typeof e == "object" && !!e && "build" in e && "columns" in e && "plots" in e, m = [
|
|
4
|
+
d,
|
|
5
|
+
r,
|
|
6
|
+
u,
|
|
7
|
+
c,
|
|
8
|
+
a,
|
|
9
|
+
e,
|
|
10
|
+
n,
|
|
11
|
+
l,
|
|
12
|
+
f,
|
|
13
|
+
o,
|
|
14
|
+
i,
|
|
15
|
+
t,
|
|
16
|
+
s
|
|
17
|
+
].flatMap((e) => Object.values(e).filter(p));
|
|
18
|
+
//#endregion
|
|
19
|
+
export { m as t };
|
|
20
|
+
|
|
21
|
+
//# sourceMappingURL=all-DeXJJd7D.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"all-DeXJJd7D.js","names":["overlap","momentum","volume","volatility","price","statistic","math","cycle","sar","patterns","tvTrend","tvOsc","tvVolume","statistic_exports","tv_osc_exports","math_exports","momentum_exports","tv_trend_exports","price_exports","patterns_exports","tv_volume_exports","volatility_exports","cycle_exports","volume_exports","overlap_exports","sar_exports","isStudy","x","ALL_STUDIES","m"],"sources":["../src/studies/all.ts"],"sourcesContent":["// Every built-in study, collected from the group modules. Importing this pulls\n// them all in; import single studies from their group module to stay small.\n\nimport type { StudyDef } from \"../types.js\";\nimport * as overlap from \"./overlap.js\";\nimport * as momentum from \"./momentum.js\";\nimport * as volume from \"./volume.js\";\nimport * as volatility from \"./volatility.js\";\nimport * as price from \"./price.js\";\nimport * as statistic from \"./statistic.js\";\nimport * as math from \"./math.js\";\nimport * as cycle from \"./cycle.js\";\nimport * as sar from \"./sar.js\";\nimport * as patterns from \"./patterns.js\";\nimport * as tvTrend from \"./tv-trend.js\";\nimport * as tvOsc from \"./tv-osc.js\";\nimport * as tvVolume from \"./tv-volume.js\";\n\nconst isStudy = (x: unknown): x is StudyDef => typeof x === \"object\" && x !== null && \"build\" in x && \"columns\" in x && \"plots\" in x;\n\nexport const ALL_STUDIES: readonly StudyDef[] = [overlap, momentum, volume, volatility, price, statistic, math, cycle, sar, patterns, tvTrend, tvOsc, tvVolume].flatMap((m) =>\n Object.values(m).filter(isStudy),\n);\n"],"mappings":";;AAkBA,IAAM0B,KAAW,MAA8B,OAAOC,KAAM,cAAYA,KAAc,WAAWA,KAAK,aAAaA,KAAK,WAAWA,GAEtHC,IAAmC;CAAC5B;CAASC;CAAUC;CAAQC;CAAYC;CAAOC;CAAWC;CAAMC;CAAOC;CAAKC;CAAUC;CAASC;CAAOC;AAAQ,CAAC,CAAC,SAAS,MACvK,OAAO,OAAOiB,CAAC,CAAC,CAAC,OAAOH,CAAO,CACjC"}
|
package/dist/all.js
ADDED
package/dist/all.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"all.js","names":["registerStudies","registerAllStudies","ALL_STUDIES"],"sources":["../src/all.ts"],"sourcesContent":["// Everything: the study list and a registrar. Importing this module pulls every\n// study in; import single studies from \"@alphacharts/indicators/studies\" to stay small.\nimport { registerStudies } from \"./registry.js\";\nimport { ALL_STUDIES } from \"./studies/all.js\";\n\nexport { ALL_STUDIES };\nexport function registerAllStudies(): void {\n registerStudies(ALL_STUDIES);\n}\n"],"mappings":";;;AAMA,SAAgBC,IAA2B;CACzC,EAAgBC,CAAW;AAC7B"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
(function(){var e=Object.defineProperty,t=(t,n)=>{let r={};for(var i in t)e(r,i,{get:t[i],enumerable:!0});return n||e(r,Symbol.toStringTag,{value:`Module`}),r};function n(){return null}function r(e,t,n){return!1}var i=class{v;constructor(e){this.v=new Float64Array(e).fill(NaN)}},a=class extends i{run=()=>{}};let o=[`close`,`open`,`high`,`low`,`hl2`,`hlc3`,`ohlc4`,`hlcc4`],s=NaN;var c=class{n=0;cap=0;cols=[];nodes=[];time;open;high;low;close;volume;sources=/* @__PURE__ */ new Map;constructor(e=0){this.cap=e,this.time=this.col(),this.open=this.col(),this.high=this.col(),this.low=this.col(),this.close=this.col(),this.volume=this.col()}col(){let e=new i(this.cap);return this.cols.push(e),e}reserve(e){if(e<=this.cap)return;let t=Math.max(e,Math.ceil(this.cap*1.5),256);for(let e of this.cols){let n=new Float64Array(t).fill(s);n.set(e.v.subarray(0,Math.min(this.n,e.v.length))),e.v=n}this.cap=t}run(e,t){if(t>this.cap)throw RangeError(`graph.run: ${t} bars exceed the reserved ${this.cap}`);for(let n of this.nodes)n.run(e,t)}clear(){for(let e of this.cols)e.v.fill(s,0,this.n);this.n=0}adopt(e,t){if(e.length!==this.cols.length)throw RangeError(`graph.adopt: ${e.length} columns, expected ${this.cols.length}`);this.cols.forEach((t,n)=>t.v=e[n]),this.cap=e[0]?.length??0,this.n=t}node(e){let t=new a(this.cap);return t.run=(n,r)=>e(t,n,r),this.cols.push(t),this.nodes.push(t),t}calc(e){return this.node((t,n,r)=>{let i=t.v;for(let t=n;t<r;t++)i[t]=e(t)})}val(e){return typeof e==`number`?()=>e:t=>e.v[t]}src(e){let t=this.sources.get(e);if(t)return t;let{open:n,high:r,low:i,close:a}=this,o;switch(e){case`close`:o=this.map(a,e=>e);break;case`open`:o=this.map(n,e=>e);break;case`high`:o=this.map(r,e=>e);break;case`low`:o=this.map(i,e=>e);break;case`hl2`:o=this.node((e,t,n)=>{let a=r.v,o=i.v,s=e.v;for(let e=t;e<n;e++)s[e]=(a[e]+o[e])/2});break;case`hlc3`:o=this.node((e,t,n)=>{let o=r.v,s=i.v,c=a.v,l=e.v;for(let e=t;e<n;e++)l[e]=(o[e]+s[e]+c[e])/3});break;case`ohlc4`:o=this.node((e,t,o)=>{let s=n.v,c=r.v,l=i.v,u=a.v,d=e.v;for(let e=t;e<o;e++)d[e]=(s[e]+c[e]+l[e]+u[e])/4});break;case`hlcc4`:o=this.node((e,t,n)=>{let o=r.v,s=i.v,c=a.v,l=e.v;for(let e=t;e<n;e++)l[e]=(o[e]+s[e]+2*c[e])/4});break;default:throw RangeError(`unknown source "${String(e)}"`)}return this.sources.set(e,o),o}map(e,t){return this.node((n,r,i)=>{let a=e.v,o=n.v;for(let e=r;e<i;e++)o[e]=t(a[e])})}map2(e,t,n){let r=this.val(e),i=this.val(t);return this.node((e,t,a)=>{let o=e.v;for(let e=t;e<a;e++)o[e]=n(r(e),i(e))})}add(e,t){return this.map2(e,t,(e,t)=>e+t)}sub(e,t){return this.map2(e,t,(e,t)=>e-t)}mul(e,t){return this.map2(e,t,(e,t)=>e*t)}div(e,t){return this.map2(e,t,(e,t)=>t===0?s:e/t)}max2(e,t){return this.map2(e,t,(e,t)=>e!==e||t!==t?s:e>t?e:t)}min2(e,t){return this.map2(e,t,(e,t)=>e!==e||t!==t?s:e<t?e:t)}abs(e){return this.map(e,Math.abs)}neg(e){return this.map(e,e=>-e)}lag(e,t){return this.node((n,r,i)=>{let a=e.v,o=n.v;for(let e=r;e<i;e++)o[e]=e>=t?a[e-t]:s})}change(e,t=1){return this.node((n,r,i)=>{let a=e.v,o=n.v;for(let e=r;e<i;e++)o[e]=e>=t?a[e]-a[e-t]:s})}validRun(e){return this.node((t,n,r)=>{let i=e.v,a=t.v;for(let e=n;e<r;e++)a[e]=i[e]===i[e]?(e>0?a[e-1]:0)+1:0})}sum(e,t){if(l(t),t===1)return this.map(e,e=>e);let i=this.validRun(e),a=this.col();return this.node((o,c,l)=>{let u=e.v,d=i.v,f=a.v,p=o.v;if(r(u,c,l)){let e=n().sumState(u.subarray(0,l),t);p.set(e.sum),f.set(e.state)}else for(let e=c;e<l;e++){let n=d[e];if(n===0){f[e]=0,p[e]=s;continue}let r=(n>1?f[e-1]:0)+u[e];n>t&&(r-=u[e-t]),f[e]=r,p[e]=n>=t?r:s}})}sma(e,t){let n=this.sum(e,t);return this.map(n,e=>e/t)}smooth(e,t,n){l(t);let r=this.validRun(e);return this.node((i,a,o)=>{let c=e.v,l=r.v,u=i.v;for(let e=a;e<o;e++){let r=l[e];if(r===0){u[e]=s;continue}let i=e>0?u[e-1]:s;if(i===i)u[e]=i+n*(c[e]-i);else if(r>=t){let n=0;for(let r=e-t+1;r<=e;r++)n+=c[r];u[e]=n/t}else u[e]=s}})}ema(e,t){return this.smooth(e,t,2/(t+1))}rma(e,t){return this.smooth(e,t,1/t)}wma(e,t){l(t);let n=this.validRun(e),r=this.col(),i=this.col(),a=t*(t+1)/2;return this.node((o,c,l)=>{let u=e.v,d=n.v,f=r.v,p=i.v,m=o.v;for(let e=c;e<l;e++){let n=d[e];if(n===0){f[e]=0,p[e]=0,m[e]=s;continue}let r=u[e];if(n<t)f[e]=(n>1?f[e-1]:0)+r,p[e]=(n>1?p[e-1]:0)+n*r,m[e]=s;else if(n===t)f[e]=(n>1?f[e-1]:0)+r,p[e]=(n>1?p[e-1]:0)+t*r,m[e]=p[e]/a;else{let n=f[e-1];p[e]=p[e-1]-n+t*r,f[e]=n-u[e-t]+r,m[e]=p[e]/a}}})}highest(e,t){return this.extreme(e,t,!0,!1)}lowest(e,t){return this.extreme(e,t,!1,!1)}highestBars(e,t,n=!1){return this.extreme(e,t,!0,!0,n)}lowestBars(e,t,n=!1){return this.extreme(e,t,!1,!0,n)}extreme(e,t,i,a,o=!1){l(t);let c=this.validRun(e);return this.node((l,u,d)=>{let f=e.v,p=c.v,m=l.v;if(!o&&r(f,u,d)){let e=n(),r=f.subarray(0,d);m.set(a?i?e.highestBars(r,t):e.lowestBars(r,t):i?e.highest(r,t):e.lowest(r,t))}else for(let e=u;e<d;e++){if(p[e]<t){m[e]=s;continue}let n=f[e],r=0;for(let a=1;a<t;a++){let t=f[e-a];(i?o?t>=n:t>n:o?t<=n:t<n)&&(n=t,r=a)}m[e]=a?r:n}})}variance(e,t){l(t);let i=this.sma(e,t);return this.node((a,o,c)=>{let l=e.v,u=i.v,d=a.v;if(r(l,o,c))d.set(n().variance(l.subarray(0,c),t));else for(let e=o;e<c;e++){let n=u[e];if(n!==n){d[e]=s;continue}let r=0;for(let i=e-t+1;i<=e;i++){let e=l[i]-n;r+=e*e}d[e]=r/t}})}stdev(e,t){return this.map(this.variance(e,t),Math.sqrt)}linreg(e,t){if(!Number.isInteger(t)||t<2)throw RangeError(`linreg: period must be an integer >= 2, got ${t}`);let i=this.validRun(e),a=t*(t-1)/2,o=t*(t*(t-1)*(2*t-1)/6)-a*a,c=this.col(),l=this.col();return{value:this.node((u,d,f)=>{let p=e.v,m=i.v,h=c.v,g=l.v,_=u.v;if(r(p,d,f)){let e=n().linreg(p.subarray(0,f),t);_.set(e.value),h.set(e.slope),g.set(e.intercept)}else for(let e=d;e<f;e++){if(m[e]<t){h[e]=s,g[e]=s,_[e]=s;continue}let n=0,r=0;for(let i=0;i<t;i++){let a=p[e-t+1+i];n+=a,r+=i*a}let i=(t*r-a*n)/o,c=(n-i*a)/t;h[e]=i,g[e]=c,_[e]=c+i*(t-1)}}),slope:this.alias(c),intercept:this.alias(l)}}alias(e){return this.node((t,n,r)=>{let i=e.v,a=t.v;for(let e=n;e<r;e++)a[e]=i[e]})}tr(){let{high:e,low:t,close:n}=this;return this.node((r,i,a)=>{let o=e.v,c=t.v,l=n.v,u=r.v;for(let e=i;e<a;e++){if(e===0){u[e]=s;continue}let t=l[e-1],n=o[e]-c[e],r=Math.abs(o[e]-t),i=Math.abs(c[e]-t);u[e]=n>r?n>i?n:i:r>i?r:i}})}atr(e){return this.rma(this.tr(),e)}};function l(e){if(!Number.isInteger(e)||e<1)throw RangeError(`period must be a positive integer, got ${e}`)}function u(e,t={}){let n={},r=new Set(e.inputs.map(e=>e.key));for(let n of Object.keys(t))if(!r.has(n))throw RangeError(`${e.id}: unknown input "${n}" (known: ${[...r].join(`, `)||`none`})`);for(let r of e.inputs){let i=t[r.key]??r.default;d(e.id,r,i),n[r.key]=i}return n}function d(e,t,n){let r=`${e}.${t.key}`;switch(t.type){case`int`:case`float`:if(typeof n!=`number`||!Number.isFinite(n))throw TypeError(`${r}: expected a finite number, got ${String(n)}`);if(t.type===`int`&&!Number.isInteger(n))throw RangeError(`${r}: expected an integer, got ${n}`);if(t.min!==void 0&&n<t.min)throw RangeError(`${r}: ${n} is below the minimum ${t.min}`);if(t.max!==void 0&&n>t.max)throw RangeError(`${r}: ${n} is above the maximum ${t.max}`);return;case`bool`:if(typeof n!=`boolean`)throw TypeError(`${r}: expected a boolean, got ${String(n)}`);return;case`source`:case`select`:{let e=t.type===`source`?t.options??o:t.options;if(typeof n!=`string`||!e?.includes(n))throw RangeError(`${r}: "${String(n)}" is not one of ${e?.join(`, `)??`(none)`}`)}}}var f=class{def;graph;outputs;params;constructor(e,t={}){if(this.def=e,this.params=u(e,t),this.graph=new c,this.outputs=e.build(this.graph,this.params),this.outputs.length!==e.columns.length)throw Error(`${e.id}: build returned ${this.outputs.length} columns, declared ${e.columns.length}`)}get length(){return this.graph.n}load(e){let t=this.graph,n=e.time.length;this.requireColumns(e),t.clear(),t.reserve(n),t.time.v.set(e.time),t.close.v.set(e.close),e.open&&t.open.v.set(e.open),e.high&&t.high.v.set(e.high),e.low&&t.low.v.set(e.low),e.volume&&t.volume.v.set(e.volume),t.n=n,t.run(0,n)}async loadChunked(e,t,n,r){let i=this.graph,a=e.time.length;this.requireColumns(e),i.clear(),i.reserve(a),i.time.v.set(e.time),i.close.v.set(e.close),e.open&&i.open.v.set(e.open),e.high&&i.high.v.set(e.high),e.low&&i.low.v.set(e.low),e.volume&&i.volume.v.set(e.volume),i.n=a;for(let e=0;e<a;e+=t){if(r())return!1;i.run(e,Math.min(a,e+t)),await n()}return!r()}push(e){let t=this.graph,n=t.n;if(n>0&&!(e.time>t.time.v[n-1]))throw RangeError(`push: time ${e.time} is not after the last bar ${t.time.v[n-1]}`);t.reserve(n+1),this.write(n,e),t.n=n+1,t.run(n,n+1)}reviseLast(e){let t=this.graph,n=t.n-1;if(n<0)throw RangeError(`reviseLast: no bars`);if(e.time!==t.time.v[n])throw RangeError(`reviseLast: time ${e.time} differs from the last bar ${t.time.v[n]}`);this.write(n,e),t.run(n,n+1)}column(e){return this.outputs[e].v.subarray(0,this.graph.n)}write(e,t){let n=this.graph;n.time.v[e]=t.time,n.open.v[e]=t.open,n.high.v[e]=t.high,n.low.v[e]=t.low,n.close.v[e]=t.close,n.volume.v[e]=t.volume}requireColumns(e){let t=e.time.length,n=this.def.needs,r=(e,n)=>{if(!n)throw TypeError(`${this.def.id} needs ${e} bars`);if(n.length!==t)throw RangeError(`${this.def.id}: ${e} has ${n.length} rows, time has ${t}`)};if(r(`close`,e.close),n!==`value`)for(let t of[`open`,`high`,`low`])r(t,e[t]);n===`ohlcv`&&r(`volume`,e.volume)}};let p=()=>new Promise(e=>setTimeout(e,0));function m(e,t){let n=/* @__PURE__ */ new Set;return r=>{let i=r;i.type===`cancel`?n.add(i.id):i.type===`run`&&(async()=>{try{let r=t(i.studyId);if(!r)throw Error(`unknown study "${i.studyId}"`);let a=new f(r,i.params??{});if(!await a.loadChunked(i.bars,65536,p,()=>n.has(i.id))){e({type:`cancelled`,id:i.id});return}let o=a.graph.cols.map(e=>e.v);e({type:`result`,id:i.id,n:a.length,buffers:o},o.map(e=>e.buffer))}catch(t){e({type:`error`,id:i.id,message:t instanceof Error?t.message:String(t)})}finally{n.delete(i.id)}})()}}let h=(e,t,n=1,r=1e4,i=e)=>({key:e,label:i,type:`int`,default:t,min:n,max:r,step:1}),g=(e,t,n=-1e9,r=1e9,i=.1,a=e)=>({key:e,label:a,type:`float`,default:t,min:n,max:r,step:i}),_=(e,t,n=e)=>({key:e,label:n,type:`bool`,default:t}),v=(e,t,n,r=e)=>({key:e,label:r,type:`select`,default:t,options:n}),y=(e=`close`,t=`source`)=>({key:t,label:t,type:`source`,default:e,options:o}),b={blue:`#2962FF`,orange:`#FF6D00`,red:`#F23645`,green:`#089981`,purple:`#9C27B0`,teal:`#00897B`,yellow:`#FBC02D`,pink:`#E91E63`,gray:`#787B86`,lime:`#8BC34A`,cyan:`#00BCD4`,brown:`#795548`},x=(e,t,n={})=>({kind:`line`,key:n.key??e,title:n.title??e,col:e,color:t,...n.width!==void 0&&{width:n.width},...n.style&&{style:n.style},...n.offset!==void 0&&{offset:n.offset},...n.connect&&{connect:!0}}),S=(e,t,n,r={})=>({kind:`histogram`,key:r.key??e,title:r.title??e,col:e,color:t,...n&&{colorDown:n}}),C=(e,t,n,r,i,a=e)=>({kind:`band`,key:e,title:a,upper:t,lower:n,color:r,fill:i}),w=(e,t,n,r,i=e)=>({kind:`fill`,key:e,title:i,a:t,b:n,color:r}),T=(e,t,n=b.gray,r=`dashed`)=>({kind:`hline`,key:e,title:e,value:t,color:n,style:r}),E=(e,t,n,r,i={})=>({kind:`markers`,key:i.key??e,title:i.title??e,col:e,shape:t,position:n,color:r,...i.offset!==void 0&&{offset:i.offset},...i.text&&{text:!0}});function D(e){return e}let ee=[`sma`,`ema`,`wma`,`rma`,`dema`,`tema`,`trima`,`kama`,`t3`];function te(e,t,n,r=2,i=30){let a=e.map2(t,e.lag(t,1),(e,t)=>Math.abs(e-t)),o=e.sum(a,n),s=e.lag(t,n),c=2/(r+1),l=2/(i+1),u=e.calc(e=>{let n=o.v[e],r=t.v[e],i=s.v[e];if(n!==n||r!==r||i!==i)return NaN;let a=((n<=0?0:Math.abs(r-i)/n)*(c-l)+l)**2,d=e>0?u.v[e-1]:NaN,f=d===d?d:t.v[e-1];return f+a*(r-f)});return u}function ne(e,t,n,r=.7){let i=e.ema(t,n),a=[i];for(let t=1;t<6;t++)a.push(i=e.ema(i,n));let o=r*r,s=o*r,c=-s,l=3*o+3*s,u=-6*o-3*r-3*s,d=1+3*r+s+3*o,[,,f,p,m,h]=a;return e.calc(e=>c*h.v[e]+l*m.v[e]+u*p.v[e]+d*f.v[e])}function re(e,t,n){let r=e.ema(t,n),i=e.ema(r,n);return e.calc(e=>2*r.v[e]-i.v[e])}function ie(e,t,n){let r=e.ema(t,n),i=e.ema(r,n),a=e.ema(i,n);return e.calc(e=>3*r.v[e]-3*i.v[e]+a.v[e])}function ae(e,t,n){return n%2==1?e.sma(e.sma(t,(n+1)/2),(n+1)/2):e.sma(e.sma(t,n/2),n/2+1)}function oe(e,t,n,r,i){let a=e.validRun(t);return e.node((e,o,s)=>{let c=t.v,l=a.v,u=i.v,d=e.v;for(let e=o;e<s;e++){let t=e>0?d[e-1]:NaN;if(t===t&&c[e]===c[e])d[e]=t+r*(c[e]-t);else if(u[e]===u[e]&&l[e]>=n){let t=0;for(let r=e-n+1;r<=e;r++)t+=c[r];d[e]=t/n}else d[e]=NaN}})}function se(e,t,n){let r=e.calc(e=>{let i=t.v[e];if(i!==i)return NaN;let a=e>0?r.v[e-1]:NaN;return a===a?a+n*(i-a):i});return r}function ce(e,t,n,r){switch(t){case`sma`:return e.sma(n,r);case`ema`:return e.ema(n,r);case`wma`:return e.wma(n,r);case`rma`:return e.rma(n,r);case`dema`:return re(e,n,r);case`tema`:return ie(e,n,r);case`trima`:return ae(e,n,r);case`kama`:return te(e,n,r);case`t3`:return ne(e,n,r)}}function le(e,t,n,r,i){return t===`ema`?oe(e,n,r,2/(r+1),i):ce(e,t,n,r)}var ue=/* @__PURE__ */ t({bbands:()=>be,bbpb:()=>xe,bbw:()=>Se,dema:()=>me,ema:()=>fe,kama:()=>_e,ma:()=>ye,midpoint:()=>Ce,midprice:()=>we,sma:()=>de,t3:()=>ve,tema:()=>he,trima:()=>ge,wma:()=>pe});let O=e=>h(`length`,e,1,5e3),de=D({id:`sma`,name:`Simple Moving Average`,family:`overlap`,needs:`value`,pane:`overlay`,inputs:[O(9),y()],columns:[`sma`],plots:[x(`sma`,b.blue)],label:e=>`${e.length}`,build:(e,t)=>[e.sma(e.src(t.source),t.length)],reference:`TA-Lib SMA`}),fe=D({id:`ema`,name:`Exponential Moving Average`,family:`overlap`,needs:`value`,pane:`overlay`,inputs:[O(9),y()],columns:[`ema`],plots:[x(`ema`,b.orange)],label:e=>`${e.length}`,build:(e,t)=>[e.ema(e.src(t.source),t.length)],reference:`TA-Lib EMA`}),pe=D({id:`wma`,name:`Weighted Moving Average`,family:`overlap`,needs:`value`,pane:`overlay`,inputs:[O(9),y()],columns:[`wma`],plots:[x(`wma`,b.green)],label:e=>`${e.length}`,build:(e,t)=>[e.wma(e.src(t.source),t.length)],reference:`TA-Lib WMA`}),me=D({id:`dema`,name:`Double Exponential Moving Average`,family:`overlap`,needs:`value`,pane:`overlay`,inputs:[O(9),y()],columns:[`dema`],plots:[x(`dema`,b.teal)],label:e=>`${e.length}`,build:(e,t)=>[re(e,e.src(t.source),t.length)],reference:`TA-Lib DEMA`}),he=D({id:`tema`,name:`Triple Exponential Moving Average`,family:`overlap`,needs:`value`,pane:`overlay`,inputs:[O(9),y()],columns:[`tema`],plots:[x(`tema`,b.pink)],label:e=>`${e.length}`,build:(e,t)=>[ie(e,e.src(t.source),t.length)],reference:`TA-Lib TEMA`}),ge=D({id:`trima`,name:`Triangular Moving Average`,family:`overlap`,needs:`value`,pane:`overlay`,inputs:[O(30),y()],columns:[`trima`],plots:[x(`trima`,b.cyan)],label:e=>`${e.length}`,build:(e,t)=>[ae(e,e.src(t.source),t.length)],reference:`TA-Lib TRIMA`}),_e=D({id:`kama`,name:`Kaufman Adaptive Moving Average`,family:`overlap`,needs:`value`,pane:`overlay`,inputs:[O(10),h(`fast`,2,1,1e3),h(`slow`,30,2,5e3),y()],columns:[`kama`],plots:[x(`kama`,b.lime)],label:e=>`${e.length}`,build:(e,t)=>{if(t.fast>=t.slow)throw RangeError(`kama: fast (${t.fast}) must be below slow (${t.slow})`);return[te(e,e.src(t.source),t.length,t.fast,t.slow)]},reference:`TA-Lib KAMA (fast/slow limits 2 and 30)`}),ve=D({id:`t3`,name:`Tillson T3`,family:`overlap`,needs:`value`,pane:`overlay`,inputs:[O(5),g(`vfactor`,.7,0,1,.1),y()],columns:[`t3`],plots:[x(`t3`,b.brown)],label:e=>`${e.length}, ${e.vfactor}`,build:(e,t)=>[ne(e,e.src(t.source),t.length,t.vfactor)],reference:`TA-Lib T3`}),ye=D({id:`ma`,name:`Moving Average`,family:`overlap`,needs:`value`,pane:`overlay`,inputs:[O(30),y(),v(`type`,`sma`,ee)],columns:[`ma`],plots:[x(`ma`,b.blue)],label:e=>`${e.type.toUpperCase()} ${e.length}`,build:(e,t)=>[ce(e,t.type,e.src(t.source),t.length)],reference:`TA-Lib MA (types SMA, EMA, WMA, DEMA, TEMA, TRIMA, KAMA, T3; RMA is Wilder's)`}),be=D({id:`bbands`,name:`Bollinger Bands`,family:`overlap`,needs:`value`,pane:`overlay`,inputs:[O(20),y(),g(`multUp`,2,0,100,.1),g(`multDn`,2,0,100,.1),v(`maType`,`sma`,ee)],columns:[`upper`,`middle`,`lower`],plots:[C(`band`,`upper`,`lower`,b.blue,`rgba(41,98,255,0.10)`,`Bands`),x(`middle`,b.orange)],label:e=>`${e.length}, ${e.multUp}`,build:(e,t)=>{let n=e.src(t.source),r=ce(e,t.maType,n,t.length),i=e.stdev(n,t.length);return[e.calc(e=>r.v[e]+t.multUp*i.v[e]),r,e.calc(e=>r.v[e]-t.multDn*i.v[e])]},reference:`TA-Lib BBANDS (population standard deviation)`}),xe=D({id:`bbpb`,name:`Bollinger Bands %B`,family:`overlap`,needs:`value`,pane:`new`,inputs:[O(20),y(),g(`mult`,2,0,100,.1)],columns:[`pb`],plots:[x(`pb`,b.teal,{title:`%B`}),T(`upper`,1),T(`lower`,0),T(`middle`,.5,b.gray,`dotted`)],label:e=>`${e.length}, ${e.mult}`,build:(e,t)=>{let n=e.src(t.source),r=e.sma(n,t.length),i=e.stdev(n,t.length);return[e.calc(e=>{let a=2*t.mult*i.v[e];return a===0?NaN:(n.v[e]-(r.v[e]-t.mult*i.v[e]))/a})]},reference:`TradingView Bollinger Bands %B = (source - lower) / (upper - lower)`}),Se=D({id:`bbw`,name:`Bollinger Bands Width`,family:`overlap`,needs:`value`,pane:`new`,inputs:[O(20),y(),g(`mult`,2,0,100,.1)],columns:[`bbw`],plots:[x(`bbw`,b.blue,{title:`BBW`})],label:e=>`${e.length}, ${e.mult}`,build:(e,t)=>{let n=e.src(t.source),r=e.sma(n,t.length),i=e.stdev(n,t.length);return[e.calc(e=>2*t.mult*i.v[e]/r.v[e])]},reference:`Pine ta.bbw = ((basis + dev) - (basis - dev)) / basis`}),Ce=D({id:`midpoint`,name:`MidPoint over period`,family:`overlap`,needs:`value`,pane:`overlay`,inputs:[O(14),y()],columns:[`midpoint`],plots:[x(`midpoint`,b.purple)],label:e=>`${e.length}`,build:(e,t)=>{let n=e.src(t.source),r=e.highest(n,t.length),i=e.lowest(n,t.length);return[e.calc(e=>(r.v[e]+i.v[e])/2)]},reference:`TA-Lib MIDPOINT`}),we=D({id:`midprice`,name:`Midpoint Price over period`,family:`overlap`,needs:`ohlc`,pane:`overlay`,inputs:[O(14)],columns:[`midprice`],plots:[x(`midprice`,b.purple)],label:e=>`${e.length}`,build:(e,t)=>{let n=e.highest(e.high,t.length),r=e.lowest(e.low,t.length);return[e.calc(e=>(n.v[e]+r.v[e])/2)]},reference:`TA-Lib MIDPRICE`});var Te=/* @__PURE__ */ t({adx:()=>ot,adxr:()=>st,apo:()=>Le,aroon:()=>tt,aroonosc:()=>nt,bop:()=>Qe,cci:()=>Ze,cmo:()=>De,dx:()=>ct,macd:()=>Ve,macdext:()=>We,macdfix:()=>He,mfi:()=>$e,minusDi:()=>dt,minusDm:()=>pt,mom:()=>Oe,plusDi:()=>ut,plusDm:()=>ft,ppo:()=>Re,roc:()=>Ae,rocp:()=>je,rocr:()=>Me,rocr100:()=>Ne,rsi:()=>Ee,stoch:()=>qe,stochf:()=>Je,stochrsi:()=>Ye,trix:()=>Pe,ultosc:()=>et,willr:()=>Xe});let k=(e,t=1)=>h(`length`,e,t,5e3),Ee=D({id:`rsi`,name:`Relative Strength Index`,family:`momentum`,needs:`value`,pane:`new`,inputs:[k(14),y()],columns:[`rsi`],plots:[x(`rsi`,b.purple),T(`upper`,70),T(`lower`,30),T(`middle`,50,b.gray,`dotted`)],label:e=>`${e.length}`,build:(e,t)=>{let n=e.change(e.src(t.source),1),r=e.rma(e.map(n,e=>e>0?e:e===e?0:NaN),t.length),i=e.rma(e.map(n,e=>e<0?-e:e===e?0:NaN),t.length);return[e.map2(r,i,(e,t)=>e+t===0?0:100*e/(e+t))]},reference:"TA-Lib RSI (Wilder smoothing, seeded with the mean of the first `length` changes)"}),De=D({id:`cmo`,name:`Chande Momentum Oscillator`,family:`momentum`,needs:`value`,pane:`new`,inputs:[k(9),y(),v(`method`,`sum`,[`sum`,`wilder`])],columns:[`cmo`],plots:[x(`cmo`,b.blue),T(`upper`,50),T(`lower`,-50),T(`zero`,0,b.gray,`dotted`)],label:e=>`${e.length}`,build:(e,t)=>{let n=e.change(e.src(t.source),1),r=e.map(n,e=>e>0?e:e===e?0:NaN),i=e.map(n,e=>e<0?-e:e===e?0:NaN),[a,o]=t.method===`wilder`?[e.rma(r,t.length),e.rma(i,t.length)]:[e.sum(r,t.length),e.sum(i,t.length)];return[e.map2(a,o,(e,t)=>e+t===0?0:100*(e-t)/(e+t))]},reference:`method sum = TradingView ta.cmo (window sums); method wilder = TA-Lib CMO`}),Oe=D({id:`mom`,name:`Momentum`,family:`momentum`,needs:`value`,pane:`new`,inputs:[k(10),y()],columns:[`mom`],plots:[x(`mom`,b.blue),T(`zero`,0,b.gray,`dotted`)],label:e=>`${e.length}`,build:(e,t)=>[e.change(e.src(t.source),t.length)],reference:`TA-Lib MOM`}),ke=(e,t,n,r,i)=>D({id:e,name:t,family:`momentum`,needs:`value`,pane:`new`,inputs:[k(e===`roc`?9:10),y()],columns:[e],plots:[x(e,b.orange),...i===void 0?[]:[T(`base`,i,b.gray,`dotted`)]],label:e=>`${e.length}`,build:(e,t)=>{let r=e.src(t.source),i=e.lag(r,t.length);return[e.map2(r,i,(e,t)=>t===0?NaN:n(e,t))]},reference:r}),Ae=ke(`roc`,`Rate of Change`,(e,t)=>(e-t)/t*100,`TA-Lib ROC = (x / x[n] - 1) * 100`,0),je=ke(`rocp`,`Rate of Change Percentage`,(e,t)=>(e-t)/t,`TA-Lib ROCP = (x - x[n]) / x[n]`,0),Me=ke(`rocr`,`Rate of Change Ratio`,(e,t)=>e/t,`TA-Lib ROCR = x / x[n]`,1),Ne=ke(`rocr100`,`Rate of Change Ratio 100 scale`,(e,t)=>e/t*100,`TA-Lib ROCR100 = x / x[n] * 100`,100),Pe=D({id:`trix`,name:`TRIX`,family:`momentum`,needs:`value`,pane:`new`,inputs:[k(18),y()],columns:[`trix`],plots:[x(`trix`,b.red),T(`zero`,0,b.gray,`dotted`)],label:e=>`${e.length}`,build:(e,t)=>{let n=e.ema(e.ema(e.ema(e.src(t.source),t.length),t.length),t.length);return[e.map2(n,e.lag(n,1),(e,t)=>t===0?NaN:(e/t-1)*100)]},reference:`TA-Lib TRIX = 1-bar ROC (percent) of a triple-smoothed EMA`}),Fe=(e,t=`maType`)=>v(t,e,ee);function Ie(e,t,n,r,i,a=!1){let o=ce(e,i,t,r);return[a?le(e,i,t,n,o):ce(e,i,t,n),o]}let Le=D({id:`apo`,name:`Absolute Price Oscillator`,family:`momentum`,needs:`value`,pane:`new`,inputs:[h(`fast`,12,1,5e3),h(`slow`,26,2,5e3),y(),Fe(`ema`)],columns:[`apo`],plots:[x(`apo`,b.blue),T(`zero`,0,b.gray,`dotted`)],label:e=>`${e.fast}, ${e.slow}`,build:(e,t)=>{if(t.fast>=t.slow)throw RangeError(`apo: fast (${t.fast}) must be below slow (${t.slow})`);let[n,r]=Ie(e,e.src(t.source),t.fast,t.slow,t.maType);return[e.sub(n,r)]},reference:`TA-Lib APO (fast average starts at the slow average's first bar)`}),Re=D({id:`ppo`,name:`Percentage Price Oscillator`,family:`momentum`,needs:`value`,pane:`new`,inputs:[h(`fast`,12,1,5e3),h(`slow`,26,2,5e3),h(`signal`,9,1,5e3),y(),Fe(`ema`)],columns:[`ppo`,`signal`,`histogram`],plots:[S(`histogram`,b.green,b.red),x(`ppo`,b.blue),x(`signal`,b.orange)],label:e=>`${e.fast}, ${e.slow}, ${e.signal}`,build:(e,t)=>{if(t.fast>=t.slow)throw RangeError(`ppo: fast (${t.fast}) must be below slow (${t.slow})`);let[n,r]=Ie(e,e.src(t.source),t.fast,t.slow,t.maType),i=e.map2(n,r,(e,t)=>t===0?NaN:(e-t)/t*100),a=e.ema(i,t.signal);return[i,a,e.sub(i,a)]},reference:`TA-Lib PPO (line only; the signal EMA and histogram follow TradingView's Price Oscillator)`}),ze=[`macd`,`signal`,`histogram`],Be=[S(`histogram`,b.green,b.red),x(`macd`,b.blue),x(`signal`,b.orange)],Ve=D({id:`macd`,name:`MACD`,family:`momentum`,needs:`value`,pane:`new`,inputs:[h(`fast`,12,1,5e3),h(`slow`,26,2,5e3),h(`signal`,9,1,5e3),y()],columns:ze,plots:Be,label:e=>`${e.fast}, ${e.slow}, ${e.signal}`,build:(e,t)=>{if(t.fast>=t.slow)throw RangeError(`macd: fast (${t.fast}) must be below slow (${t.slow})`);let[n,r]=Ie(e,e.src(t.source),t.fast,t.slow,`ema`,!0),i=e.sub(n,r),a=e.ema(i,t.signal);return[i,a,e.sub(i,a)]},reference:`TA-Lib MACD (the fast EMA is seeded at the slow EMA's first bar; TradingView seeds it at bar 0, the difference decays below 1e-9 within ~150 bars)`}),He=D({id:`macdfix`,name:`MACD Fix 12/26`,family:`momentum`,needs:`value`,pane:`new`,inputs:[h(`signal`,9,1,5e3),y()],columns:ze,plots:Be,label:e=>`${e.signal}`,build:(e,t)=>{let n=e.src(t.source),r=e.smooth(n,26,.075),i=Ue(e,n,12,.15,r),a=e.sub(i,r),o=e.ema(a,t.signal);return[a,o,e.sub(a,o)]},reference:`TA-Lib MACDFIX: fixed 12/26 with smoothing constants 0.15 and 0.075`});function Ue(e,t,n,r,i){return oe(e,t,n,r,i)}let We=D({id:`macdext`,name:`MACD with controllable MA type`,family:`momentum`,needs:`value`,pane:`new`,inputs:[h(`fast`,12,1,5e3),h(`slow`,26,2,5e3),h(`signal`,9,1,5e3),y(),Fe(`ema`,`fastType`),Fe(`ema`,`slowType`),Fe(`ema`,`signalType`)],columns:ze,plots:Be,label:e=>`${e.fast}, ${e.slow}, ${e.signal}`,build:(e,t)=>{if(t.fast>=t.slow)throw RangeError(`macdext: fast (${t.fast}) must be below slow (${t.slow})`);let n=e.src(t.source),r=ce(e,t.slowType,n,t.slow),i=le(e,t.fastType,n,t.fast,r),a=e.sub(i,r),o=ce(e,t.signalType,a,t.signal);return[a,o,e.sub(a,o)]},reference:`TA-Lib MACDEXT`});function Ge(e,t,n,r,i){let a=e.highest(n,i),o=e.lowest(r,i);return e.calc(e=>{let n=a.v[e]-o.v[e];return n===n?n===0?0:100*(t.v[e]-o.v[e])/n:NaN})}let Ke=[x(`k`,b.blue,{title:`%K`}),x(`d`,b.orange,{title:`%D`}),T(`upper`,80),T(`lower`,20)],qe=D({id:`stoch`,name:`Stochastic`,family:`momentum`,needs:`ohlc`,pane:`new`,inputs:[h(`kLength`,14,1,5e3),h(`kSmooth`,1,1,5e3),h(`dLength`,3,1,5e3),Fe(`sma`,`kType`),Fe(`sma`,`dType`)],columns:[`k`,`d`],plots:Ke,label:e=>`${e.kLength}, ${e.kSmooth}, ${e.dLength}`,build:(e,t)=>{let n=ce(e,t.kType,Ge(e,e.close,e.high,e.low,t.kLength),t.kSmooth);return[n,ce(e,t.dType,n,t.dLength)]},reference:`TA-Lib STOCH (slow %K = MA of fast %K); defaults are TradingView's 14, 1, 3`}),Je=D({id:`stochf`,name:`Stochastic Fast`,family:`momentum`,needs:`ohlc`,pane:`new`,inputs:[h(`kLength`,5,1,5e3),h(`dLength`,3,1,5e3),Fe(`sma`,`dType`)],columns:[`k`,`d`],plots:Ke,label:e=>`${e.kLength}, ${e.dLength}`,build:(e,t)=>{let n=Ge(e,e.close,e.high,e.low,t.kLength);return[n,ce(e,t.dType,n,t.dLength)]},reference:`TA-Lib STOCHF`}),Ye=D({id:`stochrsi`,name:`Stochastic RSI`,family:`momentum`,needs:`value`,pane:`new`,inputs:[h(`rsiLength`,14,1,5e3),h(`stochLength`,14,1,5e3),h(`kSmooth`,3,1,5e3),h(`dSmooth`,3,1,5e3),y()],columns:[`raw`,`k`,`d`],plots:[x(`k`,b.blue,{title:`%K`}),x(`d`,b.orange,{title:`%D`}),T(`upper`,80),T(`lower`,20)],label:e=>`${e.rsiLength}, ${e.stochLength}, ${e.kSmooth}, ${e.dSmooth}`,build:(e,t)=>{let n=e.change(e.src(t.source),1),r=e.rma(e.map(n,e=>e>0?e:e===e?0:NaN),t.rsiLength),i=e.rma(e.map(n,e=>e<0?-e:e===e?0:NaN),t.rsiLength),a=e.map2(r,i,(e,t)=>e+t===0?0:100*e/(e+t)),o=Ge(e,a,a,a,t.stochLength),s=e.sma(o,t.kSmooth);return[o,s,e.sma(s,t.dSmooth)]},reference:"TA-Lib STOCHRSI: `raw` = fastk, `k` = fastd with period kSmooth; `d` is TradingView's second smoothing"}),Xe=D({id:`willr`,name:`Williams %R`,family:`momentum`,needs:`ohlc`,pane:`new`,inputs:[k(14)],columns:[`willr`],plots:[x(`willr`,b.purple,{title:`%R`}),T(`upper`,-20),T(`lower`,-80)],label:e=>`${e.length}`,build:(e,t)=>{let n=e.highest(e.high,t.length),r=e.lowest(e.low,t.length);return[e.calc(t=>{let i=n.v[t]-r.v[t];return i!==i||i===0?NaN:-100*(n.v[t]-e.close.v[t])/i})]},reference:`TA-Lib WILLR (a flat range is absent here; TA-Lib reports 0)`}),Ze=D({id:`cci`,name:`Commodity Channel Index`,family:`momentum`,needs:`ohlc`,pane:`new`,inputs:[k(20)],columns:[`cci`],plots:[x(`cci`,b.blue),T(`upper`,100),T(`lower`,-100)],label:e=>`${e.length}`,build:(e,t)=>{let n=e.src(`hlc3`),r=e.sma(n,t.length),i=t.length;return[e.calc(e=>{let t=r.v[e];if(t!==t)return NaN;let a=0;for(let r=e-i+1;r<=e;r++)a+=Math.abs(n.v[r]-t);return a/=i,a===0?NaN:(n.v[e]-t)/(.015*a)})]},reference:`TA-Lib CCI (typical price, mean deviation; zero deviation is absent here, TA-Lib reports 0)`}),Qe=D({id:`bop`,name:`Balance Of Power`,family:`momentum`,needs:`ohlc`,pane:`new`,inputs:[],columns:[`bop`],plots:[x(`bop`,b.teal),T(`zero`,0,b.gray,`dotted`)],build:e=>[e.calc(t=>{let n=e.high.v[t]-e.low.v[t];return n>0?(e.close.v[t]-e.open.v[t])/n:0})],reference:`TA-Lib BOP = (close - open) / (high - low), 0 on a flat bar`}),$e=D({id:`mfi`,name:`Money Flow Index`,family:`momentum`,needs:`ohlcv`,pane:`new`,inputs:[k(14)],columns:[`mfi`],plots:[x(`mfi`,b.purple),T(`upper`,80),T(`lower`,20)],label:e=>`${e.length}`,build:(e,t)=>{let n=e.src(`hlc3`),r=e.calc(t=>t===0?NaN:n.v[t]>n.v[t-1]?n.v[t]*e.volume.v[t]:0),i=e.calc(t=>t===0?NaN:n.v[t]<n.v[t-1]?n.v[t]*e.volume.v[t]:0),a=e.sum(r,t.length),o=e.sum(i,t.length);return[e.map2(a,o,(e,t)=>e+t===0?0:100*e/(e+t))]},reference:`TA-Lib MFI`}),et=D({id:`ultosc`,name:`Ultimate Oscillator`,family:`momentum`,needs:`ohlc`,pane:`new`,inputs:[h(`fast`,7,1,5e3),h(`middle`,14,1,5e3),h(`slow`,28,1,5e3)],columns:[`ultosc`],plots:[x(`ultosc`,b.blue),T(`upper`,70),T(`lower`,30)],label:e=>`${e.fast}, ${e.middle}, ${e.slow}`,build:(e,t)=>{let[n,r,i]=[t.fast,t.middle,t.slow].sort((e,t)=>e-t),a=e.calc(t=>t===0?NaN:e.close.v[t]-Math.min(e.low.v[t],e.close.v[t-1])),o=e.calc(t=>t===0?NaN:Math.max(e.high.v[t],e.close.v[t-1])-Math.min(e.low.v[t],e.close.v[t-1])),[s,c,l]=[e.sum(a,n),e.sum(a,r),e.sum(a,i)],[u,d,f]=[e.sum(o,n),e.sum(o,r),e.sum(o,i)];return[e.calc(e=>{let t=s.v[e]/u.v[e],n=c.v[e]/d.v[e],r=l.v[e]/f.v[e];return 100*(4*t+2*n+r)/7})]},reference:`TA-Lib ULTOSC (periods sorted ascending, weights 4:2:1)`}),tt=D({id:`aroon`,name:`Aroon`,family:`momentum`,needs:`ohlc`,pane:`new`,inputs:[k(14)],columns:[`up`,`down`],plots:[x(`up`,b.green,{title:`Aroon Up`}),x(`down`,b.red,{title:`Aroon Down`})],label:e=>`${e.length}`,build:(e,t)=>{let n=e.highestBars(e.high,t.length+1),r=e.lowestBars(e.low,t.length+1);return[e.map(n,e=>100*(t.length-e)/t.length),e.map(r,e=>100*(t.length-e)/t.length)]},reference:`TA-Lib AROON (window of length + 1 bars)`}),nt=D({id:`aroonosc`,name:`Aroon Oscillator`,family:`momentum`,needs:`ohlc`,pane:`new`,inputs:[k(14)],columns:[`aroonosc`],plots:[x(`aroonosc`,b.blue),T(`zero`,0,b.gray,`dotted`)],label:e=>`${e.length}`,build:(e,t)=>{let n=e.highestBars(e.high,t.length+1),r=e.lowestBars(e.low,t.length+1);return[e.map2(n,r,(e,n)=>100*(n-e)/t.length)]},reference:`TA-Lib AROONOSC = Aroon Up - Aroon Down`});function rt(e,t,n){let r=e.validRun(t);return e.node((e,i,a)=>{let o=t.v,s=r.v,c=e.v;for(let e=i;e<a;e++){let t=s[e];if(t===0){c[e]=NaN;continue}let r=e>0?c[e-1]:NaN;if(r===r)c[e]=r-r/n+o[e];else if(t===n-1){let n=0;for(let r=e-t+1;r<=e;r++)n+=o[r];c[e]=n}else c[e]=NaN}})}function it(e,t){if(t<2)throw RangeError(`directional movement needs length >= 2, got ${t}`);let{high:n,low:r}=e,i=e.calc(e=>{if(e===0)return NaN;let t=n.v[e]-n.v[e-1],i=r.v[e-1]-r.v[e];return t>0&&t>i?t:0}),a=e.calc(e=>{if(e===0)return NaN;let t=n.v[e]-n.v[e-1],i=r.v[e-1]-r.v[e];return i>0&&i>t?i:0}),o=rt(e,i,t),s=rt(e,a,t),c=rt(e,e.tr(),t),l=e.lag(c,1),u=t=>e.calc(e=>l.v[e]===l.v[e]&&c.v[e]>0?100*t.v[e]/c.v[e]:NaN),d=u(o),f=u(s);return{sp:o,sm:s,pdi:d,mdi:f,dx:e.map2(d,f,(e,t)=>e+t===0?NaN:100*Math.abs(e-t)/(e+t))}}let at=[x(`adx`,b.red,{title:`ADX`}),x(`plusDi`,b.blue,{title:`+DI`}),x(`minusDi`,b.orange,{title:`-DI`})],ot=D({id:`adx`,name:`Average Directional Index`,family:`momentum`,needs:`ohlc`,pane:`new`,inputs:[k(14,2)],columns:[`adx`,`plusDi`,`minusDi`],plots:at,label:e=>`${e.length}`,build:(e,t)=>{let n=it(e,t.length);return[e.rma(n.dx,t.length),n.pdi,n.mdi]},reference:`TA-Lib ADX / PLUS_DI / MINUS_DI (Wilder smoothing seeded as TA-Lib does)`}),st=D({id:`adxr`,name:`Average Directional Movement Index Rating`,family:`momentum`,needs:`ohlc`,pane:`new`,inputs:[k(14,2)],columns:[`adxr`],plots:[x(`adxr`,b.red)],label:e=>`${e.length}`,build:(e,t)=>{let n=e.rma(it(e,t.length).dx,t.length);return[e.map2(n,e.lag(n,t.length-1),(e,t)=>(e+t)/2)]},reference:`TA-Lib ADXR = (ADX + ADX[length - 1]) / 2`}),ct=D({id:`dx`,name:`Directional Movement Index`,family:`momentum`,needs:`ohlc`,pane:`new`,inputs:[k(14,2)],columns:[`dx`],plots:[x(`dx`,b.purple)],label:e=>`${e.length}`,build:(e,t)=>[it(e,t.length).dx],reference:`TA-Lib DX`}),lt=(e,t,n,r)=>D({id:e,name:t,family:`momentum`,needs:`ohlc`,pane:`new`,inputs:[k(14,2)],columns:[e.replace(`-`,``)],plots:[x(e.replace(`-`,``),r)],label:e=>`${e.length}`,build:(e,t)=>[n(it(e,t.length))],reference:`TA-Lib ${e.replace(`-`,`_`).toUpperCase()}`}),ut=lt(`plus-di`,`Plus Directional Indicator`,e=>e.pdi,b.blue),dt=lt(`minus-di`,`Minus Directional Indicator`,e=>e.mdi,b.orange),ft=lt(`plus-dm`,`Plus Directional Movement`,e=>e.sp,b.blue),pt=lt(`minus-dm`,`Minus Directional Movement`,e=>e.sm,b.orange);var mt=/* @__PURE__ */ t({ad:()=>gt,adosc:()=>_t,obv:()=>vt});function ht(e){let t=e.calc(n=>{let r=e.high.v[n]-e.low.v[n],i=r===0?0:(e.close.v[n]-e.low.v[n]-(e.high.v[n]-e.close.v[n]))/r*e.volume.v[n];return(n>0?t.v[n-1]:0)+i});return t}let gt=D({id:`ad`,name:`Accumulation/Distribution`,family:`volume`,needs:`ohlcv`,pane:`new`,inputs:[],columns:[`ad`],plots:[x(`ad`,b.blue)],build:e=>[ht(e)],reference:`TA-Lib AD (a flat bar adds 0)`}),_t=D({id:`adosc`,name:`Chaikin Oscillator`,family:`volume`,needs:`ohlcv`,pane:`new`,inputs:[h(`fast`,3,1,5e3),h(`slow`,10,2,5e3)],columns:[`adosc`],plots:[x(`adosc`,b.purple),T(`zero`,0,b.gray,`dotted`)],label:e=>`${e.fast}, ${e.slow}`,build:(e,t)=>{if(t.fast>=t.slow)throw RangeError(`adosc: fast (${t.fast}) must be below slow (${t.slow})`);let n=ht(e),r=se(e,n,2/(t.fast+1)),i=se(e,n,2/(t.slow+1));return[e.calc(e=>e>=t.slow-1?r.v[e]-i.v[e]:NaN)]},reference:`TA-Lib ADOSC: both EMAs are seeded with the first A/D value (TradingView seeds with an SMA; the difference vanishes within ~60 bars)`}),vt=D({id:`obv`,name:`On Balance Volume`,family:`volume`,needs:`ohlcv`,pane:`new`,inputs:[],columns:[`obv`],plots:[x(`obv`,b.teal)],build:e=>{let t=e.calc(n=>{if(n===0)return e.volume.v[0];let r=e.close.v[n],i=e.close.v[n-1];return t.v[n-1]+(r>i?e.volume.v[n]:r<i?-e.volume.v[n]:0)});return[t]},reference:`TA-Lib OBV (first value is the first bar's volume)`});var yt=/* @__PURE__ */ t({atr:()=>xt,natr:()=>St,trange:()=>bt});let bt=D({id:`trange`,name:`True Range`,family:`volatility`,needs:`ohlc`,pane:`new`,inputs:[],columns:[`trange`],plots:[x(`trange`,b.orange)],build:e=>[e.tr()],reference:`TA-Lib TRANGE`}),xt=D({id:`atr`,name:`Average True Range`,family:`volatility`,needs:`ohlc`,pane:`new`,inputs:[h(`length`,14,1,5e3)],columns:[`atr`],plots:[x(`atr`,b.red)],label:e=>`${e.length}`,build:(e,t)=>[e.atr(t.length)],reference:"TA-Lib ATR (Wilder, seeded with the mean of the first `length` true ranges)"}),St=D({id:`natr`,name:`Normalized Average True Range`,family:`volatility`,needs:`ohlc`,pane:`new`,inputs:[h(`length`,14,1,5e3)],columns:[`natr`],plots:[x(`natr`,b.red)],label:e=>`${e.length}`,build:(e,t)=>{let n=e.atr(t.length);return[e.calc(t=>100*n.v[t]/e.close.v[t])]},reference:`TA-Lib NATR = 100 * ATR / close`});var Ct=/* @__PURE__ */ t({avgprice:()=>Tt,medprice:()=>Et,typprice:()=>Dt,wclprice:()=>Ot});let wt=(e,t,n,r,i)=>D({id:e,name:t,family:`price`,needs:`ohlc`,pane:`overlay`,inputs:[],columns:[e],plots:[x(e,n)],build:e=>[r(e)],reference:i}),Tt=wt(`avgprice`,`Average Price`,b.blue,e=>e.src(`ohlc4`),`TA-Lib AVGPRICE = (O + H + L + C) / 4`),Et=wt(`medprice`,`Median Price`,b.orange,e=>e.src(`hl2`),`TA-Lib MEDPRICE = (H + L) / 2`),Dt=wt(`typprice`,`Typical Price`,b.green,e=>e.src(`hlc3`),`TA-Lib TYPPRICE = (H + L + C) / 3`),Ot=wt(`wclprice`,`Weighted Close Price`,b.purple,e=>e.src(`hlcc4`),`TA-Lib WCLPRICE = (H + L + 2C) / 4`);var kt=/* @__PURE__ */ t({beta:()=>Ut,correl:()=>Ht,linearreg:()=>Nt,linearregAngle:()=>It,linearregIntercept:()=>Ft,linearregSlope:()=>Pt,stddev:()=>Rt,tsf:()=>Lt,variance:()=>zt});let At=(e,t=2)=>h(`length`,e,t,5e3),jt=180/Math.PI,Mt=(e,t,n,r,i,a)=>D({id:e,name:t,family:`statistic`,needs:`value`,pane:a,inputs:[At(14),y()],columns:[e],plots:[x(e,n)],label:e=>`${e.length}`,build:(e,t)=>[r(e.linreg(e.src(t.source),t.length),e)],reference:i}),Nt=Mt(`linearreg`,`Linear Regression`,b.blue,e=>e.value,`TA-Lib LINEARREG`,`overlay`),Pt=Mt(`linearreg-slope`,`Linear Regression Slope`,b.orange,e=>e.slope,`TA-Lib LINEARREG_SLOPE`,`new`),Ft=Mt(`linearreg-intercept`,`Linear Regression Intercept`,b.teal,e=>e.intercept,`TA-Lib LINEARREG_INTERCEPT`,`overlay`),It=Mt(`linearreg-angle`,`Linear Regression Angle`,b.purple,(e,t)=>t.map(e.slope,e=>Math.atan(e)*jt),`TA-Lib LINEARREG_ANGLE (degrees)`,`new`),Lt=Mt(`tsf`,`Time Series Forecast`,b.pink,(e,t)=>t.map2(e.value,e.slope,(e,t)=>e+t),`TA-Lib TSF = regression value one bar ahead`,`overlay`),Rt=D({id:`stddev`,name:`Standard Deviation`,family:`statistic`,needs:`value`,pane:`new`,inputs:[At(5,1),g(`nbdev`,1,0,100,.1),y()],columns:[`stddev`],plots:[x(`stddev`,b.blue)],label:e=>`${e.length}`,build:(e,t)=>[e.map(e.stdev(e.src(t.source),t.length),e=>e*t.nbdev)],reference:`TA-Lib STDDEV (population)`}),zt=D({id:`var`,name:`Variance`,family:`statistic`,needs:`value`,pane:`new`,inputs:[At(5,1),y()],columns:[`var`],plots:[x(`var`,b.blue)],label:e=>`${e.length}`,build:(e,t)=>[e.variance(e.src(t.source),t.length)],reference:`TA-Lib VAR (population)`}),Bt=[...o,`volume`];function Vt(e,t){return t===`volume`?e.volume:e.src(t)}let Ht=D({id:`correl`,name:`Correlation Coefficient`,family:`statistic`,needs:`ohlcv`,pane:`new`,inputs:[At(30),y(`close`),v(`source2`,`volume`,Bt)],columns:[`correl`],plots:[x(`correl`,b.teal)],label:e=>`${e.length}`,build:(e,t)=>{let n=e.src(t.source),r=Vt(e,t.source2),i=t.length;return[e.calc(e=>{if(e<i-1)return NaN;let t=0,a=0,o=0,s=0,c=0;for(let l=e-i+1;l<=e;l++){let e=n.v[l],i=r.v[l];t+=e,a+=i,o+=e*e,s+=i*i,c+=e*i}let l=(i*o-t*t)*(i*s-a*a);return l>0?(i*c-t*a)/Math.sqrt(l):0})]},reference:`TA-Lib CORREL (Pearson; a constant window gives 0 as TA-Lib does)`}),Ut=D({id:`beta`,name:`Beta`,family:`statistic`,needs:`ohlcv`,pane:`new`,inputs:[At(5,1),y(`close`),v(`source2`,`volume`,Bt)],columns:[`beta`],plots:[x(`beta`,b.orange)],label:e=>`${e.length}`,build:(e,t)=>{let n=e.src(t.source),r=Vt(e,t.source2),i=t.length,a=e.map2(n,e.lag(n,1),(e,t)=>t===0?0:(e-t)/t),o=e.map2(r,e.lag(r,1),(e,t)=>t===0?0:(e-t)/t);return[e.calc(e=>{if(e<i)return NaN;let t=0,n=0,r=0,s=0;for(let c=e-i+1;c<=e;c++){let e=a.v[c],i=o.v[c];t+=e,n+=i,r+=e*e,s+=e*i}let c=i*r-t*t;return c===0?0:(i*s-t*n)/c})]},reference:"TA-Lib BETA: slope of source2's one-bar returns on source's over `length` returns"});var Wt=/* @__PURE__ */ t({acos:()=>Gt,add:()=>cn,asin:()=>Kt,atan:()=>qt,ceil:()=>Jt,cos:()=>Yt,cosh:()=>Xt,div:()=>dn,exp:()=>Zt,floor:()=>Qt,ln:()=>$t,log10:()=>en,max:()=>pn,maxindex:()=>_n,min:()=>mn,minindex:()=>vn,minmax:()=>yn,minmaxindex:()=>bn,mult:()=>un,sin:()=>tn,sinh:()=>nn,sqrt:()=>rn,sub:()=>ln,sum:()=>hn,tan:()=>an,tanh:()=>on});let A=(e,t,n,r=`TA-Lib ${e.toUpperCase()}`)=>D({id:e,name:t,family:`math`,needs:`value`,pane:`new`,inputs:[y()],columns:[e],plots:[x(e,b.blue)],build:(e,t)=>[e.map(e.src(t.source),e=>{let t=n(e);return Number.isFinite(t)?t:NaN})],reference:r}),Gt=A(`acos`,`Arc Cosine`,Math.acos),Kt=A(`asin`,`Arc Sine`,Math.asin),qt=A(`atan`,`Arc Tangent`,Math.atan),Jt=A(`ceil`,`Ceiling`,Math.ceil),Yt=A(`cos`,`Cosine`,Math.cos),Xt=A(`cosh`,`Hyperbolic Cosine`,Math.cosh),Zt=A(`exp`,`Exponential`,Math.exp),Qt=A(`floor`,`Floor`,Math.floor),$t=A(`ln`,`Natural Log`,Math.log),en=A(`log10`,`Log10`,Math.log10),tn=A(`sin`,`Sine`,Math.sin),nn=A(`sinh`,`Hyperbolic Sine`,Math.sinh),rn=A(`sqrt`,`Square Root`,Math.sqrt),an=A(`tan`,`Tangent`,Math.tan),on=A(`tanh`,`Hyperbolic Tangent`,Math.tanh),sn=(e,t,n)=>D({id:e,name:t,family:`math`,needs:`ohlc`,pane:`new`,inputs:[y(`high`),y(`low`,`source2`)],columns:[e],plots:[x(e,b.orange)],build:(e,t)=>[e.map2(e.src(t.source),e.src(t.source2),n)],reference:`TA-Lib ${e.toUpperCase()}`}),cn=sn(`add`,`Vector Arithmetic Add`,(e,t)=>e+t),ln=sn(`sub`,`Vector Arithmetic Subtraction`,(e,t)=>e-t),un=sn(`mult`,`Vector Arithmetic Mult`,(e,t)=>e*t),dn=sn(`div`,`Vector Arithmetic Div`,(e,t)=>t===0?NaN:e/t),fn=(e=30)=>h(`length`,e,1,5e3),pn=D({id:`max`,name:`Highest value over a period`,family:`math`,needs:`value`,pane:`overlay`,inputs:[fn(),y()],columns:[`max`],plots:[x(`max`,b.green)],label:e=>`${e.length}`,build:(e,t)=>[e.highest(e.src(t.source),t.length)],reference:`TA-Lib MAX`}),mn=D({id:`min`,name:`Lowest value over a period`,family:`math`,needs:`value`,pane:`overlay`,inputs:[fn(),y()],columns:[`min`],plots:[x(`min`,b.red)],label:e=>`${e.length}`,build:(e,t)=>[e.lowest(e.src(t.source),t.length)],reference:`TA-Lib MIN`}),hn=D({id:`sum`,name:`Summation`,family:`math`,needs:`value`,pane:`new`,inputs:[fn(),y()],columns:[`sum`],plots:[x(`sum`,b.blue)],label:e=>`${e.length}`,build:(e,t)=>[e.sum(e.src(t.source),t.length)],reference:`TA-Lib SUM`}),gn=(e,t)=>e.calc(e=>e-t.v[e]),_n=D({id:`maxindex`,name:`Index of highest value over a period`,family:`math`,needs:`value`,pane:`new`,inputs:[fn(),y()],columns:[`maxindex`],plots:[x(`maxindex`,b.green)],label:e=>`${e.length}`,build:(e,t)=>[gn(e,e.highestBars(e.src(t.source),t.length,!0))],reference:`TA-Lib MAXINDEX`}),vn=D({id:`minindex`,name:`Index of lowest value over a period`,family:`math`,needs:`value`,pane:`new`,inputs:[fn(),y()],columns:[`minindex`],plots:[x(`minindex`,b.red)],label:e=>`${e.length}`,build:(e,t)=>[gn(e,e.lowestBars(e.src(t.source),t.length))],reference:`TA-Lib MININDEX`}),yn=D({id:`minmax`,name:`Lowest and highest values over a period`,family:`math`,needs:`value`,pane:`overlay`,inputs:[fn(),y()],columns:[`min`,`max`],plots:[x(`min`,b.red),x(`max`,b.green)],label:e=>`${e.length}`,build:(e,t)=>{let n=e.src(t.source);return[e.lowest(n,t.length),e.highest(n,t.length)]},reference:`TA-Lib MINMAX`}),bn=D({id:`minmaxindex`,name:`Indexes of lowest and highest values over a period`,family:`math`,needs:`value`,pane:`new`,inputs:[fn(),y()],columns:[`minidx`,`maxidx`],plots:[x(`minidx`,b.red),x(`maxidx`,b.green)],label:e=>`${e.length}`,build:(e,t)=>{let n=e.src(t.source);return[gn(e,e.lowestBars(n,t.length)),gn(e,e.highestBars(n,t.length,!0))]},reference:`TA-Lib MINMAXINDEX`});var xn=/* @__PURE__ */ t({htDcPeriod:()=>Nn,htDcPhase:()=>Pn,htPhasor:()=>Fn,htSine:()=>In,htTrendMode:()=>Rn,htTrendline:()=>Ln,mama:()=>zn});let Sn=.0962,Cn=.5769,wn=Math.atan(1),Tn=45/wn,En=1/Tn,Dn=wn*8;function On(e,t,n,r){return r*(Sn*e[t-n]+Cn*e[t-n-2]-Cn*e[t-n-4]-Sn*e[t-n-6])}function kn(e,t,n){let r=3+n,i=e.col(),a=e.col(),o=e.col(),s=e.col(),c=e.col(),l=e.col(),u=e.col(),d=e.col(),f=e.col(),p=e.col();return{S:r,sm:i,det:a,q1:o,sper:e.node((e,n,m)=>{let h=t.v,g=i.v,_=a.v,v=o.v,y=s.v,b=c.v,x=l.v,S=u.v,C=d.v,w=f.v,T=p.v,E=e.v;for(let e=n;e<m;e++){if(e<r){g[e]=_[e]=v[e]=y[e]=b[e]=x[e]=S[e]=C[e]=w[e]=T[e]=E[e]=0;continue}let t=T[e-1],n=.075*t+.54;g[e]=(4*h[e]+3*h[e-1]+2*h[e-2]+h[e-3])/10,_[e]=On(g,e,0,n),v[e]=On(_,e,0,n),y[e]=On(_,e,3,n),b[e]=On(v,e,0,n);let i=x[e-1],a=S[e-1],o=.2*(v[e]+y[e])+.8*i,s=.2*(_[e-3]-b[e])+.8*a;x[e]=o,S[e]=s;let c=.8*C[e-1]+.2*(s*a+o*i),l=.8*w[e-1]+.2*(s*i-o*a);C[e]=c,w[e]=l;let u=t;l!==0&&c!==0&&(u=360/(Math.atan(l/c)*Tn)),u>1.5*t&&(u=1.5*t),u<.67*t&&(u=.67*t),u<6?u=6:u>50&&(u=50),u=.2*u+.8*t,T[e]=u,E[e]=.33*u+.67*E[e-1]}})}}function An(e,t,n){return e.calc(e=>e>=n?t.v[e]:NaN)}function jn(e,t){let{S:n,sm:r,sper:i}=t;return e.node((e,t,a)=>{let o=r.v,s=i.v,c=e.v;for(let e=t;e<a;e++){if(e<n){c[e]=0;continue}let t=Math.floor(s[e]+.5),r=0,i=0;for(let n=0;n<t;n++){let a=n*Dn/t,s=e-n>=0?o[e-n]:0;r+=Math.sin(a)*s,i+=Math.cos(a)*s}let a=c[e-1];Math.abs(i)>0?a=Math.atan(r/i)*Tn:r<0?a-=90:r>0&&(a+=90),a+=90,a+=360/s[e],i<0&&(a+=180),a>315&&(a-=360),c[e]=a}})}function Mn(e,t,n){let{S:r,sper:i}=n,a=e.col();return e.node((e,n,o)=>{let s=t.v,c=i.v,l=a.v,u=e.v;for(let e=n;e<o;e++){if(e<r){l[e]=0,u[e]=0;continue}let t=Math.floor(c[e]+.5),n=0;for(let r=0;r<t&&e-r>=0;r++)n+=s[e-r];t>0&&(n/=t),l[e]=n,u[e]=(4*n+3*l[e-1]+2*l[e-2]+l[e-3])/10}})}let Nn=D({id:`ht-dcperiod`,name:`Hilbert Transform - Dominant Cycle Period`,family:`cycle`,needs:`value`,pane:`new`,inputs:[y()],columns:[`period`],plots:[x(`period`,b.blue)],build:(e,t)=>[An(e,kn(e,e.src(t.source),9).sper,32)],reference:`TA-Lib HT_DCPERIOD`}),Pn=D({id:`ht-dcphase`,name:`Hilbert Transform - Dominant Cycle Phase`,family:`cycle`,needs:`value`,pane:`new`,inputs:[y()],columns:[`phase`],plots:[x(`phase`,b.orange)],build:(e,t)=>[An(e,jn(e,kn(e,e.src(t.source),34)),63)],reference:`TA-Lib HT_DCPHASE`}),Fn=D({id:`ht-phasor`,name:`Hilbert Transform - Phasor Components`,family:`cycle`,needs:`value`,pane:`new`,inputs:[y()],columns:[`inphase`,`quadrature`],plots:[x(`inphase`,b.blue),x(`quadrature`,b.orange)],build:(e,t)=>{let n=kn(e,e.src(t.source),9);return[e.calc(e=>e>=32?n.det.v[e-3]:NaN),An(e,n.q1,32)]},reference:`TA-Lib HT_PHASOR`}),In=D({id:`ht-sine`,name:`Hilbert Transform - SineWave`,family:`cycle`,needs:`value`,pane:`new`,inputs:[y()],columns:[`sine`,`leadsine`],plots:[x(`sine`,b.blue),x(`leadsine`,b.orange)],build:(e,t)=>{let n=jn(e,kn(e,e.src(t.source),34));return[e.calc(e=>e>=63?Math.sin(n.v[e]*En):NaN),e.calc(e=>e>=63?Math.sin((n.v[e]+45)*En):NaN)]},reference:`TA-Lib HT_SINE`}),Ln=D({id:`ht-trendline`,name:`Hilbert Transform - Instantaneous Trendline`,family:`cycle`,needs:`value`,pane:`overlay`,inputs:[y()],columns:[`trendline`],plots:[x(`trendline`,b.blue)],build:(e,t)=>{let n=e.src(t.source);return[An(e,Mn(e,n,kn(e,n,34)),63)]},reference:`TA-Lib HT_TRENDLINE`}),Rn=D({id:`ht-trendmode`,name:`Hilbert Transform - Trend vs Cycle Mode`,family:`cycle`,needs:`value`,pane:`new`,inputs:[y()],columns:[`trendmode`],plots:[S(`trendmode`,b.green)],build:(e,t)=>{let n=e.src(t.source),r=kn(e,n,34),i=jn(e,r),a=Mn(e,n,r),o=e.col(),s=e.col(),c=e.col(),l=e.node((e,t,n)=>{let l=r.sm.v,u=r.sper.v,d=i.v,f=a.v,p=o.v,m=s.v,h=c.v,g=e.v;for(let e=t;e<n;e++){if(e<r.S){p[e]=m[e]=h[e]=g[e]=0;continue}let t=Math.sin(d[e]*En),n=Math.sin((d[e]+45)*En);p[e]=t,m[e]=n;let i=p[e-1],a=m[e-1],o=1,s=h[e-1];(t>n&&i<=a||t<n&&i>=a)&&(s=0,o=0),s+=1,h[e]=s,s<.5*u[e]&&(o=0);let c=d[e]-d[e-1];u[e]!==0&&c>.67*360/u[e]&&c<540/u[e]&&(o=0);let _=f[e];_!==0&&Math.abs((l[e]-_)/_)>=.015&&(o=1),g[e]=o}});return[e.calc(e=>e>=63?l.v[e]:0)]},reference:`TA-Lib HT_TRENDMODE (0 = cycle mode, 1 = trend mode; 0 during warm-up as in TA-Lib)`}),zn=D({id:`mama`,name:`MESA Adaptive Moving Average`,family:`overlap`,needs:`value`,pane:`overlay`,inputs:[g(`fastlimit`,.5,.01,.99,.01),g(`slowlimit`,.05,.01,.99,.01),y()],columns:[`mama`,`fama`],plots:[x(`mama`,b.blue),x(`fama`,b.orange)],label:e=>`${e.fastlimit}, ${e.slowlimit}`,build:(e,t)=>{let n=t.fastlimit,r=t.slowlimit,i=e.src(t.source),a=kn(e,i,9),o=e.col(),s=e.col();return[An(e,e.node((e,t,c)=>{let l=i.v,u=a.det.v,d=a.q1.v,f=o.v,p=s.v,m=e.v;for(let e=t;e<c;e++){if(e<a.S){m[e]=f[e]=p[e]=0;continue}let t=u[e-3],i=t===0?0:Math.atan(d[e]/t)*Tn;p[e]=i;let o=p[e-1]-i;o<1&&(o=1);let s=n;o>1&&(s=n/o,s<r&&(s=r));let c=(1-s)*m[e-1]+s*l[e];m[e]=c;let h=s*.5;f[e]=(1-h)*f[e-1]+h*c}}),32),An(e,o,32)]},reference:`TA-Lib MAMA`});var Bn=/* @__PURE__ */ t({sar:()=>Un,sarext:()=>Wn});function Vn(e){let t=e.high.v,n=e.low.v,r=t[1]-t[0],i=n[0]-n[1];return i>0&&r<i}function Hn(e,t){let n=e.col(),r=e.col(),i=e.col(),a=e.col(),o=e.col();return e.node((s,c,l)=>{let u=e.high.v,d=e.low.v,f=n.v,p=r.v,m=i.v,h=a.v,g=o.v,_=s.v;for(let n=c;n<l;n++){if(n<1){_[n]=NaN;continue}let r,i,a,o,s,c,l;n===1?(r=t.startValue===0?!Vn(e):t.startValue>0,t.startValue===0?r?(a=u[1],i=d[0]):(a=d[1],i=u[0]):t.startValue>0?(a=u[1],i=t.startValue):(a=d[1],i=Math.abs(t.startValue)),o=t.initLong,s=t.initShort,c=d[1],l=u[1]):(r=f[n-1]===1,i=p[n-1],a=m[n-1],o=h[n-1],s=g[n-1],c=d[n-1],l=u[n-1]);let v=d[n],y=u[n],b;r?v<=i?(r=!1,i=a,i<l&&(i=l),i<y&&(i=y),t.offsetOnReverse!==0&&(i+=i*t.offsetOnReverse),b=t.signed?-i:i,s=t.initShort,a=v,i+=s*(a-i),i<l&&(i=l),i<y&&(i=y)):(b=i,y>a&&(a=y,o+=t.accLong,o>t.maxLong&&(o=t.maxLong)),i+=o*(a-i),i>c&&(i=c),i>v&&(i=v)):y>=i?(r=!0,i=a,i>c&&(i=c),i>v&&(i=v),t.offsetOnReverse!==0&&(i-=i*t.offsetOnReverse),b=i,o=t.initLong,a=y,i+=o*(a-i),i>c&&(i=c),i>v&&(i=v)):(b=t.signed?-i:i,v<a&&(a=v,s+=t.accShort,s>t.maxShort&&(s=t.maxShort)),i+=s*(a-i),i<l&&(i=l),i<y&&(i=y)),f[n]=+!!r,p[n]=i,m[n]=a,h[n]=o,g[n]=s,_[n]=b}})}let j=(e,t)=>g(e,t,0,100,.01),Un=D({id:`sar`,name:`Parabolic SAR`,family:`overlap`,needs:`ohlc`,pane:`overlay`,inputs:[j(`start`,.02),j(`increment`,.02),j(`maximum`,.2)],columns:[`sar`],plots:[E(`sar`,`circle`,`value`,b.blue)],label:e=>`${e.start}, ${e.increment}, ${e.maximum}`,build:(e,t)=>{let n=t.maximum,r=Math.min(t.start,n);return[Hn(e,{startValue:0,offsetOnReverse:0,initLong:r,accLong:t.increment,maxLong:n,initShort:r,accShort:t.increment,maxShort:n,signed:!1})]},reference:`TA-Lib SAR (start = increment = acceleration)`}),Wn=D({id:`sarext`,name:`Parabolic SAR - Extended`,family:`overlap`,needs:`ohlc`,pane:`overlay`,inputs:[g(`startvalue`,0,-1e9,1e9,.1),j(`offsetonreverse`,0),j(`accelerationinitlong`,.02),j(`accelerationlong`,.02),j(`accelerationmaxlong`,.2),j(`accelerationinitshort`,.02),j(`accelerationshort`,.02),j(`accelerationmaxshort`,.2)],columns:[`sarext`,`level`],plots:[E(`level`,`circle`,`value`,b.blue,{title:`SAR`})],label:()=>`sarext is negative when short`,build:(e,t)=>{let n=t.accelerationmaxlong,r=t.accelerationmaxshort,i=Hn(e,{startValue:t.startvalue,offsetOnReverse:t.offsetonreverse,initLong:Math.min(t.accelerationinitlong,n),accLong:Math.min(t.accelerationlong,n),maxLong:n,initShort:Math.min(t.accelerationinitshort,r),accShort:Math.min(t.accelerationshort,r),maxShort:r,signed:!0});return[i,e.map(i,Math.abs)]},reference:`TA-Lib SAREXT (signed: negative when short)`});var Gn=/* @__PURE__ */ t({cdl2Crows:()=>rr,cdl3BlackCrows:()=>ir,cdl3Inside:()=>ar,cdl3LineStrike:()=>or,cdl3Outside:()=>sr,cdl3StarsInSouth:()=>cr,cdl3WhiteSoldiers:()=>lr,cdlAbandonedBaby:()=>ur,cdlAdvanceBlock:()=>dr,cdlBeltHold:()=>fr,cdlBreakaway:()=>pr,cdlClosingMarubozu:()=>mr,cdlConcealBabySwall:()=>hr,cdlCounterAttack:()=>gr,cdlDarkCloudCover:()=>_r,cdlDoji:()=>vr,cdlDojiStar:()=>yr,cdlDragonflyDoji:()=>br,cdlEngulfing:()=>xr,cdlEveningDojiStar:()=>Sr,cdlEveningStar:()=>Cr,cdlGapSideSideWhite:()=>wr,cdlGravestoneDoji:()=>Tr,cdlHammer:()=>Er,cdlHangingMan:()=>Dr,cdlHarami:()=>Or,cdlHaramiCross:()=>kr,cdlHighWave:()=>Ar,cdlHikkake:()=>Mr,cdlHikkakeMod:()=>Nr,cdlHomingPigeon:()=>Pr,cdlIdentical3Crows:()=>Fr,cdlInNeck:()=>Ir,cdlInvertedHammer:()=>Lr,cdlKicking:()=>Br,cdlKickingByLength:()=>Vr,cdlLadderBottom:()=>Hr,cdlLongLeggedDoji:()=>Ur,cdlLongLine:()=>Wr,cdlMarubozu:()=>Gr,cdlMatHold:()=>qr,cdlMatchingLow:()=>Kr,cdlMorningDojiStar:()=>Jr,cdlMorningStar:()=>Yr,cdlOnNeck:()=>Xr,cdlPiercing:()=>Zr,cdlRickshawMan:()=>Qr,cdlRiseFall3Methods:()=>$r,cdlSeparatingLines:()=>ei,cdlShootingStar:()=>ti,cdlShortLine:()=>ni,cdlSpinningTop:()=>ri,cdlStalledPattern:()=>ii,cdlStickSandwich:()=>ai,cdlTakuri:()=>oi,cdlTasukiGap:()=>si,cdlThrusting:()=>ci,cdlTriStar:()=>li,cdlUnique3River:()=>ui,cdlUpsideGap2Crows:()=>di,cdlXSideGap3Methods:()=>fi});let M={rt:0,p:10,f:1},N={rt:0,p:10,f:1},P={rt:1,p:10,f:.1},F={rt:0,p:0,f:1},Kn={rt:0,p:0,f:2},I={rt:2,p:10,f:1},L={rt:1,p:10,f:.1},R={rt:1,p:5,f:.2},qn={rt:1,p:5,f:.6},z={rt:1,p:5,f:.05},Jn,Yn,Xn,Zn;function Qn(e){Jn=e.open.v,Yn=e.high.v,Xn=e.low.v,Zn=e.close.v}let B=e=>Jn[e],V=e=>Yn[e],H=e=>Xn[e],U=e=>Zn[e],W=e=>Zn[e]>=Jn[e]?1:-1,G=e=>Math.abs(Zn[e]-Jn[e]),K=e=>Yn[e]-(Zn[e]>=Jn[e]?Zn[e]:Jn[e]),q=e=>(Zn[e]>=Jn[e]?Jn[e]:Zn[e])-Xn[e];function $n(e,t){return e.rt===0?G(t):e.rt===1?Yn[t]-Xn[t]:K(t)+q(t)}function J(e,t,n){return e.f*(e.p===0?$n(e,n):t/e.p)/(e.rt===2?2:1)}function er(e,t,n){let r=e*t,i=134217729*e,a=i-(i-e),o=e-a,s=134217729*t,c=s-(s-t),l=t-c,u=a*c-r+a*l+o*c+o*l,d=r+n,f=d-r;return d+(r-(d-f)+(n-f)+u)}function tr(e,t,n,r){if(t.p===0)throw RangeError(`a setting without an averaging period has no running total`);let i=t.p;return e.node((a,o,s)=>{Qn(e);let c=a.v;for(let e=o;e<s;e++){if(e<r){c[e]=NaN;continue}let a=e-n;if(e===r){let n=0;for(let e=a-i;e<a;e++)n+=$n(t,e);c[e]=n}else c[e]=c[e-1]+($n(t,a-1)-$n(t,a-1-i))}})}function nr(e,t,n,r){return D({id:`cdl-${e.toLowerCase()}`,name:t,family:`pattern`,needs:`ohlc`,pane:`overlay`,inputs:n,columns:[`signal`],plots:[E(`signal`,`arrowUp`,`sign`,b.blue,{text:!0})],build:r,reference:`TA-Lib CDL${e}`})}function Y(e,t,n,r,i,a){return nr(e,t,a?[g(`penetration`,a.pen,0,10,.05)]:[],(e,t)=>{let o=r.map(([t,r])=>tr(e,t,r,n)),s=new Float64Array(o.length),c=a?t.penetration:0;return[e.node((t,r,a)=>{Qn(e);let l=t.v;for(let e=r;e<a;e++)if(e<n)l[e]=NaN;else{for(let t=0;t<o.length;t++)s[t]=o[t].v[e];l[e]=i(e,s,c)}})]})}let rr=Y(`2CROWS`,`Two Crows`,12,[[M,2]],(e,t)=>W(e-2)===1&&G(e-2)>J(M,t[0],e-2)&&W(e-1)===-1&&Math.min(B(e-1),U(e-1))>Math.max(B(e-2),U(e-2))&&W(e)===-1&&B(e)<B(e-1)&&B(e)>U(e-1)&&U(e)>B(e-2)&&U(e)<U(e-2)?-100:0),ir=Y(`3BLACKCROWS`,`Three Black Crows`,13,[[L,2],[L,1],[L,0]],(e,t)=>W(e-3)===1&&W(e-2)===-1&&W(e-1)===-1&&W(e)===-1&&B(e-1)<B(e-2)&&B(e-1)>U(e-2)&&B(e)<B(e-1)&&B(e)>U(e-1)&&V(e-3)>U(e-2)&&U(e-2)>U(e-1)&&U(e-1)>U(e)&&q(e-2)<J(L,t[0],e-2)&&q(e-1)<J(L,t[1],e-1)&&q(e)<J(L,t[2],e)?-100:0),ar=Y(`3INSIDE`,`Three Inside Up/Down`,12,[[M,2],[N,1]],(e,t)=>Math.max(U(e-1),B(e-1))<Math.max(U(e-2),B(e-2))&&Math.min(U(e-1),B(e-1))>Math.min(U(e-2),B(e-2))&&(W(e-2)===1&&W(e)===-1&&U(e)<B(e-2)||W(e-2)===-1&&W(e)===1&&U(e)>B(e-2))&&G(e-2)>J(M,t[0],e-2)&&G(e-1)<=J(N,t[1],e-1)?-W(e-2)*100:0),or=Y(`3LINESTRIKE`,`Three-Line Strike`,8,[[R,3],[R,2]],(e,t)=>W(e-3)===W(e-2)&&W(e-2)===W(e-1)&&W(e)===-W(e-1)&&B(e-2)>=Math.min(B(e-3),U(e-3))-J(R,t[0],e-3)&&B(e-2)<=Math.max(B(e-3),U(e-3))+J(R,t[0],e-3)&&B(e-1)>=Math.min(B(e-2),U(e-2))-J(R,t[1],e-2)&&B(e-1)<=Math.max(B(e-2),U(e-2))+J(R,t[1],e-2)&&(W(e-1)===1&&U(e-1)>U(e-2)&&U(e-2)>U(e-3)&&B(e)>U(e-1)&&U(e)<B(e-3)||W(e-1)===-1&&U(e-1)<U(e-2)&&U(e-2)<U(e-3)&&B(e)<U(e-1)&&U(e)>B(e-3))?W(e-1)*100:0),sr=Y(`3OUTSIDE`,`Three Outside Up/Down`,3,[],e=>W(e-1)===1&&W(e-2)===-1&&U(e-1)>B(e-2)&&B(e-1)<U(e-2)&&U(e)>U(e-1)||W(e-1)===-1&&W(e-2)===1&&B(e-1)>U(e-2)&&U(e-1)<B(e-2)&&U(e)<U(e-1)?W(e-1)*100:0),cr=Y(`3STARSINSOUTH`,`Three Stars In The South`,12,[[M,2],[L,1],[L,0],[N,0]],(e,t)=>W(e-2)===-1&&W(e-1)===-1&&W(e)===-1&&G(e-2)>J(M,t[0],e-2)&&q(e-2)>J(F,0,e-2)&&G(e-1)<G(e-2)&&B(e-1)>U(e-2)&&B(e-1)<=V(e-2)&&H(e-1)<U(e-2)&&H(e-1)>=H(e-2)&&q(e-1)>J(L,t[1],e-1)&&G(e)<J(N,t[3],e)&&q(e)<J(L,t[2],e)&&K(e)<J(L,t[2],e)&&H(e)>H(e-1)&&V(e)<V(e-1)?100:0),lr=Y(`3WHITESOLDIERS`,`Three Advancing White Soldiers`,12,[[L,2],[L,1],[L,0],[R,2],[R,1],[qn,2],[qn,1],[N,0]],(e,t)=>W(e-2)===1&&K(e-2)<J(L,t[0],e-2)&&W(e-1)===1&&K(e-1)<J(L,t[1],e-1)&&W(e)===1&&K(e)<J(L,t[2],e)&&U(e)>U(e-1)&&U(e-1)>U(e-2)&&B(e-1)>B(e-2)&&B(e-1)<=U(e-2)+J(R,t[3],e-2)&&B(e)>B(e-1)&&B(e)<=U(e-1)+J(R,t[4],e-1)&&G(e-1)>G(e-2)-J(qn,t[5],e-2)&&G(e)>G(e-1)-J(qn,t[6],e-1)&&G(e)>J(N,t[7],e)?100:0),ur=Y(`ABANDONEDBABY`,`Abandoned Baby`,12,[[M,2],[P,1],[N,0]],(e,t,n)=>G(e-2)>J(M,t[0],e-2)&&G(e-1)<=J(P,t[1],e-1)&&G(e)>J(N,t[2],e)&&(W(e-2)===1&&W(e)===-1&&U(e)<U(e-2)-G(e-2)*n&&H(e-1)>V(e-2)&&V(e)<H(e-1)||W(e-2)===-1&&W(e)===1&&U(e)>er(G(e-2),n,U(e-2))&&V(e-1)<H(e-2)&&H(e)>V(e-1))?W(e)*100:0,{pen:.3}),dr=Y(`ADVANCEBLOCK`,`Advance Block`,12,[[I,2],[I,1],[I,0],[R,2],[R,1],[qn,2],[qn,1],[M,2]],(e,t)=>W(e-2)===1&&W(e-1)===1&&W(e)===1&&U(e)>U(e-1)&&U(e-1)>U(e-2)&&B(e-1)>B(e-2)&&B(e-1)<=U(e-2)+J(R,t[3],e-2)&&B(e)>B(e-1)&&B(e)<=U(e-1)+J(R,t[4],e-1)&&G(e-2)>J(M,t[7],e-2)&&K(e-2)<J(I,t[0],e-2)&&(G(e-1)<G(e-2)-J(qn,t[5],e-2)&&G(e)<G(e-1)+J(R,t[4],e-1)||G(e)<G(e-1)-J(qn,t[6],e-1)||G(e)<G(e-1)&&G(e-1)<G(e-2)&&(K(e)>J(I,t[2],e)||K(e-1)>J(I,t[1],e-1))||G(e)<G(e-1)&&K(e)>J(F,0,e))?-100:0),fr=Y(`BELTHOLD`,`Belt-hold`,10,[[M,0],[L,0]],(e,t)=>G(e)>J(M,t[0],e)&&(W(e)===1&&q(e)<J(L,t[1],e)||W(e)===-1&&K(e)<J(L,t[1],e))?W(e)*100:0),pr=Y(`BREAKAWAY`,`Breakaway`,14,[[M,4]],(e,t)=>W(e-4)===W(e-3)&&W(e-3)===W(e-1)&&W(e-1)===-W(e)&&G(e-4)>J(M,t[0],e-4)&&(W(e-4)===-1&&Math.max(B(e-3),U(e-3))<Math.min(B(e-4),U(e-4))&&V(e-2)<V(e-3)&&H(e-2)<H(e-3)&&V(e-1)<V(e-2)&&H(e-1)<H(e-2)&&U(e)>B(e-3)&&U(e)<U(e-4)||W(e-4)===1&&Math.min(B(e-3),U(e-3))>Math.max(B(e-4),U(e-4))&&V(e-2)>V(e-3)&&H(e-2)>H(e-3)&&V(e-1)>V(e-2)&&H(e-1)>H(e-2)&&U(e)<B(e-3)&&U(e)>U(e-4))?W(e)*100:0),mr=Y(`CLOSINGMARUBOZU`,`Closing Marubozu`,10,[[M,0],[L,0]],(e,t)=>G(e)>J(M,t[0],e)&&(W(e)===1&&K(e)<J(L,t[1],e)||W(e)===-1&&q(e)<J(L,t[1],e))?W(e)*100:0),hr=Y(`CONCEALBABYSWALL`,`Concealing Baby Swallow`,13,[[L,3],[L,2],[L,1]],(e,t)=>W(e-3)===-1&&W(e-2)===-1&&W(e-1)===-1&&W(e)===-1&&q(e-3)<J(L,t[0],e-3)&&K(e-3)<J(L,t[0],e-3)&&q(e-2)<J(L,t[1],e-2)&&K(e-2)<J(L,t[1],e-2)&&Math.max(B(e-1),U(e-1))<Math.min(B(e-2),U(e-2))&&K(e-1)>J(L,t[2],e-1)&&V(e-1)>U(e-2)&&V(e)>V(e-1)&&H(e)<H(e-1)?100:0),gr=Y(`COUNTERATTACK`,`Counterattack`,11,[[z,1],[M,1],[M,0]],(e,t)=>W(e-1)===-W(e)&&G(e-1)>J(M,t[1],e-1)&&G(e)>J(M,t[2],e)&&U(e)<=U(e-1)+J(z,t[0],e-1)&&U(e)>=U(e-1)-J(z,t[0],e-1)?W(e)*100:0),_r=Y(`DARKCLOUDCOVER`,`Dark Cloud Cover`,11,[[M,1]],(e,t,n)=>W(e-1)===1&&G(e-1)>J(M,t[0],e-1)&&W(e)===-1&&B(e)>V(e-1)&&U(e)>B(e-1)&&U(e)<U(e-1)-G(e-1)*n?-100:0,{pen:.5}),vr=Y(`DOJI`,`Doji`,10,[[P,0]],(e,t)=>G(e)<=J(P,t[0],e)?100:0),yr=Y(`DOJISTAR`,`Doji Star`,11,[[M,1],[P,0]],(e,t)=>G(e-1)>J(M,t[0],e-1)&&G(e)<=J(P,t[1],e)&&(W(e-1)===1&&Math.min(B(e),U(e))>Math.max(B(e-1),U(e-1))||W(e-1)===-1&&Math.max(B(e),U(e))<Math.min(B(e-1),U(e-1)))?-W(e-1)*100:0),br=Y(`DRAGONFLYDOJI`,`Dragonfly Doji`,10,[[P,0],[L,0]],(e,t)=>G(e)<=J(P,t[0],e)&&K(e)<J(L,t[1],e)&&q(e)>J(L,t[1],e)?100:0),xr=Y(`ENGULFING`,`Engulfing Pattern`,2,[],e=>W(e)===1&&W(e-1)===-1&&(U(e)>=B(e-1)&&B(e)<U(e-1)||U(e)>B(e-1)&&B(e)<=U(e-1))||W(e)===-1&&W(e-1)===1&&(B(e)>=U(e-1)&&U(e)<B(e-1)||B(e)>U(e-1)&&U(e)<=B(e-1))?B(e)!==U(e-1)&&U(e)!==B(e-1)?W(e)*100:W(e)*80:0),Sr=Y(`EVENINGDOJISTAR`,`Evening Doji Star`,12,[[M,2],[P,1],[N,0]],(e,t,n)=>W(e-2)===1&&W(e)===-1&&Math.min(B(e-1),U(e-1))>Math.max(B(e-2),U(e-2))&&U(e)<U(e-2)-G(e-2)*n&&G(e-2)>J(M,t[0],e-2)&&G(e-1)<=J(P,t[1],e-1)&&G(e)>J(N,t[2],e)?-100:0,{pen:.3}),Cr=Y(`EVENINGSTAR`,`Evening Star`,12,[[M,2],[N,1],[N,0]],(e,t,n)=>W(e-2)===1&&W(e)===-1&&Math.min(B(e-1),U(e-1))>Math.max(B(e-2),U(e-2))&&U(e)<U(e-2)-G(e-2)*n&&G(e-2)>J(M,t[0],e-2)&&G(e-1)<=J(N,t[1],e-1)&&G(e)>J(N,t[2],e)?-100:0,{pen:.3}),wr=Y(`GAPSIDESIDEWHITE`,`Up/Down-gap side-by-side white lines`,7,[[R,1],[z,1]],(e,t)=>{let n=Math.min(B(e-1),U(e-1))>Math.max(B(e-2),U(e-2));return(n&&Math.min(B(e),U(e))>Math.max(B(e-2),U(e-2))||Math.max(B(e-1),U(e-1))<Math.min(B(e-2),U(e-2))&&Math.max(B(e),U(e))<Math.min(B(e-2),U(e-2)))&&W(e-1)===1&&W(e)===1&&G(e)>=G(e-1)-J(R,t[0],e-1)&&G(e)<=G(e-1)+J(R,t[0],e-1)&&B(e)>=B(e-1)-J(z,t[1],e-1)&&B(e)<=B(e-1)+J(z,t[1],e-1)?n?100:-100:0}),Tr=Y(`GRAVESTONEDOJI`,`Gravestone Doji`,10,[[P,0],[L,0]],(e,t)=>G(e)<=J(P,t[0],e)&&q(e)<J(L,t[1],e)&&K(e)>J(L,t[1],e)?100:0),Er=Y(`HAMMER`,`Hammer`,11,[[N,0],[L,0],[R,1]],(e,t)=>G(e)<J(N,t[0],e)&&q(e)>J(F,0,e)&&K(e)<J(L,t[1],e)&&Math.min(U(e),B(e))<=H(e-1)+J(R,t[2],e-1)?100:0),Dr=Y(`HANGINGMAN`,`Hanging Man`,11,[[N,0],[L,0],[R,1]],(e,t)=>G(e)<J(N,t[0],e)&&q(e)>J(F,0,e)&&K(e)<J(L,t[1],e)&&Math.min(U(e),B(e))>=V(e-1)-J(R,t[2],e-1)?-100:0),Or=Y(`HARAMI`,`Harami Pattern`,11,[[M,1],[N,0]],(e,t)=>{if(!(G(e-1)>J(M,t[0],e-1)&&G(e)<=J(N,t[1],e)))return 0;let n=Math.max(U(e),B(e)),r=Math.min(U(e),B(e)),i=Math.max(U(e-1),B(e-1)),a=Math.min(U(e-1),B(e-1));return n<i&&r>a?-W(e-1)*100:n<=i&&r>=a?-W(e-1)*80:0}),kr=Y(`HARAMICROSS`,`Harami Cross Pattern`,11,[[M,1],[P,0]],(e,t)=>{if(!(G(e-1)>J(M,t[0],e-1)&&G(e)<=J(P,t[1],e)))return 0;let n=Math.max(U(e),B(e)),r=Math.min(U(e),B(e)),i=Math.max(U(e-1),B(e-1)),a=Math.min(U(e-1),B(e-1));return n<i&&r>a?-W(e-1)*100:n<=i&&r>=a?-W(e-1)*80:0}),Ar=Y(`HIGHWAVE`,`High-Wave Candle`,10,[[N,0]],(e,t)=>G(e)<J(N,t[0],e)&&K(e)>J(Kn,0,e)&&q(e)>J(Kn,0,e)?W(e)*100:0);function jr(e,t,n){let r=n?10:5,i=r-3;return nr(e,t,[],e=>{let t=n?tr(e,R,2,i):null,a=e.col(),o=e.col(),s=e.col(),c=e.col();return[e.node((l,u,d)=>{Qn(e);let f=l.v,p=a.v,m=o.v,h=s.v,g=c.v;for(let e=u;e<d;e++){if(e<i){f[e]=NaN;continue}let a=e>i?p[e-1]:0,o=e>i?m[e-1]:0,s=e>i?h[e-1]:0,c=e>i?g[e-1]:0,l=0;(n?V(e-2)<V(e-3)&&H(e-2)>H(e-3)&&V(e-1)<V(e-2)&&H(e-1)>H(e-2)&&(V(e)<V(e-1)&&H(e)<H(e-1)&&U(e-2)<=H(e-2)+J(R,t.v[e],e-2)||V(e)>V(e-1)&&H(e)>H(e-1)&&U(e-2)>=V(e-2)-J(R,t.v[e],e-2)):V(e-1)<V(e-2)&&H(e-1)>H(e-2)&&(V(e)<V(e-1)&&H(e)<H(e-1)||V(e)>V(e-1)&&H(e)>H(e-1)))?(o=100*(V(e)<V(e-1)?1:-1),s=V(e-1),c=H(e-1),a=4,l=o):a>0&&(o>0&&U(e)>s||o<0&&U(e)<c)&&(l=o+100*(o>0?1:-1),a=0),a>0&&--a,p[e]=a,m[e]=o,h[e]=s,g[e]=c,f[e]=e>=r?l:NaN}})]})}let Mr=jr(`HIKKAKE`,`Hikkake Pattern`,!1),Nr=jr(`HIKKAKEMOD`,`Modified Hikkake Pattern`,!0),Pr=Y(`HOMINGPIGEON`,`Homing Pigeon`,11,[[M,1],[N,0]],(e,t)=>W(e-1)===-1&&W(e)===-1&&G(e-1)>J(M,t[0],e-1)&&G(e)<=J(N,t[1],e)&&B(e)<B(e-1)&&U(e)>U(e-1)?100:0),Fr=Y(`IDENTICAL3CROWS`,`Identical Three Crows`,12,[[L,2],[L,1],[L,0],[z,2],[z,1]],(e,t)=>W(e-2)===-1&&q(e-2)<J(L,t[0],e-2)&&W(e-1)===-1&&q(e-1)<J(L,t[1],e-1)&&W(e)===-1&&q(e)<J(L,t[2],e)&&U(e-2)>U(e-1)&&U(e-1)>U(e)&&B(e-1)<=U(e-2)+J(z,t[3],e-2)&&B(e-1)>=U(e-2)-J(z,t[3],e-2)&&B(e)<=U(e-1)+J(z,t[4],e-1)&&B(e)>=U(e-1)-J(z,t[4],e-1)?-100:0),Ir=Y(`INNECK`,`In-Neck Pattern`,11,[[z,1],[M,1]],(e,t)=>W(e-1)===-1&&G(e-1)>J(M,t[1],e-1)&&W(e)===1&&B(e)<H(e-1)&&U(e)<=U(e-1)+J(z,t[0],e-1)&&U(e)>=U(e-1)?-100:0),Lr=Y(`INVERTEDHAMMER`,`Inverted Hammer`,11,[[N,0],[L,0]],(e,t)=>Math.max(B(e),U(e))<Math.min(B(e-1),U(e-1))&&G(e)<J(N,t[0],e)&&K(e)>J(F,0,e)&&q(e)<J(L,t[1],e)?100:0);function Rr(e,t){return W(e-1)===-W(e)&&G(e-1)>J(M,t[2],e-1)&&K(e-1)<J(L,t[0],e-1)&&q(e-1)<J(L,t[0],e-1)&&G(e)>J(M,t[3],e)&&K(e)<J(L,t[1],e)&&q(e)<J(L,t[1],e)&&(W(e-1)===-1&&H(e)>V(e-1)||W(e-1)===1&&V(e)<H(e-1))}let zr=[[L,1],[L,0],[M,1],[M,0]],Br=Y(`KICKING`,`Kicking`,11,zr,(e,t)=>Rr(e,t)?W(e)*100:0),Vr=Y(`KICKINGBYLENGTH`,`Kicking - bull/bear determined by the longer marubozu`,11,zr,(e,t)=>Rr(e,t)?W(G(e)>G(e-1)?e:e-1)*100:0),Hr=Y(`LADDERBOTTOM`,`Ladder Bottom`,14,[[L,1]],(e,t)=>W(e-4)===-1&&W(e-3)===-1&&W(e-2)===-1&&B(e-4)>B(e-3)&&B(e-3)>B(e-2)&&U(e-4)>U(e-3)&&U(e-3)>U(e-2)&&W(e-1)===-1&&K(e-1)>J(L,t[0],e-1)&&W(e)===1&&B(e)>B(e-1)&&U(e)>V(e-1)?100:0),Ur=Y(`LONGLEGGEDDOJI`,`Long Legged Doji`,10,[[P,0]],(e,t)=>G(e)<=J(P,t[0],e)&&(q(e)>J(F,0,e)||K(e)>J(F,0,e))?100:0),Wr=Y(`LONGLINE`,`Long Line Candle`,10,[[M,0],[I,0]],(e,t)=>G(e)>J(M,t[0],e)&&K(e)<J(I,t[1],e)&&q(e)<J(I,t[1],e)?W(e)*100:0),Gr=Y(`MARUBOZU`,`Marubozu`,10,[[M,0],[L,0]],(e,t)=>G(e)>J(M,t[0],e)&&K(e)<J(L,t[1],e)&&q(e)<J(L,t[1],e)?W(e)*100:0),Kr=Y(`MATCHINGLOW`,`Matching Low`,6,[[z,1]],(e,t)=>W(e-1)===-1&&W(e)===-1&&U(e)<=U(e-1)+J(z,t[0],e-1)&&U(e)>=U(e-1)-J(z,t[0],e-1)?100:0),qr=Y(`MATHOLD`,`Mat Hold`,14,[[M,4],[N,3],[N,2],[N,1]],(e,t,n)=>W(e-4)===1&&W(e-3)===-1&&W(e)===1&&Math.min(B(e-3),U(e-3))>Math.max(B(e-4),U(e-4))&&Math.min(B(e-2),U(e-2))<U(e-4)&&Math.min(B(e-1),U(e-1))<U(e-4)&&Math.min(B(e-2),U(e-2))>U(e-4)-G(e-4)*n&&Math.min(B(e-1),U(e-1))>U(e-4)-G(e-4)*n&&Math.max(U(e-2),B(e-2))<B(e-3)&&Math.max(U(e-1),B(e-1))<Math.max(U(e-2),B(e-2))&&B(e)>U(e-1)&&U(e)>Math.max(Math.max(V(e-3),V(e-2)),V(e-1))&&G(e-4)>J(M,t[0],e-4)&&G(e-3)<J(N,t[1],e-3)&&G(e-2)<J(N,t[2],e-2)&&G(e-1)<J(N,t[3],e-1)?100:0,{pen:.5}),Jr=Y(`MORNINGDOJISTAR`,`Morning Doji Star`,12,[[M,2],[P,1],[N,0]],(e,t,n)=>W(e-2)===-1&&W(e)===1&&Math.max(B(e-1),U(e-1))<Math.min(B(e-2),U(e-2))&&U(e)>er(G(e-2),n,U(e-2))&&G(e-2)>J(M,t[0],e-2)&&G(e-1)<=J(P,t[1],e-1)&&G(e)>J(N,t[2],e)?100:0,{pen:.3}),Yr=Y(`MORNINGSTAR`,`Morning Star`,12,[[M,2],[N,1],[N,0]],(e,t,n)=>W(e-2)===-1&&W(e)===1&&Math.max(B(e-1),U(e-1))<Math.min(B(e-2),U(e-2))&&U(e)>er(G(e-2),n,U(e-2))&&G(e-2)>J(M,t[0],e-2)&&G(e-1)<=J(N,t[1],e-1)&&G(e)>J(N,t[2],e)?100:0,{pen:.3}),Xr=Y(`ONNECK`,`On-Neck Pattern`,11,[[z,1],[M,1]],(e,t)=>W(e-1)===-1&&G(e-1)>J(M,t[1],e-1)&&W(e)===1&&B(e)<H(e-1)&&U(e)<=H(e-1)+J(z,t[0],e-1)&&U(e)>=H(e-1)-J(z,t[0],e-1)?-100:0),Zr=Y(`PIERCING`,`Piercing Pattern`,11,[[M,1],[M,0]],(e,t)=>W(e-1)===-1&&G(e-1)>J(M,t[0],e-1)&&W(e)===1&&G(e)>J(M,t[1],e)&&B(e)<H(e-1)&&U(e)<B(e-1)&&U(e)>er(G(e-1),.5,U(e-1))?100:0),Qr=Y(`RICKSHAWMAN`,`Rickshaw Man`,10,[[P,0],[R,0]],(e,t)=>G(e)<=J(P,t[0],e)&&q(e)>J(F,0,e)&&K(e)>J(F,0,e)&&Math.min(B(e),U(e))<=H(e)+(V(e)-H(e))/2+J(R,t[1],e)&&Math.max(B(e),U(e))>=H(e)+(V(e)-H(e))/2-J(R,t[1],e)?100:0),$r=Y(`RISEFALL3METHODS`,`Rising/Falling Three Methods`,14,[[M,4],[N,3],[N,2],[N,1],[M,0]],(e,t)=>{let n=W(e-4);return W(e-4)===-W(e-3)&&W(e-3)===W(e-2)&&W(e-2)===W(e-1)&&W(e-1)===-W(e)&&Math.min(B(e-3),U(e-3))<V(e-4)&&Math.max(B(e-3),U(e-3))>H(e-4)&&Math.min(B(e-2),U(e-2))<V(e-4)&&Math.max(B(e-2),U(e-2))>H(e-4)&&Math.min(B(e-1),U(e-1))<V(e-4)&&Math.max(B(e-1),U(e-1))>H(e-4)&&U(e-2)*n<U(e-3)*n&&U(e-1)*n<U(e-2)*n&&B(e)*n>U(e-1)*n&&U(e)*n>U(e-4)*n&&G(e-4)>J(M,t[0],e-4)&&G(e-3)<J(N,t[1],e-3)&&G(e-2)<J(N,t[2],e-2)&&G(e-1)<J(N,t[3],e-1)&&G(e)>J(M,t[4],e)?100*n:0}),ei=Y(`SEPARATINGLINES`,`Separating Lines`,11,[[L,0],[M,0],[z,1]],(e,t)=>W(e-1)===-W(e)&&B(e)<=B(e-1)+J(z,t[2],e-1)&&B(e)>=B(e-1)-J(z,t[2],e-1)&&G(e)>J(M,t[1],e)&&(W(e)===1&&q(e)<J(L,t[0],e)||W(e)===-1&&K(e)<J(L,t[0],e))?W(e)*100:0),ti=Y(`SHOOTINGSTAR`,`Shooting Star`,11,[[N,0],[L,0]],(e,t)=>Math.min(B(e),U(e))>Math.max(B(e-1),U(e-1))&&G(e)<J(N,t[0],e)&&K(e)>J(F,0,e)&&q(e)<J(L,t[1],e)?-100:0),ni=Y(`SHORTLINE`,`Short Line Candle`,10,[[N,0],[I,0]],(e,t)=>G(e)<J(N,t[0],e)&&K(e)<J(I,t[1],e)&&q(e)<J(I,t[1],e)?W(e)*100:0),ri=Y(`SPINNINGTOP`,`Spinning Top`,10,[[N,0]],(e,t)=>K(e)>G(e)&&q(e)>G(e)&&G(e)<J(N,t[0],e)?W(e)*100:0),ii=Y(`STALLEDPATTERN`,`Stalled Pattern`,12,[[M,2],[M,1],[N,0],[L,1],[R,2],[R,1]],(e,t)=>W(e-2)===1&&W(e-1)===1&&W(e)===1&&U(e)>U(e-1)&&U(e-1)>U(e-2)&&G(e-2)>J(M,t[0],e-2)&&G(e-1)>J(M,t[1],e-1)&&K(e-1)<J(L,t[3],e-1)&&B(e-1)>B(e-2)&&B(e-1)<=U(e-2)+J(R,t[4],e-2)&&G(e)<J(N,t[2],e)&&B(e)>=U(e-1)-G(e)-J(R,t[5],e-1)?-100:0),ai=Y(`STICKSANDWICH`,`Stick Sandwich`,7,[[z,2]],(e,t)=>W(e-2)===-1&&W(e-1)===1&&W(e)===-1&&H(e-1)>U(e-2)&&U(e)<=U(e-2)+J(z,t[0],e-2)&&U(e)>=U(e-2)-J(z,t[0],e-2)?100:0),oi=Y(`TAKURI`,`Takuri (Dragonfly Doji with very long lower shadow)`,10,[[P,0],[L,0]],(e,t)=>G(e)<=J(P,t[0],e)&&K(e)<J(L,t[1],e)&&q(e)>J(Kn,0,e)?100:0),si=Y(`TASUKIGAP`,`Tasuki Gap`,7,[[R,1]],(e,t)=>Math.min(B(e-1),U(e-1))>Math.max(B(e-2),U(e-2))&&W(e-1)===1&&W(e)===-1&&B(e)<U(e-1)&&B(e)>B(e-1)&&U(e)<B(e-1)&&U(e)>Math.max(U(e-2),B(e-2))&&Math.abs(G(e-1)-G(e))<J(R,t[0],e-1)||Math.max(B(e-1),U(e-1))<Math.min(B(e-2),U(e-2))&&W(e-1)===-1&&W(e)===1&&B(e)<B(e-1)&&B(e)>U(e-1)&&U(e)>B(e-1)&&U(e)<Math.min(U(e-2),B(e-2))&&Math.abs(G(e-1)-G(e))<J(R,t[0],e-1)?W(e-1)*100:0),ci=Y(`THRUSTING`,`Thrusting Pattern`,11,[[z,1],[M,1]],(e,t)=>W(e-1)===-1&&G(e-1)>J(M,t[1],e-1)&&W(e)===1&&B(e)<H(e-1)&&U(e)>U(e-1)+J(z,t[0],e-1)&&U(e)<=er(G(e-1),.5,U(e-1))?-100:0),li=Y(`TRISTAR`,`Tristar Pattern`,12,[[P,2]],(e,t)=>{if(!(G(e-2)<=J(P,t[0],e-2)&&G(e-1)<=J(P,t[0],e-2)&&G(e)<=J(P,t[0],e-2)))return 0;let n=0;return Math.min(B(e-1),U(e-1))>Math.max(B(e-2),U(e-2))&&Math.max(B(e),U(e))<Math.max(B(e-1),U(e-1))&&(n=-100),Math.max(B(e-1),U(e-1))<Math.min(B(e-2),U(e-2))&&Math.min(B(e),U(e))>Math.min(B(e-1),U(e-1))&&(n=100),n}),ui=Y(`UNIQUE3RIVER`,`Unique 3 River`,12,[[M,2],[N,0]],(e,t)=>W(e-2)===-1&&W(e-1)===-1&&W(e)===1&&U(e-1)>U(e-2)&&B(e-1)<=B(e-2)&&H(e-1)<H(e-2)&&B(e)>H(e-1)&&G(e-2)>J(M,t[0],e-2)&&G(e)<J(N,t[1],e)?100:0),di=Y(`UPSIDEGAP2CROWS`,`Upside Gap Two Crows`,12,[[M,2],[N,1]],(e,t)=>W(e-2)===1&&G(e-2)>J(M,t[0],e-2)&&W(e-1)===-1&&G(e-1)<=J(N,t[1],e-1)&&Math.min(B(e-1),U(e-1))>Math.max(B(e-2),U(e-2))&&W(e)===-1&&B(e)>B(e-1)&&U(e)<U(e-1)&&U(e)>U(e-2)?-100:0),fi=Y(`XSIDEGAP3METHODS`,`Upside/Downside Gap Three Methods`,2,[],e=>W(e-2)===W(e-1)&&W(e-1)===-W(e)&&B(e)<Math.max(U(e-1),B(e-1))&&B(e)>Math.min(U(e-1),B(e-1))&&U(e)<Math.max(U(e-2),B(e-2))&&U(e)>Math.min(U(e-2),B(e-2))&&(W(e-2)===1&&Math.min(B(e-1),U(e-1))>Math.max(B(e-2),U(e-2))||W(e-2)===-1&&Math.max(B(e-1),U(e-1))<Math.min(B(e-2),U(e-2)))?W(e-2)*100:0);var pi=/* @__PURE__ */ t({alligator:()=>zi,alma:()=>Si,chandeKrollStop:()=>Pi,donchian:()=>Mi,envelopes:()=>ki,fractals:()=>Vi,hma:()=>xi,ichimoku:()=>Li,keltner:()=>Ai,linregChannel:()=>Fi,lsma:()=>Ci,maCross:()=>Oi,maRibbon:()=>Di,mcginley:()=>wi,median:()=>Ii,priceChannel:()=>Ni,smma:()=>yi,supertrend:()=>Ri,vwma:()=>bi,zigzag:()=>Hi});let X=NaN,Z=(e,t=1)=>h(`length`,e,t,5e3),mi=(e,t)=>{let n=parseInt(e.slice(1),16);return`rgba(${n>>16},${n>>8&255},${n&255},${t})`};function hi(e){let{high:t,low:n,close:r}=e;return e.node((e,i,a)=>{let o=t.v,s=n.v,c=r.v,l=e.v;for(let e=i;e<a;e++){let t=o[e]-s[e];if(e===0){l[e]=t;continue}let n=c[e-1],r=Math.abs(o[e]-n),i=Math.abs(s[e]-n);l[e]=t>r?t>i?t:i:r>i?r:i}})}let gi=(e,t)=>e.rma(hi(e),t);function _i(e,t,n){if(!Number.isInteger(n)||n<2)throw RangeError(`linreg: period must be an integer >= 2, got ${n}`);let r=e.validRun(t),i=n*(n-1)/2,a=n*(n*(n-1)*(2*n-1)/6)-i*i,o=e.col(),s=e.col();return{value:e.node((e,c,l)=>{let u=t.v,d=r.v,f=o.v,p=s.v,m=e.v;for(let e=c;e<l;e++){if(d[e]<n){f[e]=X,p[e]=X,m[e]=X;continue}let t=0,r=0;for(let i=0;i<n;i++){let a=u[e-n+1+i];t+=a,r+=i*a}let o=(n*r-i*t)/a,s=(t-o*i)/n;f[e]=o,p[e]=s,m[e]=s+o*(n-1)}}),slope:o,intercept:s}}let vi=(e,t,n,r)=>t===`ema`?e.ema(n,r):e.sma(n,r),yi=D({id:`smma`,name:`Smoothed Moving Average`,family:`tv`,needs:`value`,pane:`overlay`,inputs:[Z(7),y()],columns:[`smma`],plots:[x(`smma`,b.teal)],label:e=>`${e.length}`,build:(e,t)=>[e.rma(e.src(t.source),t.length)],reference:`TradingView Smoothed Moving Average: smma := na(smma[1]) ? ta.sma(src, n) : (smma[1] * (n - 1) + src) / n`}),bi=D({id:`vwma`,name:`Volume Weighted Moving Average`,family:`tv`,needs:`ohlcv`,pane:`overlay`,inputs:[Z(20),y()],columns:[`vwma`],plots:[x(`vwma`,b.purple)],label:e=>`${e.length}`,build:(e,t)=>[e.div(e.sum(e.mul(e.src(t.source),e.volume),t.length),e.sum(e.volume,t.length))],reference:`Pine ta.vwma(src, n) = ta.sma(src * volume, n) / ta.sma(volume, n)`}),xi=D({id:`hma`,name:`Hull Moving Average`,family:`tv`,needs:`value`,pane:`overlay`,inputs:[Z(9,2),y()],columns:[`hma`],plots:[x(`hma`,b.pink)],label:e=>`${e.length}`,build:(e,t)=>{let n=e.src(t.source),r=Math.floor(t.length/2),i=Math.round(Math.sqrt(t.length)),a=e.map2(e.wma(n,r),e.wma(n,t.length),(e,t)=>2*e-t);return[e.wma(a,i)]},reference:`Pine ta.hma(src, n) = ta.wma(2 * ta.wma(src, n / 2) - ta.wma(src, n), round(sqrt(n))), with n / 2 truncated to an int`}),Si=D({id:`alma`,name:`Arnaud Legoux Moving Average`,family:`tv`,needs:`value`,pane:`overlay`,inputs:[Z(9),g(`offset`,.85,0,1,.05),g(`sigma`,6,.1,100,.5),y()],columns:[`alma`],plots:[x(`alma`,b.blue)],label:e=>`${e.length}, ${e.offset}, ${e.sigma}`,build:(e,t)=>{let n=t.length,r=Math.floor(t.offset*(n-1)),i=n/t.sigma,a=new Float64Array(n),o=0;for(let e=0;e<n;e++)a[e]=Math.exp(-((e-r)**2)/(2*i*i)),o+=a[e];let s=e.src(t.source),c=e.validRun(s);return[e.node((e,t,r)=>{let i=s.v,l=c.v,u=e.v;for(let e=t;e<r;e++){if(l[e]<n){u[e]=X;continue}let t=0;for(let r=0;r<n;r++)t+=i[e-n+1+r]*a[r];u[e]=t/o}})]},reference:`Pine ta.alma(src, n, offset, sigma): m = floor(offset * (n - 1)), s = n / sigma, w_k = exp(-(k - m)^2 / (2 s^2)), sum(src[n-1-k] * w_k) / sum(w_k)`}),Ci=D({id:`lsma`,name:`Least Squares Moving Average`,family:`tv`,needs:`value`,pane:`overlay`,inputs:[Z(25,2),h(`offset`,0,-5e3,5e3),y()],columns:[`lsma`],plots:[x(`lsma`,b.orange)],label:e=>`${e.length}, ${e.offset}`,build:(e,t)=>{let n=_i(e,e.src(t.source),t.length);return[e.map2(n.value,n.slope,(e,n)=>e-t.offset*n)]},reference:`TradingView Least Squares Moving Average = Pine ta.linreg(src, n, offset); offset 0 equals TA-Lib LINEARREG`}),wi=D({id:`mcginley`,name:`McGinley Dynamic`,family:`tv`,needs:`value`,pane:`overlay`,inputs:[Z(14),y()],columns:[`mcginley`],plots:[x(`mcginley`,b.green)],label:e=>`${e.length}`,build:(e,t)=>{let n=t.length,r=e.src(t.source),i=e.ema(r,n);return[e.node((e,t,a)=>{let o=r.v,s=i.v,c=e.v;for(let e=t;e<a;e++){let t=e>0?c[e-1]:X;c[e]=t===t?t+(o[e]-t)/(n*(o[e]/t)**4):s[e]}})]},reference:`TradingView McGinley Dynamic: mg := na(mg[1]) ? ta.ema(src, n) : mg[1] + (src - mg[1]) / (n * (src / mg[1])^4)`}),Ti=[b.blue,b.teal,b.green,b.lime,b.yellow,b.orange,b.red,b.pink],Ei=Ti.map((e,t)=>`ma${t+1}`),Di=D({id:`ma-ribbon`,name:`Moving Average Ribbon`,family:`tv`,needs:`value`,pane:`overlay`,inputs:[h(`first`,20,1,5e3,`first`),h(`step`,5,1,1e3,`step`),y()],columns:Ei,plots:Ei.map((e,t)=>x(e,Ti[t],{title:`MA ${t+1}`,width:1})),label:e=>`${e.first}, ${e.step}`,build:(e,t)=>{let n=t.first+7*t.step;if(n>5e3)throw RangeError(`ma-ribbon: the 8th period ${n} exceeds 5000`);let r=e.src(t.source);return Ei.map((n,i)=>e.sma(r,t.first+i*t.step))},reference:`Moving Average Ribbon: eight simple moving averages of periods first, first + step, ... first + 7 * step (default 20..55 step 5)`}),Oi=D({id:`ma-cross`,name:`Moving Average Cross`,family:`tv`,needs:`value`,pane:`overlay`,inputs:[v(`type`,`sma`,[`sma`,`ema`]),h(`fast`,9,1,5e3),h(`slow`,21,1,5e3),y()],columns:[`fast`,`slow`,`crossUp`,`crossDown`],plots:[x(`fast`,b.blue,{title:`Fast MA`}),x(`slow`,b.orange,{title:`Slow MA`}),E(`crossUp`,`circle`,`value`,b.green,{title:`Cross up`}),E(`crossDown`,`circle`,`value`,b.red,{title:`Cross down`})],label:e=>`${e.type}, ${e.fast}, ${e.slow}`,build:(e,t)=>{let n=e.src(t.source),r=vi(e,t.type,n,t.fast),i=vi(e,t.type,n,t.slow);return[r,i,e.calc(e=>e>0&&r.v[e]>i.v[e]&&r.v[e-1]<=i.v[e-1]?r.v[e]:X),e.calc(e=>e>0&&r.v[e]<i.v[e]&&r.v[e-1]>=i.v[e-1]?r.v[e]:X)]},reference:`TradingView Moving Average Cross: two moving averages, circles where ta.crossover / ta.crossunder(fast, slow) is true`}),ki=D({id:`envelopes`,name:`Moving Average Envelopes`,family:`tv`,needs:`value`,pane:`overlay`,inputs:[Z(20),g(`percent`,10,0,100,.5),v(`basis`,`sma`,[`sma`,`ema`]),y()],columns:[`basis`,`upper`,`lower`],plots:[x(`basis`,b.orange,{title:`Basis`}),C(`band`,`upper`,`lower`,b.blue,mi(b.blue,.08),`Envelope`)],label:e=>`${e.length}, ${e.percent}, ${e.basis}`,build:(e,t)=>{let n=vi(e,t.basis,e.src(t.source),t.length),r=t.percent/100;return[n,e.map(n,e=>e*(1+r)),e.map(n,e=>e*(1-r))]},reference:`TradingView Envelope: basis = sma|ema(src, n), upper = basis * (1 + percent / 100), lower = basis * (1 - percent / 100)`}),Ai=D({id:`keltner`,name:`Keltner Channels`,family:`tv`,needs:`ohlc`,pane:`overlay`,inputs:[Z(20),g(`mult`,2,0,100,.25),h(`atrLength`,10,1,5e3),_(`useEma`,!0),y()],columns:[`basis`,`upper`,`lower`],plots:[x(`basis`,b.blue,{title:`Basis`}),C(`band`,`upper`,`lower`,b.blue,mi(b.blue,.08),`Channel`)],label:e=>`${e.length}, ${e.mult}, ${e.atrLength}`,build:(e,t)=>{let n=e.src(t.source),r=t.useEma?e.ema(n,t.length):e.sma(n,t.length),i=e.map(gi(e,t.atrLength),e=>e*t.mult);return[r,e.add(r,i),e.sub(r,i)]},reference:`TradingView Keltner Channels (ATR band style): basis = ema|sma(src, n), bands = basis +- mult * ta.atr(atrLength)`});function ji(e,t){let n=e.highest(e.high,t),r=e.lowest(e.low,t);return{upper:n,lower:r,mid:e.map2(n,r,(e,t)=>(e+t)/2)}}let Mi=D({id:`donchian`,name:`Donchian Channels`,family:`tv`,needs:`ohlc`,pane:`overlay`,inputs:[Z(20)],columns:[`upper`,`lower`,`basis`],plots:[C(`band`,`upper`,`lower`,b.blue,mi(b.blue,.08),`Channel`),x(`basis`,b.orange,{title:`Basis`})],label:e=>`${e.length}`,build:(e,t)=>{let n=ji(e,t.length);return[n.upper,n.lower,n.mid]},reference:`TradingView Donchian Channels: upper = ta.highest(high, n), lower = ta.lowest(low, n), basis = (upper + lower) / 2; equals TA-Lib MAX(high), MIN(low), MIDPRICE`}),Ni=D({id:`price-channel`,name:`Price Channel`,family:`tv`,needs:`ohlc`,pane:`overlay`,inputs:[Z(20)],columns:[`upper`,`lower`,`center`],plots:[x(`upper`,b.green,{title:`Highest high`}),x(`lower`,b.red,{title:`Lowest low`}),x(`center`,b.gray,{title:`Center`,style:`dashed`})],label:e=>`${e.length}`,build:(e,t)=>{let n=ji(e,t.length);return[n.upper,n.lower,n.mid]},reference:`Price Channel: highest high and lowest low of the last n bars with their midline; equals TA-Lib MAX(high), MIN(low), MIDPRICE`}),Pi=D({id:`chande-kroll-stop`,name:`Chande Kroll Stop`,family:`tv`,needs:`ohlc`,pane:`overlay`,inputs:[h(`p`,10,1,5e3),g(`x`,1,0,100,.25),h(`q`,9,1,5e3)],columns:[`stopShort`,`stopLong`],plots:[x(`stopShort`,b.red,{title:`Stop short`}),x(`stopLong`,b.green,{title:`Stop long`})],label:e=>`${e.p}, ${e.x}, ${e.q}`,build:(e,t)=>{let n=e.map(gi(e,t.p),e=>e*t.x),r=e.sub(e.highest(e.high,t.p),n),i=e.add(e.lowest(e.low,t.p),n);return[e.highest(r,t.q),e.lowest(i,t.q)]},reference:`TradingView Chande Kroll Stop: first_high = ta.highest(high, p) - x * ta.atr(p); first_low = ta.lowest(low, p) + x * ta.atr(p); stop_short = ta.highest(first_high, q); stop_long = ta.lowest(first_low, q)`}),Fi=D({id:`linreg-channel`,name:`Linear Regression Channel`,family:`tv`,needs:`value`,pane:`overlay`,inputs:[Z(100,2),g(`upperDev`,2,0,100,.25),g(`lowerDev`,2,0,100,.25),y()],columns:[`base`,`upper`,`lower`],plots:[x(`base`,b.orange,{title:`Base`}),C(`band`,`upper`,`lower`,b.blue,mi(b.blue,.08),`Channel`)],label:e=>`${e.length}, ${e.upperDev}, ${e.lowerDev}`,build:(e,t)=>{let n=t.length,r=e.src(t.source),i=_i(e,r,n),a=e.node((e,t,a)=>{let o=r.v,s=i.slope.v,c=i.intercept.v,l=e.v;for(let e=t;e<a;e++){let t=s[e],r=c[e];if(t!==t){l[e]=X;continue}let i=0;for(let a=0;a<n;a++){let s=o[e-n+1+a]-(r+t*a);i+=s*s}l[e]=Math.sqrt(i/n)}});return[i.value,e.map2(i.value,a,(e,n)=>e+t.upperDev*n),e.map2(i.value,a,(e,n)=>e-t.lowerDev*n)]},reference:`TradingView Linear Regression Channel: base = linear regression value at the newest bar over n bars (Pine ta.linreg(src, n, 0)), bands = base +- deviation * population stdev of the residuals. TradingView draws the tool as one anchored segment between two chosen bars; this study is the rolling per-bar form (each bar's own n-bar fit, newest point), not the anchored line.`}),Ii=D({id:`median`,name:`Median`,family:`tv`,needs:`ohlc`,pane:`overlay`,inputs:[Z(3),h(`atrLength`,14,1,5e3),g(`mult`,2,0,100,.25),y(`hl2`)],columns:[`median`,`upper`,`lower`],plots:[x(`median`,b.blue,{title:`Median`}),C(`band`,`upper`,`lower`,b.gray,mi(b.gray,.08),`ATR band`)],label:e=>`${e.length}, ${e.atrLength}, ${e.mult}`,build:(e,t)=>{let n=t.length,r=e.src(t.source),i=e.validRun(r),a=e.node((e,t,a)=>{let o=r.v,s=i.v,c=e.v,l=new Float64Array(n);for(let e=t;e<a;e++)if(s[e]<n)c[e]=X;else{for(let t=0;t<n;t++)l[t]=o[e-n+1+t];l.sort(),c[e]=n%2==1?l[(n-1)/2]:(l[n/2-1]+l[n/2])/2}}),o=e.map(gi(e,t.atrLength),e=>e*t.mult);return[a,e.add(a,o),e.sub(a,o)]},reference:`TradingView Median: rolling median of src (hl2) over n bars with an ATR band, median +- mult * ta.atr(atrLength). The band construction follows the task's definition; an even n takes the mean of the two middle values.`}),Li=D({id:`ichimoku`,name:`Ichimoku Cloud`,family:`tv`,needs:`ohlc`,pane:`overlay`,inputs:[h(`conversion`,9,1,5e3),h(`base`,26,1,5e3),h(`spanB`,52,1,5e3)],columns:[`conversion`,`base`,`spanA`,`spanB`,`lagging`],plots:[x(`conversion`,b.blue,{title:`Conversion line`}),x(`base`,b.red,{title:`Base line`}),w(`cloud`,`spanA`,`spanB`,b.green,`Cloud`),x(`spanA`,b.green,{title:`Leading span A`,offset:25}),x(`spanB`,b.orange,{title:`Leading span B`,offset:25}),x(`lagging`,b.purple,{title:`Lagging span`,offset:-25})],label:e=>`${e.conversion}, ${e.base}, ${e.spanB}, 26`,build:(e,t)=>{let n=ji(e,t.conversion).mid,r=ji(e,t.base).mid;return[n,r,e.map2(n,r,(e,t)=>(e+t)/2),ji(e,t.spanB).mid,e.map(e.close,e=>e)]},reference:`TradingView Ichimoku Cloud: donchian(n) = (ta.highest(high, n) + ta.lowest(low, n)) / 2; conversion = donchian(9), base = donchian(26), span A = (conversion + base) / 2, span B = donchian(52), lagging = close; leading spans plotted with offset displacement - 1 = 25, the lagging span with -25 (TradingView's own plot offsets for displacement 26). Columns hold the undisplaced values.`}),Ri=D({id:`supertrend`,name:`Supertrend`,family:`tv`,needs:`ohlc`,pane:`overlay`,inputs:[h(`atrLength`,10,1,5e3),g(`factor`,3,.1,100,.1)],columns:[`up`,`down`,`direction`],plots:[x(`up`,b.green,{title:`Up trend`}),x(`down`,b.red,{title:`Down trend`})],label:e=>`${e.factor}, ${e.atrLength}`,build:(e,t)=>{let{high:n,low:r,close:i}=e,a=gi(e,t.atrLength),o=e.col(),s=e.col(),c=e.col(),l=e.col(),u=e.node((e,u,d)=>{let f=n.v,p=r.v,m=i.v,h=a.v,g=o.v,_=s.v,v=c.v,y=l.v;for(let n=u;n<d;n++){let r=h[n];if(r!==r){g[n]=X,_[n]=X,v[n]=X,y[n]=X,e.v[n]=X;continue}let i=(f[n]+p[n])/2,a=i-t.factor*r,o=i+t.factor*r,s=n===0||g[n-1]!==g[n-1];if(!s){let e=g[n-1],t=_[n-1],r=m[n-1];a=a>e||r<e?a:e,o=o<t||r>t?o:t}let c;c=s?1:y[n-1]===_[n-1]?m[n]>o?-1:1:m[n]<a?1:-1,g[n]=a,_[n]=o,v[n]=c,y[n]=c===-1?a:o,e.v[n]=c}});return[e.calc(e=>c.v[e]===-1?l.v[e]:X),e.calc(e=>c.v[e]===1?l.v[e]:X),u]},reference:"Pine ta.supertrend(factor, atrPeriod): bands hl2 +- factor * ta.atr; direction is Pine's: -1 = uptrend (line below price, column `up`), 1 = downtrend (line above price, column `down`)"}),zi=D({id:`alligator`,name:`Williams Alligator`,family:`tv`,needs:`ohlc`,pane:`overlay`,inputs:[h(`jawLength`,13,1,5e3),h(`teethLength`,8,1,5e3),h(`lipsLength`,5,1,5e3),y(`hl2`)],columns:[`jaw`,`teeth`,`lips`],plots:[x(`jaw`,b.blue,{title:`Jaw`,offset:8}),x(`teeth`,b.red,{title:`Teeth`,offset:5}),x(`lips`,b.green,{title:`Lips`,offset:3})],label:e=>`${e.jawLength}, ${e.teethLength}, ${e.lipsLength}`,build:(e,t)=>{let n=e.src(t.source);return[e.rma(n,t.jawLength),e.rma(n,t.teethLength),e.rma(n,t.lipsLength)]},reference:`TradingView Williams Alligator: jaw = smma(hl2, 13) shifted 8 bars, teeth = smma(hl2, 8) shifted 5, lips = smma(hl2, 5) shifted 3 (the shifts are fixed plot offsets, not inputs)`});function Bi(e,t,n){return e.node((e,r,i)=>{let a=t.v,o=e.v;for(let e=r;e<i;e++){o[e]=X;let t=e-2;if(t<0)continue;let r=a[t],i=e=>n?e<r:e>r,s=!0;for(let e=1;e<=2&&s;e++)s=i(a[t+e]);if(!s)continue;let c=0;for(;c<=4&&t-1-c>=0&&a[t-1-c]===r;)c++;let l=t-1-c;c<=4&&l>=0&&i(a[l])&&(o[e]=r)}})}let Vi=D({id:`fractals`,name:`Williams Fractals`,family:`tv`,needs:`ohlc`,pane:`overlay`,inputs:[],columns:[`up`,`down`],plots:[E(`up`,`triangleUp`,`above`,b.green,{title:`Up fractal`,offset:-2}),E(`down`,`triangleDown`,`below`,b.red,{title:`Down fractal`,offset:-2})],build:e=>[Bi(e,e.high,!0),Bi(e,e.low,!1)],reference:`TradingView Williams Fractals (n = 2): high[n] strictly above the n bars after it, and above the bars before it allowing up to four tied equal highs followed by a strictly lower one; mirrored for lows. Confirmed n bars late.`}),Hi=D({id:`zigzag`,name:`ZigZag`,family:`tv`,needs:`ohlc`,pane:`overlay`,inputs:[g(`deviation`,5,.01,100,.5),h(`depth`,10,1,5e3)],columns:[`price`,`back`,`live`,`liveBack`],plots:[{kind:`zigzag`,key:`zigzag`,title:`ZigZag`,price:`price`,back:`back`,color:b.blue,width:2}],label:e=>`${e.deviation}, ${e.depth}`,build:(e,t)=>{let{high:n,low:r}=e,i=t.deviation/100,a=t.depth,o=e.col(),s=e.col(),c=e.col(),l=e.col(),u=e.col(),d=e.col(),f=e.col(),p=e.col(),m=e.col(),h=e.col(),g=e.col();return[e.node((e,t,_)=>{let v=n.v,y=r.v,b=e.v;for(let e=t;e<_;e++){let t=0,n=X,r=X,_=X,x=v[e],S=e,C=y[e],w=e;e>0&&(t=o.v[e-1],n=s.v[e-1],r=c.v[e-1],_=l.v[e-1],x=u.v[e-1],S=d.v[e-1],C=f.v[e-1],w=p.v[e-1]);let T=X,E=X;t===0?(v[e]>x&&(x=v[e],S=e),y[e]<C&&(C=y[e],w=e),S>w&&x>=C*(1+i)?(T=C,E=e-w,_=w,t=1,n=x,r=S):w>S&&C<=x*(1-i)&&(T=x,E=e-S,_=S,t=-1,n=C,r=w)):t===1?v[e]>n?(n=v[e],r=e):y[e]<=n*(1-i)&&e-_>=a&&(T=n,E=e-r,_=r,t=-1,n=y[e],r=e):y[e]<n?(n=y[e],r=e):v[e]>=n*(1+i)&&e-_>=a&&(T=n,E=e-r,_=r,t=1,n=v[e],r=e),o.v[e]=t,s.v[e]=n,c.v[e]=r,l.v[e]=_,u.v[e]=x,d.v[e]=S,f.v[e]=C,p.v[e]=w,b[e]=T,m.v[e]=E,h.v[e]=t===0?X:n,g.v[e]=t===0?X:e-r}}),e.alias(m),e.alias(h),e.alias(g)]},reference:`ZigZag as defined in this file's header: percentage-reversal pivots on high/low with a minimum spacing in bars, confirmed causally`});var Ui=/* @__PURE__ */ t({accelerator:()=>da,awesome:()=>ua,bullBearPower:()=>ca,choppiness:()=>ra,connorsRsi:()=>na,coppock:()=>ta,dpo:()=>pa,fisher:()=>Zi,kst:()=>Qi,massIndex:()=>fa,rankCorr:()=>sa,rviVigor:()=>ia,rviVolatility:()=>aa,schaffTc:()=>ma,smiErgodic:()=>oa,stochTv:()=>ha,tsi:()=>$i,vortex:()=>ea});let Q=NaN;function Wi(e,t,n){return e.node((e,r,i)=>{let a=t.v,o=e.v;for(let e=r;e<i;e++){let t=e>=n?a[e-n]:Q;o[e]=t===0?Q:100*(a[e]-t)/t}})}function Gi(e,t,n){let r=e.change(t,1),i=e.map(r,e=>e>0?e:e===e?0:Q),a=e.map(r,e=>e<0?-e:e===e?0:Q),o=e.rma(i,n),s=e.rma(a,n);return e.map2(o,s,(e,t)=>e!==e||t!==t?Q:t===0?100:e===0?0:100-100/(1+e/t))}function Ki(e,t,n,r){return e.ema(e.ema(t,n),r)}function qi(e,t){return e.calc(e=>e>=3?(t.v[e]+2*t.v[e-1]+2*t.v[e-2]+t.v[e-3])/6:Q)}function Ji(e){let{high:t,low:n,close:r}=e;return e.calc(e=>{let i=t.v[e],a=n.v[e];if(e===0)return i-a;let o=r.v[e-1];return Math.max(i-a,Math.abs(i-o),Math.abs(a-o))})}function Yi(e,t){let n=e.change(t,1);return{up:e.map2(t,n,(e,t)=>t>0?e:Q),down:e.map2(t,n,(e,t)=>t<=0?e:Q)}}function Xi(e,t,n){let r=e.highest(t,n),i=e.lowest(t,n);return e.node((e,n,a)=>{let o=t.v,s=r.v,c=i.v,l=e.v;for(let e=n;e<a;e++){let t=s[e],n=c[e];t!==t||n!==n?l[e]=Q:l[e]=t>n?100*(o[e]-n)/(t-n):e>0?l[e-1]:Q}})}let Zi=D({id:`fisher`,name:`Fisher Transform`,family:`tv`,needs:`ohlc`,pane:`new`,inputs:[h(`length`,9,1,5e3)],columns:[`fisher`,`trigger`],plots:[x(`fisher`,b.blue),x(`trigger`,b.orange),T(`zero`,0,b.gray,`dotted`)],label:e=>`${e.length}`,build:(e,t)=>{let n=e.src(`hl2`),r=e.highest(n,t.length),i=e.lowest(n,t.length),a=e.node((e,t,a)=>{let o=n.v,s=r.v,c=i.v,l=e.v;for(let e=t;e<a;e++){let t=s[e],n=c[e];if(!(t>n)){l[e]=Q;continue}let r=e>0&&l[e-1]===l[e-1]?l[e-1]:0,i=.66*((o[e]-n)/(t-n)-.5)+.67*r;l[e]=i>.99?.999:i<-.99?-.999:i}}),o=e.node((e,t,n)=>{let r=a.v,i=e.v;for(let e=t;e<n;e++){let t=r[e];if(t!==t){i[e]=Q;continue}let n=e>0&&i[e-1]===i[e-1]?i[e-1]:0;i[e]=.5*Math.log((1+t)/(1-t))+.5*n}});return[o,e.lag(o,1)]},reference:`TradingView 'Fisher Transform' (Pine v5): value = round(0.66 ((hl2 - lowest) / (highest - lowest) - 0.5) + 0.67 nz(value[1])), fish = 0.5 ln((1 + value) / (1 - value)) + 0.5 nz(fish[1]); trigger = fish[1]`}),Qi=D({id:`kst`,name:`Know Sure Thing`,family:`tv`,needs:`value`,pane:`new`,inputs:[h(`roc1`,10,1,5e3),h(`roc2`,15,1,5e3),h(`roc3`,20,1,5e3),h(`roc4`,30,1,5e3),h(`sma1`,10,1,5e3),h(`sma2`,10,1,5e3),h(`sma3`,10,1,5e3),h(`sma4`,15,1,5e3),h(`signal`,9,1,5e3),y()],columns:[`kst`,`signal`],plots:[x(`kst`,b.green),x(`signal`,b.red),T(`zero`,0,b.gray,`dotted`)],label:e=>`${e.roc1} ${e.roc2} ${e.roc3} ${e.roc4} ${e.sma1} ${e.sma2} ${e.sma3} ${e.sma4} ${e.signal}`,build:(e,t)=>{let n=e.src(t.source),r=[1,2,3,4].map(r=>e.sma(Wi(e,n,t[`roc${r}`]),t[`sma${r}`])),i=e.calc(e=>r[0].v[e]+2*r[1].v[e]+3*r[2].v[e]+4*r[3].v[e]);return[i,e.sma(i,t.signal)]},reference:`TradingView 'Know Sure Thing': kst = sma(roc(c,10),10) + 2 sma(roc(c,15),10) + 3 sma(roc(c,20),10) + 4 sma(roc(c,30),15); signal = sma(kst, 9)`}),$i=D({id:`tsi`,name:`True Strength Index`,family:`tv`,needs:`value`,pane:`new`,inputs:[h(`long`,25,1,5e3),h(`short`,13,1,5e3),h(`signal`,13,1,5e3),y()],columns:[`tsi`,`signal`],plots:[x(`tsi`,b.blue),x(`signal`,b.red),T(`zero`,0,b.gray,`dotted`)],label:e=>`${e.long} ${e.short} ${e.signal}`,build:(e,t)=>{let n=e.change(e.src(t.source),1),r=Ki(e,n,t.long,t.short),i=Ki(e,e.abs(n),t.long,t.short),a=e.mul(e.div(r,i),100);return[a,e.ema(a,t.signal)]},reference:`TradingView 'True Strength Index' (Pine v5): 100 ema(ema(change(src), long), short) / ema(ema(abs(change(src)), long), short); signal = ema(tsi, 13)`}),ea=D({id:`vortex`,name:`Vortex Indicator`,family:`tv`,needs:`ohlc`,pane:`new`,inputs:[h(`length`,14,2,5e3)],columns:[`viPlus`,`viMinus`],plots:[x(`viPlus`,b.blue,{title:`VI+`}),x(`viMinus`,b.red,{title:`VI-`})],label:e=>`${e.length}`,build:(e,t)=>{let{high:n,low:r}=e,i=e.calc(e=>e>=1?Math.abs(n.v[e]-r.v[e-1]):Q),a=e.calc(e=>e>=1?Math.abs(r.v[e]-n.v[e-1]):Q),o=e.sum(Ji(e),t.length);return[e.div(e.sum(i,t.length),o),e.div(e.sum(a,t.length),o)]},reference:`TradingView 'Vortex Indicator' (Pine v5): VI+ = sum(|high - low[1]|, n) / sum(atr(1), n); VI- = sum(|low - high[1]|, n) / sum(atr(1), n)`}),ta=D({id:`coppock`,name:`Coppock Curve`,family:`tv`,needs:`value`,pane:`new`,inputs:[h(`length`,10,1,5e3,`WMA length`),h(`longRoc`,14,1,5e3,`Long ROC length`),h(`shortRoc`,11,1,5e3,`Short ROC length`),y()],columns:[`coppock`],plots:[x(`coppock`,b.blue),T(`zero`,0,b.gray,`dotted`)],label:e=>`${e.length} ${e.longRoc} ${e.shortRoc}`,build:(e,t)=>{let n=e.src(t.source);return[e.wma(e.add(Wi(e,n,t.longRoc),Wi(e,n,t.shortRoc)),t.length)]},reference:`TradingView 'Coppock Curve' (Pine v5): wma(roc(src, 14) + roc(src, 11), 10)`}),na=D({id:`connors-rsi`,name:`Connors RSI`,family:`tv`,needs:`value`,pane:`new`,inputs:[h(`rsiLength`,3,1,5e3),h(`updownLength`,2,1,5e3),h(`rocLength`,100,1,5e3),y()],columns:[`crsi`],plots:[x(`crsi`,b.blue),T(`upper`,70),T(`lower`,30),T(`middle`,50,b.gray,`dotted`)],label:e=>`${e.rsiLength} ${e.updownLength} ${e.rocLength}`,build:(e,t)=>{let n=e.src(t.source),r=Gi(e,n,t.rsiLength),i=Gi(e,e.node((e,t,r)=>{let i=n.v,a=e.v;for(let e=t;e<r;e++){if(e===0||i[e]!==i[e]||i[e-1]!==i[e-1]){a[e]=Q;continue}let t=a[e-1]===a[e-1]?a[e-1]:0,n=i[e],r=i[e-1];a[e]=n===r?0:n>r?t<=0?1:t+1:t>=0?-1:t-1}}),t.updownLength),a=Wi(e,n,1),o=e.validRun(a),s=e.node((e,n,r)=>{let i=a.v,s=o.v,c=e.v;for(let e=n;e<r;e++){if(s[e]<t.rocLength+1){c[e]=Q;continue}let n=0;for(let r=1;r<=t.rocLength;r++)i[e-r]<=i[e]&&n++;c[e]=100*n/t.rocLength}});return[e.calc(e=>(r.v[e]+i.v[e]+s.v[e])/3)]},reference:`TradingView 'Connors RSI' (Pine v5): avg(rsi(src, 3), rsi(updown streak, 2), percentrank(roc(src, 1), 100)); the first bar has no streak (absent)`}),ra=D({id:`choppiness`,name:`Choppiness Index`,family:`tv`,needs:`ohlc`,pane:`new`,inputs:[h(`length`,14,2,5e3)],columns:[`chop`],plots:[x(`chop`,b.blue),T(`upper`,61.8,b.gray,`dashed`),T(`lower`,38.2,b.gray,`dashed`)],label:e=>`${e.length}`,build:(e,t)=>{let n=e.sum(Ji(e),t.length),r=e.sub(e.highest(e.high,t.length),e.lowest(e.low,t.length)),i=e.div(n,r),a=100/Math.log10(t.length);return[e.map(i,e=>e>0?a*Math.log10(e):Q)]},reference:`TradingView 'Choppiness Index' (Pine v5): 100 log10(sum(atr(1), n) / (highest(high, n) - lowest(low, n))) / log10(n)`}),ia=D({id:`rvi-vigor`,name:`Relative Vigor Index`,family:`tv`,needs:`ohlc`,pane:`new`,inputs:[h(`length`,10,1,5e3)],columns:[`rvi`,`signal`],plots:[x(`rvi`,b.green),x(`signal`,b.red)],label:e=>`${e.length}`,build:(e,t)=>{let n=e.sma(qi(e,e.sub(e.close,e.open)),t.length),r=e.sma(qi(e,e.sub(e.high,e.low)),t.length),i=e.div(n,r);return[i,qi(e,i)]},reference:`TradingView 'Relative Vigor Index' (Pine v5): rvi = sma(swma(close - open), n) / sma(swma(high - low), n); signal = swma(rvi)`}),aa=D({id:`rvi-volatility`,name:`Relative Volatility Index`,family:`tv`,needs:`value`,pane:`new`,inputs:[h(`length`,10,2,5e3,`StdDev length`),h(`smoothing`,14,1,5e3),v(`ma`,`ema`,[`ema`,`rma`],`Smoothing`),y()],columns:[`rvi`],plots:[x(`rvi`,b.purple),T(`upper`,80),T(`lower`,20),T(`middle`,50,b.gray,`dotted`)],label:e=>`${e.length} ${e.smoothing}`,build:(e,t)=>{let n=e.src(t.source),r=e.stdev(n,t.length),i=e.change(n,1),a=e.map2(i,r,(e,t)=>e!==e||t!==t?Q:e<=0?0:t),o=e.map2(i,r,(e,t)=>e!==e||t!==t?Q:e>0?0:t),s=n=>t.ma===`rma`?e.rma(n,t.smoothing):e.ema(n,t.smoothing),c=s(a),l=s(o);return[e.mul(e.div(c,e.add(c,l)),100)]},reference:`TradingView 'Relative Volatility Index' (Pine v5): upper = ema(change(src) <= 0 ? 0 : stdev(src, 10), 14), lower = ema(change(src) > 0 ? 0 : stdev, 14), rvi = 100 upper / (upper + lower); ma 'rma' gives Dorsey's Wilder form`}),oa=D({id:`smi-ergodic`,name:`SMI Ergodic Indicator/Oscillator`,family:`tv`,needs:`value`,pane:`new`,inputs:[h(`longLength`,5,1,5e3),h(`shortLength`,20,1,5e3),h(`signal`,5,1,5e3),y()],columns:[`erg`,`signal`,`osc`],plots:[S(`osc`,b.gray,b.gray,{title:`Oscillator`}),x(`erg`,b.blue,{title:`SMI Ergodic`}),x(`signal`,b.red),T(`zero`,0,b.gray,`dotted`)],label:e=>`${e.longLength} ${e.shortLength} ${e.signal}`,build:(e,t)=>{let n=e.change(e.src(t.source),1),r=e.mul(e.div(Ki(e,n,t.longLength,t.shortLength),Ki(e,e.abs(n),t.longLength,t.shortLength)),100),i=e.ema(r,t.signal);return[r,i,e.sub(r,i)]},reference:`TradingView 'SMI Ergodic Indicator/Oscillator' (Pine v5): erg = 100 ema(ema(change, long 5), short 20) / ema(ema(abs(change), 5), 20); signal = ema(erg, 5); oscillator = erg - signal`}),sa=D({id:`rank-corr`,name:`Rank Correlation vs Time`,family:`tv`,needs:`value`,pane:`new`,inputs:[h(`length`,14,2,500),y()],columns:[`rho`],plots:[x(`rho`,b.teal),T(`zero`,0,b.gray,`dotted`)],label:e=>`${e.length}`,build:(e,t)=>{let n=e.src(t.source),r=e.validRun(n),i=t.length,a=(i+1)/2,o=i*(i*i-1)/12;return[e.node((e,t,s)=>{let c=n.v,l=r.v,u=e.v;for(let e=t;e<s;e++){if(l[e]<i){u[e]=Q;continue}let t=e-i+1,n=0,r=0;for(let e=0;e<i;e++){let o=c[t+e],s=0,l=0;for(let n=0;n<i;n++){let r=c[t+n];r<o?s++:r===o&&n!==e&&l++}let u=1+s+l/2;n+=(u-a)*(e+1-a),r+=(u-a)*(u-a)}let s=Math.sqrt(r*o);u[e]=s>0?Math.max(-1,Math.min(1,n/s)):Q}})]},reference:`Spearman's rho of the source against the bar index over a rolling window (not a TradingView built-in): Pearson correlation of the ranks, tied source values take the mean rank; a window of all equal values is absent`}),ca=D({id:`bull-bear-power`,name:`Bull Bear Power`,family:`tv`,needs:`ohlc`,pane:`new`,inputs:[h(`length`,13,1,5e3),y()],columns:[`bull`,`bear`],plots:[S(`bull`,b.green,b.green,{title:`Bull Power`}),S(`bear`,b.red,b.red,{title:`Bear Power`}),T(`zero`,0,b.gray,`dotted`)],label:e=>`${e.length}`,build:(e,t)=>{let n=e.ema(e.src(t.source),t.length);return[e.sub(e.high,n),e.sub(e.low,n)]},reference:`Elder Ray (TradingView 'Bull Bear Power'): bull = high - ema(close, 13), bear = low - ema(close, 13)`});function la(e,t,n){let r=e.src(`hl2`);return e.sub(e.sma(r,t),e.sma(r,n))}let ua=D({id:`awesome`,name:`Awesome Oscillator`,family:`tv`,needs:`ohlc`,pane:`new`,inputs:[h(`fast`,5,1,5e3),h(`slow`,34,2,5e3)],columns:[`ao`,`up`,`down`],plots:[S(`up`,b.green,void 0,{title:`AO rising`}),S(`down`,b.red,void 0,{title:`AO falling`})],label:()=>``,build:(e,t)=>{if(t.fast>=t.slow)throw RangeError(`awesome: fast (${t.fast}) must be below slow (${t.slow})`);let n=la(e,t.fast,t.slow),{up:r,down:i}=Yi(e,n);return[n,r,i]},reference:`TradingView 'Awesome Oscillator': sma(hl2, 5) - sma(hl2, 34); bar green when above the previous bar's value, red otherwise`}),da=D({id:`accelerator`,name:`Accelerator Oscillator`,family:`tv`,needs:`ohlc`,pane:`new`,inputs:[h(`fast`,5,1,5e3),h(`slow`,34,2,5e3),h(`signal`,5,1,5e3)],columns:[`ac`,`up`,`down`],plots:[S(`up`,b.green,void 0,{title:`AC rising`}),S(`down`,b.red,void 0,{title:`AC falling`})],label:()=>``,build:(e,t)=>{if(t.fast>=t.slow)throw RangeError(`accelerator: fast (${t.fast}) must be below slow (${t.slow})`);let n=la(e,t.fast,t.slow),r=e.sub(n,e.sma(n,t.signal)),{up:i,down:a}=Yi(e,r);return[r,i,a]},reference:`Bill Williams / TradingView 'Accelerator Oscillator': AO - sma(AO, 5); bar green when above the previous bar's value, red otherwise`}),fa=D({id:`mass-index`,name:`Mass Index`,family:`tv`,needs:`ohlc`,pane:`new`,inputs:[h(`length`,10,1,5e3,`Sum length`),h(`emaLength`,9,1,5e3)],columns:[`mi`],plots:[x(`mi`,b.blue)],label:e=>`${e.length}`,build:(e,t)=>{let n=e.ema(e.sub(e.high,e.low),t.emaLength),r=e.ema(n,t.emaLength);return[e.sum(e.div(n,r),t.length)]},reference:`TradingView 'Mass Index' (Pine v5): sum(ema(high - low, 9) / ema(ema(high - low, 9), 9), length), length 10 (Dorsey's 25 via the input)`}),pa=D({id:`dpo`,name:`Detrended Price Oscillator`,family:`tv`,needs:`value`,pane:`new`,inputs:[h(`length`,21,1,5e3),_(`centered`,!1),y()],columns:[`dpo`],plots:[x(`dpo`,b.teal),T(`zero`,0,b.gray,`dotted`)],label:e=>`${e.length}`,build:(e,t)=>{let n=e.src(t.source),r=Math.floor(t.length/2)+1,i=e.sma(n,t.length);return[t.centered?e.calc(e=>e>=r?n.v[e-r]-i.v[e]:Q):e.calc(e=>e>=r?n.v[e]-i.v[e-r]:Q)]},reference:`TradingView 'Detrended Price Oscillator' (Pine v5): barsback = floor(n/2) + 1; dpo = src - sma(src, n)[barsback]; centered: src[barsback] - sma(src, n), which TradingView draws shifted back by barsback bars (here the value stays on the bar that computes it)`}),ma=D({id:`schaff-tc`,name:`Schaff Trend Cycle`,family:`tv`,needs:`value`,pane:`new`,inputs:[h(`fast`,23,1,5e3),h(`slow`,50,2,5e3),h(`cycle`,10,2,5e3),h(`d1`,3,1,5e3),h(`d2`,3,1,5e3),y()],columns:[`stc`],plots:[x(`stc`,b.blue),T(`upper`,75),T(`lower`,25)],label:e=>`${e.fast} ${e.slow} ${e.cycle}`,build:(e,t)=>{let n=e.src(t.source),r=e.sub(e.ema(n,t.fast),e.ema(n,t.slow)),i=e.ema(Xi(e,r,t.cycle),t.d1),a=e.ema(Xi(e,i,t.cycle),t.d2);return[e.map(a,e=>e>100?100:e<0?0:e)]},reference:`TradingView 'Schaff Trend Cycle' (reproduced from the published script, not fetched): macd = ema(src,23) - ema(src,50); k = stoch(macd,10); d = ema(k,3); kd = stoch(d,10); stc = clamp(ema(kd,3), 0, 100); a flat range carries the last stoch (fixnan) and warm-up stays absent instead of nz-ed to 0`}),ha=D({id:`stoch-tv`,name:`Stochastic`,family:`tv`,needs:`ohlc`,pane:`new`,inputs:[h(`kLength`,14,1,5e3,`%K length`),h(`kSmooth`,1,1,5e3,`%K smoothing`),h(`dLength`,3,1,5e3,`%D smoothing`)],columns:[`k`,`d`],plots:[x(`k`,b.blue,{title:`%K`}),x(`d`,b.orange,{title:`%D`}),T(`upper`,80),T(`lower`,20),T(`middle`,50,b.gray,`dotted`)],label:e=>`${e.kLength} ${e.kSmooth} ${e.dLength}`,build:(e,t)=>{let n=e.highest(e.high,t.kLength),r=e.lowest(e.low,t.kLength),i=e.mul(e.div(e.sub(e.close,r),e.sub(n,r)),100),a=e.sma(i,t.kSmooth);return[a,e.sma(a,t.dLength)]},reference:`TradingView 'Stochastic' (Pine v5): k = sma(stoch(close, high, low, 14), 1), d = sma(k, 3); TA-Lib STOCH with fastk 14 / slowk sma 1 / slowd sma 3 (TA-Lib gives 0 on a flat range, here it is absent)`});var ga=/* @__PURE__ */ t({adr:()=>La,anchoredVwap:()=>ja,chaikinMf:()=>Oa,elderForce:()=>Ea,eom:()=>Da,histVol:()=>Ia,klinger:()=>ka,netVolume:()=>Ta,pivotPoints:()=>Fa,pvt:()=>wa,volume:()=>Sa,volumeOsc:()=>Ca,vwap:()=>Aa});let $=NaN;function _a(e){let t=e+719468,n=Math.floor(t/146097),r=t-n*146097,i=Math.floor((r-Math.floor(r/1460)+Math.floor(r/36524)-Math.floor(r/146096))/365),a=r-(365*i+Math.floor(i/4)-Math.floor(i/100)),o=Math.floor((5*a+2)/153),s=o<10?o+3:o-9;return[i+n*400+ +(s<=2),s-1]}function va(e,t,n){let r=e.time,i=n*6e4;return e.calc(e=>{let n=Math.floor((r.v[e]+i)/864e5);switch(t){case`day`:return n;case`week`:return Math.floor((n+3)/7);case`month`:{let[e,t]=_a(n);return e*12+t}case`year`:return _a(n)[0]}})}function ya(e,t,n,r=()=>!0){return e.node((e,i,a)=>{let o=e.v;for(let e=i;e<a;e++)r(e)?o[e]=(n(e)?0:o[e-1])+t(e):o[e]=$})}function ba(e,t,n,r,i){let a=e.calc(e=>n.v[e]>0?t.v[e]/n.v[e]:$),o=e.calc(e=>{let t=a.v[e],i=r.v[e]/n.v[e]-t*t;return t===t?i>0?Math.sqrt(i):0:$});return[a,e.calc(e=>a.v[e]+i*o.v[e]),e.calc(e=>a.v[e]-i*o.v[e])]}let xa=h(`utcOffsetMinutes`,0,-720,840,`UTC offset (minutes)`),Sa=D({id:`volume`,name:`Volume`,family:`tv`,needs:`ohlcv`,pane:`new`,inputs:[h(`maLength`,20,1,5e3,`MA length`)],columns:[`volume`,`up`,`down`,`ma`],plots:[S(`up`,b.green,void 0,{title:`Volume (up)`}),S(`down`,b.red,void 0,{title:`Volume (down)`}),x(`ma`,b.yellow,{title:`Volume MA`})],label:e=>`${e.maLength}`,build:(e,t)=>{let{volume:n,open:r,close:i}=e,a=e.calc(e=>i.v[e]>r.v[e]?n.v[e]:$),o=e.calc(e=>i.v[e]>r.v[e]?$:n.v[e]);return[e.calc(e=>n.v[e]),a,o,e.sma(n,t.maLength)]},reference:`TradingView Volume: histogram of volume, green when close > open, red otherwise; MA is ta.sma(volume, 20). Verified against TA-Lib SMA for the MA.`}),Ca=D({id:`volume-osc`,name:`Volume Oscillator`,family:`tv`,needs:`ohlcv`,pane:`new`,inputs:[h(`short`,5,1,5e3,`Short length`),h(`long`,10,1,5e3,`Long length`)],columns:[`osc`],plots:[x(`osc`,b.blue,{title:`Volume Oscillator`})],label:e=>`${e.short}, ${e.long}`,build:(e,t)=>{let n=e.ema(e.volume,t.short),r=e.ema(e.volume,t.long);return[e.map2(n,r,(e,t)=>t===0?$:100*(e-t)/t)]},reference:`TradingView Volume Oscillator: 100 * (ta.ema(volume, 5) - ta.ema(volume, 10)) / ta.ema(volume, 10). Equals TA-Lib PPO(volume, 5, 10, EMA).`}),wa=D({id:`pvt`,name:`Price Volume Trend`,family:`tv`,needs:`ohlcv`,pane:`new`,inputs:[],columns:[`pvt`],plots:[x(`pvt`,b.blue,{title:`PVT`})],build:e=>{let{close:t,volume:n}=e,r=e.calc(e=>e===0?$:(t.v[e]-t.v[e-1])/t.v[e-1]*n.v[e]);return[ya(e,e=>r.v[e],e=>e<=1,e=>e>=1)]},reference:`Pine ta.pvt = ta.cum(ta.change(close) / close[1] * volume)`}),Ta=D({id:`net-volume`,name:`Net Volume`,family:`tv`,needs:`ohlcv`,pane:`new`,inputs:[],columns:[`netVolume`],plots:[S(`netVolume`,b.green,b.red,{title:`Net Volume`})],build:e=>{let{close:t,volume:n}=e;return[e.calc(e=>{if(e===0)return $;let r=t.v[e]-t.v[e-1];return r>0?n.v[e]:r<0?-n.v[e]:0})]},reference:`TradingView Net Volume: volume signed by the sign of ta.change(close) (zero on an unchanged close)`}),Ea=D({id:`elder-force`,name:`Elder's Force Index`,family:`tv`,needs:`ohlcv`,pane:`new`,inputs:[h(`length`,13,1,5e3)],columns:[`efi`],plots:[x(`efi`,b.red,{title:`EFI`})],label:e=>`${e.length}`,build:(e,t)=>{let{close:n,volume:r}=e,i=e.calc(e=>e===0?$:(n.v[e]-n.v[e-1])*r.v[e]);return[e.ema(i,t.length)]},reference:`TradingView Elder's Force Index: ta.ema(ta.change(close) * volume, 13)`}),Da=D({id:`eom`,name:`Ease of Movement`,family:`tv`,needs:`ohlcv`,pane:`new`,inputs:[h(`length`,14,1,5e3),h(`divisor`,1e4,1,1e9)],columns:[`eom`],plots:[x(`eom`,b.teal,{title:`EOM`})],label:e=>`${e.length}`,build:(e,t)=>{let{high:n,low:r,volume:i}=e,a=e.src(`hl2`),o=e.calc(e=>e===0?$:t.divisor*(a.v[e]-a.v[e-1])*(n.v[e]-r.v[e]));return[e.sma(e.div(o,i),t.length)]},reference:`TradingView Ease of Movement: ta.sma(10000 * ta.change(hl2) * (high - low) / volume, 14); zero volume is absent`}),Oa=D({id:`chaikin-mf`,name:`Chaikin Money Flow`,family:`tv`,needs:`ohlcv`,pane:`new`,inputs:[h(`length`,20,1,5e3)],columns:[`cmf`],plots:[x(`cmf`,b.green,{title:`CMF`})],label:e=>`${e.length}`,build:(e,t)=>{let{high:n,low:r,close:i,volume:a}=e,o=e.calc(e=>{let t=n.v[e],o=r.v[e],s=i.v[e];return t===o?0:(2*s-o-t)/(t-o)*a.v[e]});return[e.div(e.sum(o,t.length),e.sum(a,t.length))]},reference:`TradingView Chaikin Money Flow: sum(ad, 20) / sum(volume, 20), ad = (2*close - low - high) / (high - low) * volume (0 when high == low)`}),ka=D({id:`klinger`,name:`Klinger Oscillator`,family:`tv`,needs:`ohlcv`,pane:`new`,inputs:[h(`fast`,34,1,5e3),h(`slow`,55,1,5e3),h(`signal`,13,1,5e3)],columns:[`kvo`,`signal`],plots:[x(`kvo`,b.blue,{title:`KVO`}),x(`signal`,b.green,{title:`Signal`})],label:e=>`${e.fast}, ${e.slow}, ${e.signal}`,build:(e,t)=>{let n=e.src(`hlc3`),r=e.volume,i=e.calc(e=>e===0?$:n.v[e]-n.v[e-1]>=0?r.v[e]:-r.v[e]),a=e.sub(e.ema(i,t.fast),e.ema(i,t.slow));return[a,e.ema(a,t.signal)]},reference:`TradingView Klinger Oscillator: sv = ta.change(hlc3) >= 0 ? volume : -volume; kvo = ta.ema(sv, 34) - ta.ema(sv, 55); signal = ta.ema(kvo, 13)`}),Aa=D({id:`vwap`,name:`VWAP`,family:`tv`,needs:`ohlcv`,pane:`overlay`,inputs:[v(`anchor`,`session`,[`session`,`week`,`month`,`year`]),y(`hlc3`),g(`bandMult`,1,0,100,.1,`Band multiplier`),xa],columns:[`vwap`,`upper`,`lower`],plots:[x(`vwap`,b.blue,{title:`VWAP`}),C(`bands`,`upper`,`lower`,b.green,`rgba(8,153,129,0.1)`,`VWAP bands`)],label:e=>`${e.anchor}`,build:(e,t)=>{let n=va(e,t.anchor===`session`?`day`:t.anchor,t.utcOffsetMinutes),r=e.src(t.source),i=e.volume,a=e=>e===0||n.v[e]!==n.v[e-1],o=ya(e,e=>i.v[e],a);return ba(e,ya(e,e=>r.v[e]*i.v[e],a),o,ya(e,e=>r.v[e]*r.v[e]*i.v[e],a),t.bandMult)},reference:`Pine ta.vwap(hlc3, anchor, stdev_mult 1): cumulative sum(src*volume) / sum(volume) restarting at each session/week/month/year; bands = vwap +/- mult * sqrt(sum(volume*src^2)/sum(volume) - vwap^2). Session = calendar day in the exchange time zone.`}),ja=D({id:`anchored-vwap`,name:`Anchored VWAP`,family:`tv`,needs:`ohlcv`,pane:`overlay`,inputs:[g(`anchorTime`,0,0,0x38d7ea4c68000,1,`Anchor time (UTC ms)`),y(`hlc3`),g(`bandMult`,1,0,100,.1,`Band multiplier`)],columns:[`vwap`,`upper`,`lower`],plots:[x(`vwap`,b.orange,{title:`Anchored VWAP`}),C(`bands`,`upper`,`lower`,b.orange,`rgba(255,109,0,0.1)`,`Anchored VWAP bands`)],build:(e,t)=>{let n=e.time,r=e.src(t.source),i=e.volume,a=e=>n.v[e]>=t.anchorTime,o=e=>e===0||!a(e-1),s=ya(e,e=>i.v[e],o,a);return ba(e,ya(e,e=>r.v[e]*i.v[e],o,a),s,ya(e,e=>r.v[e]*r.v[e]*i.v[e],o,a),t.bandMult)},reference:`TradingView Anchored VWAP: VWAP (hlc3) accumulated from the first bar at or after the anchor time, with stdev bands; earlier bars are absent`}),Ma=[`p`,`r1`,`r2`,`r3`,`r4`,`s1`,`s2`,`s3`,`s4`];function Na(e,t,n,r,i){let a={p:$,r1:$,r2:$,r3:$,r4:$,s1:$,s2:$,s3:$,s4:$},o=n-r;if(e===`dm`){let e=i<t?n+2*r+i:i>t?2*n+r+i:n+r+2*i;return a.p=e/4,a.r1=e/2-r,a.s1=e/2-n,a}if(e===`woodie`){let e=(n+r+2*i)/4;return a.p=e,a.r1=2*e-r,a.s1=2*e-n,a.r2=e+o,a.s2=e-o,a.r3=n+2*o,a.s3=r-2*o,a.r4=a.r3+o,a.s4=a.s3-o,a}if(e===`camarilla`)return a.p=(n+r+i)/3,a.r1=i+o*1.1/12,a.r2=i+o*1.1/6,a.r3=i+o*1.1/4,a.r4=i+o*1.1/2,a.s1=i-o*1.1/12,a.s2=i-o*1.1/6,a.s3=i-o*1.1/4,a.s4=i-o*1.1/2,a;let s=(n+r+i)/3;return a.p=s,e===`fibonacci`?(a.r1=s+.382*o,a.r2=s+.618*o,a.r3=s+o,a.s1=s-.382*o,a.s2=s-.618*o,a.s3=s-o):e===`classic`?(a.r1=2*s-r,a.s1=2*s-n,a.r2=s+o,a.s2=s-o,a.r3=s+2*o,a.s3=s-2*o,a.r4=s+3*o,a.s4=s-3*o):(a.r1=2*s-r,a.s1=2*s-n,a.r2=s+o,a.s2=s-o,a.r3=2*s+n-2*r,a.s3=2*s-(2*n-r),a.r4=3*s+n-3*r,a.s4=3*s-(3*n-r)),a}let Pa={p:b.gray,r1:b.red,r2:b.red,r3:b.red,r4:b.red,s1:b.green,s2:b.green,s3:b.green,s4:b.green},Fa=D({id:`pivot-points`,name:`Pivot Points Standard`,family:`tv`,needs:`ohlc`,pane:`overlay`,inputs:[v(`kind`,`standard`,[`standard`,`fibonacci`,`woodie`,`classic`,`dm`,`camarilla`]),v(`period`,`day`,[`day`,`week`,`month`,`year`]),xa],columns:[...Ma],plots:Ma.map(e=>x(e,Pa[e],{title:e.toUpperCase(),width:1})),label:e=>`${e.kind} ${e.period}`,build:(e,t)=>{let n=va(e,t.period,t.utcOffsetMinutes),{open:r,high:i,low:a,close:o}=e,s=e.col(),c=e.col(),l=e.col(),u=e.col(),d=e.col(),f=e.col(),p=e.col(),m=e.col();return e.node((e,t,h)=>{for(let e=t;e<h;e++)e===0||n.v[e]!==n.v[e-1]?(e===0?(d.v[e]=$,f.v[e]=$,p.v[e]=$,m.v[e]=$):(d.v[e]=s.v[e-1],f.v[e]=c.v[e-1],p.v[e]=l.v[e-1],m.v[e]=u.v[e-1]),s.v[e]=r.v[e],c.v[e]=i.v[e],l.v[e]=a.v[e]):(d.v[e]=d.v[e-1],f.v[e]=f.v[e-1],p.v[e]=p.v[e-1],m.v[e]=m.v[e-1],s.v[e]=s.v[e-1],c.v[e]=Math.max(c.v[e-1],i.v[e]),l.v[e]=Math.min(l.v[e-1],a.v[e])),u.v[e]=o.v[e]}),Ma.map(n=>e.calc(e=>f.v[e]===f.v[e]?Na(t.kind,d.v[e],f.v[e],p.v[e],m.v[e])[n]:$))},reference:`TradingView Pivot Points Standard (Traditional, Fibonacci, Woodie, Classic, DM, Camarilla) from the previous completed period's open/high/low/close; constant over the current period, absent in the first`}),Ia=D({id:`hist-vol`,name:`Historical Volatility`,family:`tv`,needs:`value`,pane:`new`,inputs:[h(`length`,10,2,5e3),h(`annual`,252,1,1e4,`Periods per year`),h(`periodDays`,1,1,1e4,`Days per bar`)],columns:[`hv`],plots:[x(`hv`,b.blue,{title:`HV`})],label:e=>`${e.length}`,build:(e,t)=>{let n=e.close,r=e.calc(e=>e===0?$:Math.log(n.v[e]/n.v[e-1])),i=100*Math.sqrt(t.annual/t.periodDays);return[e.map(e.stdev(r,t.length),e=>e*i)]},reference:`TradingView Historical Volatility: 100 * ta.stdev(ln(close/close[1]), 10) * sqrt(annual / periodDays); ta.stdev is the population deviation (biased). annual defaults to 252 trading days (TradingView's script uses 365).`}),La=D({id:`adr`,name:`Average Day Range`,family:`tv`,needs:`ohlc`,pane:`new`,inputs:[h(`length`,14,1,5e3)],columns:[`adr`],plots:[x(`adr`,b.orange,{title:`ADR`})],label:e=>`${e.length}`,build:(e,t)=>[e.sma(e.sub(e.high,e.low),t.length)],reference:`TradingView Average Day Range: ta.sma(high - low, 14) on the chart's bars`}),Ra=e=>typeof e==`object`&&!!e&&`build`in e&&`columns`in e&&`plots`in e,za=[ue,Te,mt,yt,Ct,kt,Wt,xn,Bn,Gn,pi,Ui,ga].flatMap(e=>Object.values(e).filter(Ra)),Ba=new Map(za.map(e=>[e.id,e])),Va=self,Ha=m((e,t)=>Va.postMessage(e,t),e=>Ba.get(e));Va.onmessage=e=>Ha(e.data)})();
|
|
2
|
+
//# sourceMappingURL=worker-BrUuzTIJ.js.map
|