lightweight-charts-indicators 0.19.0 → 0.19.2

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.
Files changed (32) hide show
  1. package/dist/community/abc-on-recursive-zigzag.d.ts.map +1 -1
  2. package/dist/community/auto-fib-channels-by-dgt.d.ts.map +1 -1
  3. package/dist/community/auto-fib-speed-resistance-fans-by-dgt.d.ts.map +1 -1
  4. package/dist/community/bollinger-heatmap.d.ts.map +1 -1
  5. package/dist/community/fair-value-bands-flowly-indicators.d.ts.map +1 -1
  6. package/dist/community/gann-box.d.ts.map +1 -1
  7. package/dist/community/harmonic-pattern-detection-prediction-and.d.ts.map +1 -1
  8. package/dist/community/ichimoku-kink-hy.d.ts.map +1 -1
  9. package/dist/community/institutional-orderblock-pressure.d.ts.map +1 -1
  10. package/dist/community/lorentzian-classification.d.ts.map +1 -1
  11. package/dist/community/machine-learning-rsi-ai-classification-ranking.d.ts.map +1 -1
  12. package/dist/community/machine-learning-rsi-bullvision.d.ts.map +1 -1
  13. package/dist/community/next-pivot-projection.d.ts.map +1 -1
  14. package/dist/community/order-blocks-w-realtime-fibs.d.ts.map +1 -1
  15. package/dist/community/previous-day-high-and-low-separators-daily.d.ts.map +1 -1
  16. package/dist/community/prometheus-topological-persistent-entropy.d.ts.map +1 -1
  17. package/dist/community/r-r-trading-system-framework.d.ts.map +1 -1
  18. package/dist/community/support-resistance-pro-toolkit.d.ts.map +1 -1
  19. package/dist/community/three-drive-pattern-detector.d.ts.map +1 -1
  20. package/dist/community/wavelet-filter-with-adaptive-upsampling.d.ts.map +1 -1
  21. package/dist/community/wolfe-scanner.d.ts.map +1 -1
  22. package/dist/index.cjs +499 -348
  23. package/dist/index.d.ts +1 -1
  24. package/dist/index.mjs +1907 -1759
  25. package/dist/render/primitives.d.ts +12 -0
  26. package/dist/render/primitives.d.ts.map +1 -1
  27. package/dist/render/renderer.d.ts +6 -1
  28. package/dist/render/renderer.d.ts.map +1 -1
  29. package/dist/render.mjs +60 -10
  30. package/dist/sources.mjs +1 -1
  31. package/dist/standard/auto-fib-retracement.d.ts.map +1 -1
  32. package/package.json +1 -1
package/dist/index.cjs CHANGED
@@ -55365,6 +55365,17 @@ function calculate411(bars, inputs = {}, chart) {
55365
55365
  const levelLabels = /* @__PURE__ */ new Map();
55366
55366
  const alertCalls = [];
55367
55367
  const ticker = tickerOf(chart);
55368
+ const levelTexts = /* @__PURE__ */ new Map();
55369
+ const levelText = (k, m, r) => {
55370
+ const last = levelTexts.get(k);
55371
+ if (last && Object.is(last.r, r))
55372
+ return last.text;
55373
+ const lv = cfg.levelsFormat === "Values" ? import_oakscriptjs382.str.tostring(m) : import_oakscriptjs382.str.tostring(m * 100) + "%";
55374
+ const txt = (cfg.levels ? lv : "") + (cfg.prices ? "(" + fmt3(r) + ")" : "");
55375
+ const text = (left ? txt : " " + txt) + LABEL_PAD2;
55376
+ levelTexts.set(k, { r, text });
55377
+ return text;
55378
+ };
55368
55379
  for (let i = 0; i < n; i++) {
55369
55380
  (0, import_oakscriptjs382.setDrawingBar)(i, i === n - 1);
55370
55381
  if (i === n - 1 && zigZag.pivots.length < 2) {
@@ -55427,9 +55438,7 @@ function calculate411(bars, inputs = {}, chart) {
55427
55438
  }
55428
55439
  import_oakscriptjs382.line.set_xy1(id, timeMs(s.time), r);
55429
55440
  import_oakscriptjs382.line.set_xy2(id, timeMs(e.time), r);
55430
- const lv = cfg.levelsFormat === "Values" ? import_oakscriptjs382.str.tostring(m) : import_oakscriptjs382.str.tostring(m * 100) + "%";
55431
- const txt = (cfg.levels ? lv : "") + (cfg.prices ? "(" + fmt3(r) + ")" : "");
55432
- const text = (left ? txt : " " + txt) + LABEL_PAD2;
55441
+ const text = levelText(k, m, r);
55433
55442
  const x = timeMs(left ? s.time : !cfg.extendRight ? e.time : bars[i].time);
55434
55443
  let lb = levelLabels.get(k);
55435
55444
  if (!lb) {
@@ -125249,23 +125258,37 @@ function calculate874(bars, inputs = {}, chart) {
125249
125258
  const close11 = bars.map((b) => b.close);
125250
125259
  const hist3 = (b, k) => b - k >= 0 ? close11[b - k] : NaN;
125251
125260
  const { windowSize, bins, lgrLkb } = cfg;
125261
+ const pairEntropy = (logReturns, i) => {
125262
+ const segment1 = [];
125263
+ const segment2 = [];
125264
+ pineFor3(0, windowSize - 1, (j) => {
125265
+ segment1.push(get(logReturns, i + j));
125266
+ segment2.push(get(logReturns, i + windowSize + j));
125267
+ });
125268
+ const combined = persistenceDiagram(segment1).concat(persistenceDiagram(segment2));
125269
+ return entropyOf(combined, bins);
125270
+ };
125271
+ const n = lgrLkb - 2 * windowSize + 1;
125272
+ const forward = windowSize >= 1 && n >= 1;
125273
+ const pairEntropies = /* @__PURE__ */ new Map();
125252
125274
  const smoothPe = new Array(nBars);
125253
125275
  for (let b = 0; b < nBars; b++) {
125254
125276
  const logReturns = [];
125255
125277
  pineFor3(1, lgrLkb, (i) => {
125256
125278
  logReturns.push(Math.log(hist3(b, i) / hist3(b, i + 1)));
125257
125279
  });
125258
- const n = lgrLkb - 2 * windowSize + 1;
125259
125280
  const entropies = [];
125260
125281
  pineFor3(0, n - 1, (i) => {
125261
- const segment1 = [];
125262
- const segment2 = [];
125263
- pineFor3(0, windowSize - 1, (j) => {
125264
- segment1.push(get(logReturns, i + j));
125265
- segment2.push(get(logReturns, i + windowSize + j));
125266
- });
125267
- const combined = persistenceDiagram(segment1).concat(persistenceDiagram(segment2));
125268
- entropies.push(entropyOf(combined, bins));
125282
+ if (!forward) {
125283
+ entropies.push(pairEntropy(logReturns, i));
125284
+ return;
125285
+ }
125286
+ let entropy = pairEntropies.get(b - i);
125287
+ if (entropy === void 0) {
125288
+ entropy = pairEntropy(logReturns, i);
125289
+ pairEntropies.set(b - i, entropy);
125290
+ }
125291
+ entropies.push(entropy);
125269
125292
  });
125270
125293
  let sum2 = 0;
125271
125294
  for (const e of entropies)
@@ -131281,14 +131304,14 @@ function calculate921(bars, inputs = {}) {
131281
131304
  plot1: bars.map((b) => ({ time: b.time, value: 45, color: "#00000000" }))
131282
131305
  };
131283
131306
  const closeArr = bars.map((b) => b.close);
131284
- const avgSite = import_oakscriptjs890.callsite.sma();
131285
- const devSite2 = import_oakscriptjs890.callsite.stdev();
131307
+ const lengths3 = Array.from({ length: TOTAL_BARS }, (_x, k) => cfg[lengthKey(k)]);
131308
+ const basisOf = lengths3.map((length) => import_oakscriptjs890.taCore.sma(closeArr, length));
131309
+ const devOf = lengths3.map((length) => import_oakscriptjs890.taCore.stdev(closeArr, length));
131286
131310
  const pts = Array.from({ length: TOTAL_BARS }, () => new Array(n));
131287
131311
  for (let i = 0; i < n; i++) {
131288
131312
  for (let k = 0; k < TOTAL_BARS; k++) {
131289
- const length = cfg[lengthKey(k)];
131290
- const basis = avgSite(i, closeArr[i], length);
131291
- const dev = devSite2(i, closeArr[i], length);
131313
+ const basis = basisOf[k][i];
131314
+ const dev = devOf[k][i];
131292
131315
  const u = basis + cfg.bbStd * dev;
131293
131316
  const l = basis - cfg.bbStd * dev;
131294
131317
  const bandRange = u - l;
@@ -141536,39 +141559,26 @@ var C = 1 / Math.sqrt(2);
141536
141559
  var highPass2 = (a, b) => (a - b) * C;
141537
141560
  var lowPass = (a, b) => (a + b) * C;
141538
141561
  var softThreshold = (coeff, threshold) => gt492(coeff, threshold) ? coeff - threshold : lt374(coeff, -threshold) ? coeff + threshold : 0;
141539
- function downsample(arr5) {
141540
- const out = import_oakscriptjs964.array.new_float(Math.ceil(arr5.length / 2), NaN);
141541
- pineFor4(0, arr5.length - 1, 2, (i) => aset(out, i / 2, aget(arr5, i)));
141542
- return out;
141543
- }
141544
- function upsample(arr5) {
141562
+ var upsampledSize = (size2) => size2 <= 1 ? size2 : size2 * 2 - 1;
141563
+ function upsampleAt(arr5, k) {
141545
141564
  if (arr5.length <= 1)
141546
- return arr5;
141547
- const size2 = arr5.length * 2 - 1;
141548
- const out = import_oakscriptjs964.array.new_float(size2, NaN);
141549
- pineFor4(0, arr5.length - 2, 1, (i) => {
141550
- const a = aget(arr5, i);
141551
- const b = aget(arr5, i + 1);
141552
- aset(out, i * 2, a);
141553
- aset(out, i * 2 + 1, (a + b) / 2);
141554
- });
141555
- aset(out, size2 - 1, aget(arr5, arr5.length - 1));
141556
- return out;
141557
- }
141558
- function sinusoidalUpsample(arr5, freq, phase) {
141565
+ return aget(arr5, k);
141566
+ if (k % 2 === 0)
141567
+ return aget(arr5, k / 2);
141568
+ const a = aget(arr5, (k - 1) / 2);
141569
+ const b = aget(arr5, (k + 1) / 2);
141570
+ return (a + b) / 2;
141571
+ }
141572
+ function sinusoidalUpsampleAt(arr5, k, freq, phase) {
141559
141573
  if (arr5.length <= 1)
141560
- return arr5;
141561
- const out = [];
141562
- pineFor4(0, arr5.length - 2, 1, (i) => {
141563
- const a = aget(arr5, i);
141564
- const b = aget(arr5, i + 1);
141565
- const amplitude = (b - a) / 2;
141566
- const midPoint = (a + b) / 2;
141567
- out.push(a);
141568
- out.push(amplitude * Math.sin(Math.PI * freq + phase) + midPoint);
141569
- });
141570
- out.push(aget(arr5, arr5.length - 1));
141571
- return out;
141574
+ return aget(arr5, k);
141575
+ if (k % 2 === 0)
141576
+ return aget(arr5, k / 2);
141577
+ const a = aget(arr5, (k - 1) / 2);
141578
+ const b = aget(arr5, (k + 1) / 2);
141579
+ const amplitude = (b - a) / 2;
141580
+ const midPoint = (a + b) / 2;
141581
+ return amplitude * Math.sin(Math.PI * freq + phase) + midPoint;
141572
141582
  }
141573
141583
  var MAX_WHILE = 1e6;
141574
141584
  function advancedUpsample(srcarr, npast, frqtol, upsampleFactor, barIndex) {
@@ -141649,61 +141659,52 @@ function calculate996(bars, inputs = {}) {
141649
141659
  const src = (0, import_oakscriptjs964.getSourceSeries)(bars, cfg.src).toArray().map((v) => v ?? NaN);
141650
141660
  const npast = cfg.npast;
141651
141661
  const logRoc = src.map((v, i) => i > 0 ? Math.log(v / src[i - 1]) : NaN);
141662
+ const high1 = logRoc.map((x, t) => highPass2(x, t > 0 ? logRoc[t - 1] : NaN));
141663
+ const low1 = logRoc.map((x, t) => lowPass(x, t > 0 ? logRoc[t - 1] : NaN));
141664
+ const high22 = low1.map((x, t) => highPass2(x, t > 1 ? low1[t - 2] : NaN));
141665
+ const low22 = low1.map((x, t) => lowPass(x, t > 1 ? low1[t - 2] : NaN));
141652
141666
  const recon = new Array(nBars).fill(NaN);
141653
141667
  const cum = new Array(nBars).fill(NaN);
141654
141668
  let reconstructed = NaN;
141655
141669
  let series = 1;
141656
141670
  for (let bi = 0; bi < nBars; bi++) {
141657
141671
  if (bi > 0 && bi > npast) {
141658
- const highFreqValues = [];
141659
- const lowFreqValues = [];
141660
- const highFreqValues2 = [];
141661
- const lowFreqValues2 = [];
141662
- pineFor4(0, Math.min(bi, 5e3) - 1, 1, (i) => {
141663
- const x = bi - i >= 0 ? logRoc[bi - i] : NaN;
141664
- const y = bi - i - 1 >= 0 ? logRoc[bi - i - 1] : NaN;
141665
- highFreqValues.push(highPass2(x, y));
141666
- lowFreqValues.push(lowPass(x, y));
141667
- });
141668
- const downsampledLow = downsample(lowFreqValues);
141669
- const downsampledHigh = downsample(highFreqValues);
141672
+ const size2 = Math.min(bi, 5e3);
141673
+ const downsampledHigh = [];
141674
+ for (let i = 0; i < size2; i += 2)
141675
+ downsampledHigh.push(high1[bi - i]);
141676
+ const downsampledLowSize = downsampledHigh.length;
141670
141677
  const noiseEstimate = import_oakscriptjs964.array.stdev(downsampledHigh);
141671
141678
  const n = downsampledHigh.length;
141672
141679
  const adaptiveThreshold = noiseEstimate * Math.sqrt(2 * Math.log(n));
141673
- pineFor4(0, n - 1, 1, (i) => aset(downsampledHigh, i, softThreshold(aget(downsampledHigh, i), adaptiveThreshold)));
141674
- pineFor4(0, downsampledLow.length - 2, 1, (i) => {
141675
- const frst = aget(downsampledLow, i);
141676
- const scnd = aget(downsampledLow, i + 1);
141677
- highFreqValues2.push(highPass2(frst, scnd));
141678
- lowFreqValues2.push(lowPass(frst, scnd));
141679
- });
141680
- const secondDownsampledLow = downsample(lowFreqValues2);
141681
- const secondDownsampledHigh = downsample(highFreqValues2);
141680
+ if (downsampledLowSize < 2) {
141681
+ throw new Error(`In 'array.get()' function. Index 1 is out of bounds, array size is ${downsampledLowSize}.`);
141682
+ }
141683
+ const secondDownsampledHigh = [];
141684
+ const secondDownsampledLow = [];
141685
+ for (let i = 0; i < downsampledLowSize - 1; i += 2) {
141686
+ secondDownsampledHigh.push(high22[bi - 2 * i]);
141687
+ secondDownsampledLow.push(low22[bi - 2 * i]);
141688
+ }
141682
141689
  const secondNoiseEstimate = import_oakscriptjs964.array.stdev(secondDownsampledHigh);
141683
141690
  const secondN = secondDownsampledHigh.length;
141684
141691
  const secondAdaptiveThreshold = secondNoiseEstimate * Math.sqrt(2 * Math.log(secondN));
141685
- pineFor4(0, secondN - 1, 1, (i) => aset(secondDownsampledHigh, i, softThreshold(aget(secondDownsampledHigh, i), secondAdaptiveThreshold)));
141686
- if (secondDownsampledLow.length > 0) {
141687
- const firstReconSize = Math.min(secondDownsampledHigh.length, secondDownsampledLow.length);
141688
- const firstReconstruct = import_oakscriptjs964.array.new_float(firstReconSize, NaN);
141689
- pineFor4(0, firstReconSize - 1, 1, (j) => {
141690
- const hiVal = aget(secondDownsampledHigh, j);
141691
- const loVal = aget(secondDownsampledLow, j);
141692
- if (!isNa3(hiVal) && !isNa3(loVal))
141693
- aset(firstReconstruct, j, hiVal + loVal);
141694
- });
141695
- const upSampledApprox = cfg.upsampleType === "Sinusoidal Upsample" ? sinusoidalUpsample(firstReconstruct, cfg.freq, cfg.phase) : cfg.upsampleType === "Advanced Upsample" ? advancedUpsample(firstReconstruct, npast, cfg.freq, cfg.upp, bi) : upsample(firstReconstruct);
141696
- if (upSampledApprox.length > 0) {
141697
- const finalReconSize = Math.min(upSampledApprox.length, downsampledHigh.length);
141698
- const finalRecon = import_oakscriptjs964.array.new_float(finalReconSize, NaN);
141699
- pineFor4(0, finalReconSize - 1, 1, (k) => {
141700
- const approxVal = aget(upSampledApprox, k);
141701
- const detailVal = aget(downsampledHigh, k);
141702
- if (!isNa3(approxVal) && !isNa3(detailVal))
141703
- aset(finalRecon, k, approxVal + detailVal);
141704
- });
141705
- reconstructed = finalRecon.length > 0 ? aget(finalRecon, bi % finalRecon.length) : NaN;
141706
- }
141692
+ const firstReconSize = Math.min(secondDownsampledHigh.length, secondDownsampledLow.length);
141693
+ const firstReconstruct = import_oakscriptjs964.array.new_float(firstReconSize, NaN);
141694
+ for (let j = 0; j < firstReconSize; j++) {
141695
+ const hiVal = softThreshold(secondDownsampledHigh[j], secondAdaptiveThreshold);
141696
+ const loVal = secondDownsampledLow[j];
141697
+ if (!isNa3(hiVal) && !isNa3(loVal))
141698
+ firstReconstruct[j] = hiVal + loVal;
141699
+ }
141700
+ const advanced = cfg.upsampleType === "Advanced Upsample" ? advancedUpsample(firstReconstruct, npast, cfg.freq, cfg.upp, bi) : null;
141701
+ const upSampledSize = advanced ? advanced.length : upsampledSize(firstReconSize);
141702
+ if (upSampledSize > 0) {
141703
+ const finalReconSize = Math.min(upSampledSize, n);
141704
+ const k = bi % finalReconSize;
141705
+ const approxVal = advanced ? aget(advanced, k) : cfg.upsampleType === "Sinusoidal Upsample" ? sinusoidalUpsampleAt(firstReconstruct, k, cfg.freq, cfg.phase) : upsampleAt(firstReconstruct, k);
141706
+ const detailVal = softThreshold(downsampledHigh[k], adaptiveThreshold);
141707
+ reconstructed = !isNa3(approxVal) && !isNa3(detailVal) ? approxVal + detailVal : NaN;
141707
141708
  }
141708
141709
  }
141709
141710
  if (bi > npast && !isNa3(reconstructed))
@@ -177518,20 +177519,23 @@ function calculate1275(bars, inputs = {}) {
177518
177519
  const featureCount = cfg.featureCount;
177519
177520
  const neighborsCount = cfg.neighborsCount;
177520
177521
  const quartileIndex = import_oakscriptjs1238.math.round(neighborsCount * 3 / 4);
177521
- const distanceAt = (bar, i) => {
177522
+ const indexAt = (bar, i) => {
177522
177523
  const size2 = bar + 1;
177523
177524
  const j = i < 0 ? size2 + i : i;
177524
177525
  if (j < 0 || j >= size2)
177525
177526
  throw new Error(`Index ${i} is out of bounds, array size is ${size2}`);
177527
+ return j;
177528
+ };
177529
+ const distanceAt = (bar, j) => {
177526
177530
  switch (featureCount) {
177527
177531
  case 5:
177528
- return import_oakscriptjs1238.math.log(1 + Math.abs(f1[bar] - f1[j])) + import_oakscriptjs1238.math.log(1 + Math.abs(f2[bar] - f2[j])) + import_oakscriptjs1238.math.log(1 + Math.abs(f3[bar] - f3[j])) + import_oakscriptjs1238.math.log(1 + Math.abs(f4[bar] - f4[j])) + import_oakscriptjs1238.math.log(1 + Math.abs(f5[bar] - f5[j]));
177532
+ return Math.log(1 + Math.abs(f1[bar] - f1[j])) + Math.log(1 + Math.abs(f2[bar] - f2[j])) + Math.log(1 + Math.abs(f3[bar] - f3[j])) + Math.log(1 + Math.abs(f4[bar] - f4[j])) + Math.log(1 + Math.abs(f5[bar] - f5[j]));
177529
177533
  case 4:
177530
- return import_oakscriptjs1238.math.log(1 + Math.abs(f1[bar] - f1[j])) + import_oakscriptjs1238.math.log(1 + Math.abs(f2[bar] - f2[j])) + import_oakscriptjs1238.math.log(1 + Math.abs(f3[bar] - f3[j])) + import_oakscriptjs1238.math.log(1 + Math.abs(f4[bar] - f4[j]));
177534
+ return Math.log(1 + Math.abs(f1[bar] - f1[j])) + Math.log(1 + Math.abs(f2[bar] - f2[j])) + Math.log(1 + Math.abs(f3[bar] - f3[j])) + Math.log(1 + Math.abs(f4[bar] - f4[j]));
177531
177535
  case 3:
177532
- return import_oakscriptjs1238.math.log(1 + Math.abs(f1[bar] - f1[j])) + import_oakscriptjs1238.math.log(1 + Math.abs(f2[bar] - f2[j])) + import_oakscriptjs1238.math.log(1 + Math.abs(f3[bar] - f3[j]));
177536
+ return Math.log(1 + Math.abs(f1[bar] - f1[j])) + Math.log(1 + Math.abs(f2[bar] - f2[j])) + Math.log(1 + Math.abs(f3[bar] - f3[j]));
177533
177537
  case 2:
177534
- return import_oakscriptjs1238.math.log(1 + Math.abs(f1[bar] - f1[j])) + import_oakscriptjs1238.math.log(1 + Math.abs(f2[bar] - f2[j]));
177538
+ return Math.log(1 + Math.abs(f1[bar] - f1[j])) + Math.log(1 + Math.abs(f2[bar] - f2[j]));
177535
177539
  default:
177536
177540
  return NaN;
177537
177541
  }
@@ -177548,11 +177552,13 @@ function calculate1275(bars, inputs = {}) {
177548
177552
  if (bar >= maxBarsBackIndex) {
177549
177553
  const step = startIndex <= sizeLoop ? 1 : -1;
177550
177554
  for (let i = startIndex; step > 0 ? i <= sizeLoop : i >= sizeLoop; i += step) {
177551
- const d12 = distanceAt(bar, i);
177552
- if (ge288(d12, lastDistance) && i % 4 !== 0) {
177555
+ const j = indexAt(bar, i);
177556
+ if (i % 4 === 0)
177557
+ continue;
177558
+ const d12 = distanceAt(bar, j);
177559
+ if (ge288(d12, lastDistance)) {
177553
177560
  lastDistance = d12;
177554
177561
  distances.push(d12);
177555
- const j = i < 0 ? bar + 1 + i : i;
177556
177562
  predictions.push(import_oakscriptjs1238.math.round(yTrain[j]));
177557
177563
  if (predictions.length > neighborsCount) {
177558
177564
  if (quartileIndex >= distances.length) {
@@ -228789,7 +228795,7 @@ function calculate1418(bars, inputs = {}) {
228789
228795
  let start = NaN;
228790
228796
  let found = false;
228791
228797
  let extreme = NaN;
228792
- for (const i of range3(0, len)) {
228798
+ for (let i = 0; i <= len; i++) {
228793
228799
  if (t) {
228794
228800
  if (na3(extreme) || gt815(H(i), extreme))
228795
228801
  extreme = H(i);
@@ -228823,40 +228829,44 @@ function calculate1418(bars, inputs = {}) {
228823
228829
  if (lt648(L4(k), lSince) || eq166(lSince, 0))
228824
228830
  lSince = L4(k);
228825
228831
  };
228826
- for (const i of range3(start, len))
228832
+ const trackStep = start <= len ? 1 : -1;
228833
+ for (let i = start; trackStep > 0 ? i <= len : i >= len; i += trackStep)
228827
228834
  track(i);
228828
- for (const i of range3(start, lb)) {
228829
- track(i + len);
228830
- const ph = at2(pv2.ph, i);
228831
- const pl = at2(pv2.pl, i);
228832
- const lowPoint = (ref) => {
228833
- if (gt815(hSince, ref))
228835
+ let ph = NaN;
228836
+ let pl = NaN;
228837
+ const lowPoint = (ref) => {
228838
+ if (gt815(hSince, ref))
228839
+ return "break";
228840
+ if (!na3(ph))
228841
+ return gt815(ph, ref) ? "break" : "skip";
228842
+ if (!na3(pl)) {
228843
+ if (gt815(pl, ref))
228834
228844
  return "break";
228835
- if (!na3(ph))
228836
- return gt815(ph, ref) ? "break" : "skip";
228837
- if (!na3(pl)) {
228838
- if (gt815(pl, ref))
228839
- return "break";
228840
- if (lt648(lSince, pl))
228841
- return "break";
228842
- return pl;
228843
- }
228844
- return "skip";
228845
- };
228846
- const highPoint = (ref) => {
228847
- if (lt648(lSince, ref))
228845
+ if (lt648(lSince, pl))
228848
228846
  return "break";
228849
- if (!na3(pl))
228850
- return lt648(pl, ref) ? "break" : "skip";
228851
- if (!na3(ph)) {
228852
- if (lt648(ph, ref))
228853
- return "break";
228854
- if (gt815(hSince, ph))
228855
- return "break";
228856
- return ph;
228857
- }
228858
- return "skip";
228859
- };
228847
+ return pl;
228848
+ }
228849
+ return "skip";
228850
+ };
228851
+ const highPoint = (ref) => {
228852
+ if (lt648(lSince, ref))
228853
+ return "break";
228854
+ if (!na3(pl))
228855
+ return lt648(pl, ref) ? "break" : "skip";
228856
+ if (!na3(ph)) {
228857
+ if (lt648(ph, ref))
228858
+ return "break";
228859
+ if (gt815(hSince, ph))
228860
+ return "break";
228861
+ return ph;
228862
+ }
228863
+ return "skip";
228864
+ };
228865
+ const step = start <= lb ? 1 : -1;
228866
+ for (let i = start; step > 0 ? i <= lb : i >= lb; i += step) {
228867
+ track(i + len);
228868
+ ph = at2(pv2.ph, i);
228869
+ pl = at2(pv2.pl, i);
228860
228870
  if (b === -1) {
228861
228871
  const r = t ? lowPoint(cY) : highPoint(cY);
228862
228872
  if (r === "break")
@@ -260651,6 +260661,17 @@ function calculate1497(bars, inputs = {}) {
260651
260661
  });
260652
260662
  return true;
260653
260663
  };
260664
+ const memo = (format) => {
260665
+ const texts = /* @__PURE__ */ new Map();
260666
+ return (v) => {
260667
+ let text = texts.get(v);
260668
+ if (text === void 0)
260669
+ texts.set(v, text = format(v));
260670
+ return text;
260671
+ };
260672
+ };
260673
+ const volumeText = memo(formatVal);
260674
+ const countText = memo((v) => import_oakscriptjs1460.str.format("{0}", v));
260654
260675
  for (let i = 0; i < n; i++) {
260655
260676
  (0, import_oakscriptjs1460.setDrawingBar)(i, i === n - 1);
260656
260677
  const b = bars[i];
@@ -260854,7 +260875,14 @@ function calculate1497(bars, inputs = {}) {
260854
260875
  } else if (l.extBoxId) {
260855
260876
  l.extBoxId = drop(l.extBoxId);
260856
260877
  }
260857
- const txt = import_oakscriptjs1460.str.format("E:{0} | S:{1} | SW:{2} | V:{3} | D:{4}", l.entries, l.strength, l.sweeps, formatVal(l.tradedVolume), curD);
260878
+ const txt = import_oakscriptjs1460.str.format(
260879
+ "E:{0} | S:{1} | SW:{2} | V:{3} | D:{4}",
260880
+ countText(l.entries),
260881
+ countText(l.strength),
260882
+ countText(l.sweeps),
260883
+ volumeText(l.tradedVolume),
260884
+ countText(curD)
260885
+ );
260858
260886
  if (!l.statsLabel) {
260859
260887
  l.statsLabel = newLabel(endExt, avgY, false, txt, c4, "label_left", "tiny");
260860
260888
  } else {
@@ -269935,6 +269963,38 @@ var gt908 = (a, b) => a - b > EPS913;
269935
269963
  var lt729 = (a, b) => b - a > EPS913;
269936
269964
  var TABLE_COLOR = "#160d0db3";
269937
269965
  var NO_COLOR10 = "#00000000";
269966
+ function loopExtremeSite(isLowest, length) {
269967
+ const kept = [];
269968
+ const better = (a, b) => isLowest ? a < b : a > b;
269969
+ let bar = NaN;
269970
+ let own = NaN;
269971
+ let before = NaN;
269972
+ let beforeAll = NaN;
269973
+ return (barIndex, value) => {
269974
+ if (barIndex !== bar) {
269975
+ if (!Number.isNaN(own))
269976
+ kept.push(own);
269977
+ bar = barIndex;
269978
+ own = NaN;
269979
+ before = NaN;
269980
+ beforeAll = NaN;
269981
+ for (let k = kept.length - 1, count = 0; k >= 0 && count < length; k--, count++) {
269982
+ const v = kept[k];
269983
+ if (count < length - 1 && (Number.isNaN(before) || better(v, before)))
269984
+ before = v;
269985
+ if (Number.isNaN(beforeAll) || better(v, beforeAll))
269986
+ beforeAll = v;
269987
+ }
269988
+ }
269989
+ if (Number.isFinite(value))
269990
+ own = value;
269991
+ if (barIndex < length - 1)
269992
+ return NaN;
269993
+ if (Number.isNaN(own))
269994
+ return beforeAll;
269995
+ return !Number.isNaN(before) && better(before, own) ? before : own;
269996
+ };
269997
+ }
269938
269998
  function calculate1521(bars, inputs = {}) {
269939
269999
  const cfg = { ...defaultInputs1521, ...inputs };
269940
270000
  const n = bars.length;
@@ -270030,9 +270090,9 @@ function calculate1521(bars, inputs = {}) {
270030
270090
  if (featureCount >= 5)
270031
270091
  current.push(normalizeSeries(close11.map((v, i) => v - (i >= 5 ? close11[i - 5] : NaN))));
270032
270092
  const loopNormalize = () => {
270033
- const hi = import_oakscriptjs1484.callsite.highestByBar();
270034
- const lo = import_oakscriptjs1484.callsite.lowestByBar();
270035
- return (bar, source) => scale(source, hi(bar, source, knnLookback), lo(bar, source, knnLookback));
270093
+ const hi = loopExtremeSite(false, knnLookback);
270094
+ const lo = loopExtremeSite(true, knnLookback);
270095
+ return (bar, source) => scale(source, hi(bar, source), lo(bar, source));
270036
270096
  };
270037
270097
  const loopMomentum = (length) => {
270038
270098
  const kept = [];
@@ -282132,6 +282192,7 @@ function calculate1561(bars, inputs = {}, chart) {
282132
282192
  const ext = cfg.extendL ? "both" : "right";
282133
282193
  const alertCalls = [];
282134
282194
  const ticker = tickerOf(chart);
282195
+ let barIdx = 0;
282135
282196
  const half = cfg.depth / 2;
282136
282197
  const back4 = Math.trunc(half);
282137
282198
  const span = half * 2;
@@ -282207,20 +282268,24 @@ function calculate1561(bars, inputs = {}, chart) {
282207
282268
  };
282208
282269
  const tooltipText = (level3, price, tool) => `${tool} Level ${import_oakscriptjs1524.str.tostring(level3)} : ${priceText(price)}`;
282209
282270
  const drawLabel = (site, index, price, txt, colorx, txtColor, style, size2, align2, tooltip) => {
282271
+ const last = barIdx === n - 1;
282210
282272
  let v = varLabels.get(site);
282211
282273
  if (!v) {
282212
282274
  v = (0, import_oakscriptjs1524.varDrawing)();
282213
- v.value = import_oakscriptjs1524.label.new(index, price, txt, "bar_index", "price", colorx, style, txtColor, size2, align2);
282275
+ v.value = import_oakscriptjs1524.label.new(index, price, last ? txt() : "", "bar_index", "price", colorx, style, txtColor, size2, align2);
282214
282276
  varLabels.set(site, v);
282215
282277
  }
282216
282278
  const id = v.value;
282217
282279
  import_oakscriptjs1524.label.set_xy(id, index, price);
282218
- import_oakscriptjs1524.label.set_text(id, txt + ALIGN_PAD);
282280
+ if (last)
282281
+ import_oakscriptjs1524.label.set_text(id, txt() + ALIGN_PAD);
282219
282282
  import_oakscriptjs1524.label.set_textcolor(id, txtColor);
282220
- import_oakscriptjs1524.label.set_tooltip(id, tooltip);
282283
+ if (last)
282284
+ import_oakscriptjs1524.label.set_tooltip(id, tooltip());
282221
282285
  };
282222
282286
  for (let i = 0; i < n; i++) {
282223
282287
  (0, import_oakscriptjs1524.setDrawingBar)(i, i === n - 1);
282288
+ barIdx = i;
282224
282289
  const close11 = bars[i].close;
282225
282290
  const closePrev = i > 0 ? bars[i - 1].close : NaN;
282226
282291
  const crossing = (r) => gt941(r, close11) && lt754(r, closePrev) || lt754(r, close11) && gt941(r, closePrev);
@@ -282276,15 +282341,15 @@ function calculate1561(bars, inputs = {}, chart) {
282276
282341
  `${key2}:chl`,
282277
282342
  i,
282278
282343
  pLastBar,
282279
- labelText2(value, pLastBar, "CHL "),
282344
+ () => labelText2(value, pLastBar, "CHL "),
282280
282345
  "#00000000",
282281
282346
  col2,
282282
282347
  "label_left",
282283
282348
  "normal",
282284
282349
  "left",
282285
- tooltipText(value, pLastBar, "Fib Channel")
282350
+ () => tooltipText(value, pLastBar, "Fib Channel")
282286
282351
  );
282287
- drawLabel(`${key2}:dot`, i, pLastBar, "", col2, "#00000000", "circle", "auto", "left", "");
282352
+ drawLabel(`${key2}:dot`, i, pLastBar, () => "", col2, "#00000000", "circle", "auto", "left", () => "");
282288
282353
  }
282289
282354
  if (crossing(pLastBar)) {
282290
282355
  alertCalls.push({ time: bars[i].time, message: "AutoFibChannel: " + ticker + " crossing level " + import_oakscriptjs1524.str.tostring(value), freq: "once_per_bar" });
@@ -282330,13 +282395,13 @@ function calculate1561(bars, inputs = {}, chart) {
282330
282395
  `${key2}:ret`,
282331
282396
  isExt ? iMidPivot : iStartBase,
282332
282397
  r,
282333
- labelText2(value, r, isExt ? "EXT " : "RET "),
282398
+ () => labelText2(value, r, isExt ? "EXT " : "RET "),
282334
282399
  "#00000000",
282335
282400
  col2,
282336
282401
  "label_right",
282337
282402
  "normal",
282338
282403
  "right",
282339
- tooltipText(value, r, isExt ? "Fib Extention" : "Fib Retracement")
282404
+ () => tooltipText(value, r, isExt ? "Fib Extention" : "Fib Retracement")
282340
282405
  );
282341
282406
  }
282342
282407
  if (crossing(r)) {
@@ -288547,11 +288612,19 @@ function calculate1576(bars, inputs = {}, chart) {
288547
288612
  import_oakscriptjs1539.box.set_right(topBox.value, i);
288548
288613
  }
288549
288614
  if (isNewPivot && topBoxes.length > 0) {
288615
+ let kept = 0;
288550
288616
  for (let k = 0; k < topBoxes.length; k++) {
288617
+ if (Number.isNaN(import_oakscriptjs1539.box.get_left(topBoxes[k])) && Number.isNaN(import_oakscriptjs1539.label.get_x(bottomLabels[k])))
288618
+ continue;
288551
288619
  import_oakscriptjs1539.box.set_top(topBoxes[k], boxTop[i]);
288552
288620
  import_oakscriptjs1539.box.set_bottom(topBoxes[k], boxBottom[i]);
288553
288621
  import_oakscriptjs1539.label.set_y(bottomLabels[k], labelLevel[i]);
288622
+ topBoxes[kept] = topBoxes[k];
288623
+ bottomLabels[kept] = bottomLabels[k];
288624
+ kept++;
288554
288625
  }
288626
+ topBoxes.length = kept;
288627
+ bottomLabels.length = kept;
288555
288628
  }
288556
288629
  if (isNewWeek) {
288557
288630
  import_oakscriptjs1539.line.new(i, b.low, i, b.high, "bar_index", "both", cfg.weeklySeparatorColorInput, weeklyStyle, cfg.weeklySeparatorWidthInput);
@@ -294452,10 +294525,20 @@ function calculate1591(bars, inputs = {}, chart) {
294452
294525
  return import_oakscriptjs1554.line.new(i, value, i, value);
294453
294526
  return null;
294454
294527
  };
294528
+ const priceTexts = /* @__PURE__ */ new Map();
294529
+ const priceText = (v) => {
294530
+ let text = priceTexts.get(v);
294531
+ if (text === void 0) {
294532
+ text = import_oakscriptjs1554.str.tostring(import_oakscriptjs1554.math.round_to_mintick(v, mintick));
294533
+ if (!Object.is(v, -0))
294534
+ priceTexts.set(v, text);
294535
+ }
294536
+ return text;
294537
+ };
294455
294538
  const priceLabel = (i, value, col2, prefix) => {
294456
294539
  if (!(cfg.displaySupportResistance && cfg.displayPriceLevels))
294457
294540
  return null;
294458
- const text = prefix + " - " + import_oakscriptjs1554.str.tostring(import_oakscriptjs1554.math.round_to_mintick(value, mintick));
294541
+ const text = prefix + " - " + priceText(value);
294459
294542
  return import_oakscriptjs1554.label.new(i, value, text, "bar_index", "price", void 0, "none", col2);
294460
294543
  };
294461
294544
  const y12 = (l) => l ? import_oakscriptjs1554.line.get_y1(l) : NaN;
@@ -294521,13 +294604,13 @@ function calculate1591(bars, inputs = {}, chart) {
294521
294604
  const ref = bearish ? up : lo;
294522
294605
  if (wickStyle || fullStyle) {
294523
294606
  if (lHigh) {
294524
- import_oakscriptjs1554.label.set_text(lHigh, (bearish ? BEAR_PREFIX : BULL_PREFIX) + import_oakscriptjs1554.str.tostring(import_oakscriptjs1554.math.round_to_mintick(y12(ref), mintick)));
294607
+ import_oakscriptjs1554.label.set_text(lHigh, (bearish ? BEAR_PREFIX : BULL_PREFIX) + priceText(y12(ref)));
294525
294608
  import_oakscriptjs1554.label.set_size(lHigh, "small");
294526
294609
  import_oakscriptjs1554.label.set_x(lHigh, i);
294527
294610
  }
294528
294611
  } else if (avgStyle) {
294529
294612
  if (lMid) {
294530
- import_oakscriptjs1554.label.set_text(lMid, (bearish ? BEAR_PREFIX : BULL_PREFIX) + import_oakscriptjs1554.str.tostring(import_oakscriptjs1554.math.round_to_mintick(y12(mid), mintick)));
294613
+ import_oakscriptjs1554.label.set_text(lMid, (bearish ? BEAR_PREFIX : BULL_PREFIX) + priceText(y12(mid)));
294531
294614
  import_oakscriptjs1554.label.set_size(lMid, "small");
294532
294615
  import_oakscriptjs1554.label.set_x(lMid, i);
294533
294616
  }
@@ -295645,8 +295728,6 @@ function calculate1596(bars, inputs = {}, chart) {
295645
295728
  for (let i = 0; i < n; i++) {
295646
295729
  (0, import_oakscriptjs1559.setDrawingBar)(i, i === n - 1);
295647
295730
  const b = bars[i];
295648
- const lines = import_oakscriptjs1559.line.all();
295649
- const labels = import_oakscriptjs1559.label.all();
295650
295731
  const back4 = i >= barsReq ? bars[i - barsReq] : null;
295651
295732
  const backLow = back4 ? back4.low : NaN;
295652
295733
  const backHigh = back4 ? back4.high : NaN;
@@ -295668,6 +295749,8 @@ function calculate1596(bars, inputs = {}, chart) {
295668
295749
  }
295669
295750
  const bullish = lastDown && barsCount >= barsReq && gainCheck && (cfg.opposites ? !bu : true);
295670
295751
  const bearish = lastUp && barsCount >= barsReq && gainCheck && (cfg.opposites ? !be : true);
295752
+ const lines = bullish || bearish ? import_oakscriptjs1559.line.all() : [];
295753
+ const labels = bullish || bearish ? import_oakscriptjs1559.label.all() : [];
295671
295754
  if (bullish) {
295672
295755
  for (const l of lines)
295673
295756
  import_oakscriptjs1559.line.delete(l);
@@ -295794,6 +295877,8 @@ function calculate1596(bars, inputs = {}, chart) {
295794
295877
  }
295795
295878
  }
295796
295879
  for (const o of obBoxArr) {
295880
+ if (!o.a)
295881
+ continue;
295797
295882
  if (o.a)
295798
295883
  import_oakscriptjs1559.box.set_right(o.bx, i);
295799
295884
  const left = import_oakscriptjs1559.box.get_left(o.bx);
@@ -296012,15 +296097,12 @@ function autoFeatureWeights(bank, minRows, floor) {
296012
296097
  const o = row[8];
296013
296098
  if (gt972(o, 0) || lt784(o, 0)) {
296014
296099
  const isB = gt972(o, 0);
296100
+ const sum2 = isB ? sumB : sumBe;
296101
+ const sq2 = isB ? sqB : sqBe;
296015
296102
  for (let j = 0; j < 8; j++) {
296016
296103
  const v = row[j];
296017
- if (isB) {
296018
- sumB[j] = sumB[j] + v;
296019
- sqB[j] = sqB[j] + v * v;
296020
- } else {
296021
- sumBe[j] = sumBe[j] + v;
296022
- sqBe[j] = sqBe[j] + v * v;
296023
- }
296104
+ sum2[j] = sum2[j] + v;
296105
+ sq2[j] = sq2[j] + v * v;
296024
296106
  }
296025
296107
  if (isB)
296026
296108
  cntB += 1;
@@ -296114,9 +296196,7 @@ function calculate1597(bars, inputs = {}, chart) {
296114
296196
  const bankN = bank.length;
296115
296197
  const scanEnd = Math.min(memoryDepth - 1, bankN - 1);
296116
296198
  if (bankN > 1) {
296117
- for (let idx = 0; idx <= scanEnd; idx++) {
296118
- if (idx % SPACING !== 0)
296119
- continue;
296199
+ for (let idx = 0; idx <= scanEnd; idx += SPACING) {
296120
296200
  const row = bank[idx];
296121
296201
  let g = w[0] * compress2(cur[0] - row[0]);
296122
296202
  for (let j = 1; j < 8; j++)
@@ -301255,11 +301335,25 @@ function changeValues5() {
301255
301335
  get: (occurrence) => occurrence >= 0 && values.length > occurrence ? values[values.length - 1 - occurrence] : NaN
301256
301336
  };
301257
301337
  }
301338
+ function cachedText(format) {
301339
+ const texts = /* @__PURE__ */ new Map();
301340
+ return (v) => {
301341
+ if (Object.is(v, -0))
301342
+ return format(v);
301343
+ let s = texts.get(v);
301344
+ if (s === void 0) {
301345
+ s = format(v);
301346
+ texts.set(v, s);
301347
+ }
301348
+ return s;
301349
+ };
301350
+ }
301258
301351
  function calculate1608(bars, inputs = {}, chart) {
301259
301352
  const cfg = { ...defaultInputs1608, ...inputs };
301260
301353
  const n = bars.length;
301261
301354
  const tick = mintickOf(chart);
301262
- const priceText = (v) => import_oakscriptjs1571.str.tostring(v, "mintick", tick);
301355
+ const priceText = cachedText((v) => import_oakscriptjs1571.str.tostring(v, "mintick", tick));
301356
+ const levelText = cachedText((v) => import_oakscriptjs1571.str.tostring(v));
301263
301357
  const atr10 = import_oakscriptjs1571.ta.atr(bars, 10).toArray().map((v) => v ?? NaN);
301264
301358
  const lsize = cfg.lSize === "Normal" ? "normal" : cfg.lSize === "Small" ? "small" : "large";
301265
301359
  const hist3 = Math.trunc(cfg.histPivot);
@@ -301359,7 +301453,7 @@ function calculate1608(bars, inputs = {}, chart) {
301359
301453
  if (gt982(r, c0) && lt793(r, c1) || lt793(r, c0) && gt982(r, c1)) {
301360
301454
  alertCalls.push({
301361
301455
  time: bars[barIdx].time,
301362
- message: "AutoFibFan: " + ticker + " crossing " + ptl + " level " + import_oakscriptjs1571.str.tostring(level3),
301456
+ message: "AutoFibFan: " + ticker + " crossing " + ptl + " level " + levelText(level3),
301363
301457
  freq: "once_per_bar"
301364
301458
  });
301365
301459
  }
@@ -301371,7 +301465,7 @@ function calculate1608(bars, inputs = {}, chart) {
301371
301465
  else
301372
301466
  (was === "first" ? aLnt1 : aLnt2).push(copy);
301373
301467
  };
301374
- const levelLabelText = (content, lb, y) => content === "Levels" ? import_oakscriptjs1571.str.tostring(lb) : content === "Prices" ? priceText(y) : import_oakscriptjs1571.str.tostring(lb) + " (" + priceText(y) + ")";
301468
+ const levelLabelText = (content, lb, y) => content === "Levels" ? levelText(lb) : content === "Prices" ? priceText(y) : levelText(lb) + " (" + priceText(y) + ")";
301375
301469
  const drawLabelX = (x1, y12, x2, y22, c4, lb, st) => {
301376
301470
  if (st) {
301377
301471
  if (cfg.lbRight !== "None") {
@@ -301406,10 +301500,10 @@ function calculate1608(bars, inputs = {}, chart) {
301406
301500
  }
301407
301501
  } else {
301408
301502
  if (cfg.tpLabel) {
301409
- aLb.push(import_oakscriptjs1571.label.new(x1, Math.max(y12, y22), import_oakscriptjs1571.str.tostring(lb), "bar_index", "price", "#00000000", "label_down", c4, lsize));
301503
+ aLb.push(import_oakscriptjs1571.label.new(x1, Math.max(y12, y22), levelText(lb), "bar_index", "price", "#00000000", "label_down", c4, lsize));
301410
301504
  }
301411
301505
  if (cfg.btLabel) {
301412
- aLb.push(import_oakscriptjs1571.label.new(x1, Math.min(y12, y22), import_oakscriptjs1571.str.tostring(lb), "bar_index", "price", "#00000000", "label_up", c4, lsize));
301506
+ aLb.push(import_oakscriptjs1571.label.new(x1, Math.min(y12, y22), levelText(lb), "bar_index", "price", "#00000000", "label_up", c4, lsize));
301413
301507
  }
301414
301508
  }
301415
301509
  };
@@ -319681,7 +319775,17 @@ function calculate1652(bars, inputs = {}, chart) {
319681
319775
  }
319682
319776
  }
319683
319777
  };
319684
- const srText = (isRes, level3) => import_oakscriptjs1615.str.format("{0} \u2022 {1}", isRes ? "R" : "S", rtm(level3));
319778
+ const srTexts = [/* @__PURE__ */ new Map(), /* @__PURE__ */ new Map()];
319779
+ const srText = (isRes, level3) => {
319780
+ const memo = srTexts[isRes ? 0 : 1];
319781
+ let text = memo.get(level3);
319782
+ if (text === void 0) {
319783
+ text = import_oakscriptjs1615.str.format("{0} \u2022 {1}", isRes ? "R" : "S", rtm(level3));
319784
+ if (level3 !== 0)
319785
+ memo.set(level3, text);
319786
+ }
319787
+ return text;
319788
+ };
319685
319789
  const deleteSrZone = (idx) => {
319686
319790
  const z = srZones[idx];
319687
319791
  if (z.line)
@@ -322973,7 +323077,7 @@ var LIGHT_COLORS = [
322973
323077
  [12, 123, 147],
322974
323078
  [195, 43, 173]
322975
323079
  ];
322976
- var newPivot = (point, dir) => ({ point, dir, level: 0, ratio: 1, sizeRatio: 1, barRatio: 1 });
323080
+ var newPivot = (point, dir) => ({ point, dir, level: 0, ratio: 1 });
322977
323081
  var newZigzag = (length, numberOfPivots) => ({ length, numberOfPivots, level: 0, pivots: [], newPivot: false });
322978
323082
  function addNewPivot(z, pivot) {
322979
323083
  const dir = Math.sign(pivot.dir);
@@ -322987,12 +323091,7 @@ function addNewPivot(z, pivot) {
322987
323091
  const value = pivot.point.price;
322988
323092
  const llastValue = llastPivot.point.price;
322989
323093
  pivot.dir = import_oakscriptjs1622.compare.gt(dir * value, dir * llastValue) ? dir * 2 : dir;
322990
- pivot.ratio = import_oakscriptjs1622.math.round(Math.abs(lastValue - value) / Math.abs(llastValue - lastValue), 3);
322991
- pivot.barRatio = import_oakscriptjs1622.math.round(Math.abs(lastPivot.point.index - pivot.point.index) / Math.abs(llastPivot.point.index - lastPivot.point.index), 3);
322992
- if (z.pivots.length >= 3) {
322993
- const lllastValue = z.pivots[2].point.price;
322994
- pivot.sizeRatio = import_oakscriptjs1622.math.round(Math.abs(lastValue - value) / Math.abs(lllastValue - llastValue), 3);
322995
- }
323094
+ pivot.ratio = Math.abs(lastValue - value) / Math.abs(llastValue - lastValue);
322996
323095
  }
322997
323096
  }
322998
323097
  z.pivots.unshift(pivot);
@@ -323217,7 +323316,8 @@ function calculate1659(bars, inputs = {}, chart) {
323217
323316
  const aDir = Math.abs(a.dir);
323218
323317
  const bDir = Math.abs(b.dir);
323219
323318
  const conditionInLine = condition === 0 || condition === 1 && aDir === 1 && bDir === 2 || condition === 2 && aDir === 2 && bDir === 1 || condition === 3 && aDir === 1 && bDir === 1 || condition === 4 && aDir === 2 && bDir === 2;
323220
- const ratioInLine = ge547(c4.ratio, 0.618) && le397(c4.ratio, 0.786);
323319
+ const ratio = import_oakscriptjs1622.math.round(c4.ratio, 3);
323320
+ const ratioInLine = ge547(ratio, 0.618) && le397(ratio, 0.786);
323221
323321
  if (ratioInLine && conditionInLine) {
323222
323322
  isAbc = true;
323223
323323
  for (const p of abcdPatterns) {
@@ -332993,7 +333093,8 @@ ${EM3}`);
332993
333093
  s.rrtAvgTpBars[j] = import_oakscriptjs1640.math.round(s.tpBarsCount[j] / gTpHitCount[j]);
332994
333094
  s.rrtAvgTslBars = import_oakscriptjs1640.math.round(s.tslBarsCount / gTslHitCount);
332995
333095
  const S2 = (x) => import_oakscriptjs1640.str.tostring(x);
332996
- if (cfg.rrtActivated && rrTable) {
333096
+ const lastBar = i === n - 1;
333097
+ if (cfg.rrtActivated && rrTable && lastBar) {
332997
333098
  const tb = rrTable;
332998
333099
  const size2 = cfg.rrtTextSize;
332999
333100
  const cell = (c4, r2, text, textColor, bg, tooltip, halign = "center") => import_oakscriptjs1640.table.cell(tb, c4, r2, text, 0, 0, textColor, halign, "center", size2, bg, tooltip);
@@ -333064,7 +333165,7 @@ ${EM3}`);
333064
333165
  import_oakscriptjs1640.table.merge_cells(tb, 22, 0, 23, 0);
333065
333166
  }
333066
333167
  }
333067
- if (cfg.tttActivated && ttTable) {
333168
+ if (cfg.tttActivated && ttTable && lastBar) {
333068
333169
  const tb = ttTable;
333069
333170
  const size2 = cfg.tttTextSize;
333070
333171
  const cell = (c4, r2, text, textColor, bg, tooltip, halign = "center") => import_oakscriptjs1640.table.cell(tb, c4, r2, text, 0, 0, textColor, halign, "center", size2, bg, tooltip);
@@ -344448,6 +344549,34 @@ var gt1061 = (a, b) => a - b > EPS1067;
344448
344549
  var lt865 = (a, b) => b - a > EPS1067;
344449
344550
  var ge500 = (a, b) => a - b >= -EPS1067;
344450
344551
  var le354 = (a, b) => b - a >= -EPS1067;
344552
+ function pivotsByLeft(source, minLeft, maxLeft, isHigh) {
344553
+ const n = source.length;
344554
+ const values = [];
344555
+ const barOf = [];
344556
+ const out = Array.from({ length: maxLeft - minLeft + 1 }, () => new Array(n).fill(NaN));
344557
+ for (let i = 0; i < n; i++) {
344558
+ if (Number.isFinite(source[i])) {
344559
+ values.push(source[i]);
344560
+ barOf.push(i);
344561
+ }
344562
+ const k = values.length - 1;
344563
+ if (k < 0)
344564
+ continue;
344565
+ let best = k;
344566
+ let j = k - 1;
344567
+ for (let left = minLeft; left <= maxLeft && i >= left + 1; left++) {
344568
+ for (; j >= 0 && j >= k - left - 1; j--) {
344569
+ if (isHigh ? values[j] > values[best] : values[j] < values[best])
344570
+ best = j;
344571
+ }
344572
+ if (barOf[best] < i - 1)
344573
+ break;
344574
+ if (barOf[best] === i - 1)
344575
+ out[left - minLeft][i] = values[best];
344576
+ }
344577
+ }
344578
+ return out;
344579
+ }
344451
344580
  function calculate1714(allBars, inputs = {}, chart) {
344452
344581
  const cfg = { ...defaultInputs1714, ...inputs };
344453
344582
  const bars = allBars.length > CALC_BARS6 ? allBars.slice(allBars.length - CALC_BARS6) : allBars;
@@ -344467,14 +344596,8 @@ function calculate1714(allBars, inputs = {}, chart) {
344467
344596
  const toMs = chart?.timeUnit === "ms" || chart?.timeUnit === void 0 && n > 0 && bars[0].time >= 1e12 ? 1 : 1e3;
344468
344597
  const high16 = bars.map((b) => b.high);
344469
344598
  const low17 = bars.map((b) => b.low);
344470
- const highS = import_oakscriptjs1677.Series.fromBars(bars, "high");
344471
- const lowS = import_oakscriptjs1677.Series.fromBars(bars, "low");
344472
- const phs = [];
344473
- const pls = [];
344474
- for (let i = 0; i < dif; i++) {
344475
- phs.push(import_oakscriptjs1677.ta.pivothigh(highS, stt + i, 1).toArray());
344476
- pls.push(import_oakscriptjs1677.ta.pivotlow(lowS, stt + i, 1).toArray());
344477
- }
344599
+ const phs = pivotsByLeft(high16, stt, num5 - 1, true);
344600
+ const pls = pivotsByLeft(low17, stt, num5 - 1, false);
344478
344601
  (0, import_oakscriptjs1677.resetDrawings)({ line: 500, label: 500, box: 500, polyline: 100 });
344479
344602
  const tb = import_oakscriptjs1677.table.new(tablePosition, 1, 1, "#1e222d", "#373a46", 1, "#373a46", 1);
344480
344603
  const arrayZZ = [];
@@ -344530,8 +344653,8 @@ ${NB2.repeat(3)}\u2534
344530
344653
  const arrBin = [NaN, NaN, NaN];
344531
344654
  for (let z = dif - 1; z >= 0; z--) {
344532
344655
  const piv = arrayZZ[z];
344533
- const ph = phs[z][i] ?? NaN;
344534
- const pl = pls[z][i] ?? NaN;
344656
+ const ph = phs[z][i];
344657
+ const pl = pls[z][i];
344535
344658
  if (!Number.isNaN(ph)) {
344536
344659
  const p = piv[0];
344537
344660
  const Dx = i - right2;
@@ -349696,65 +349819,79 @@ function addNewPivot2(m, pivot, max35) {
349696
349819
  if (m.length > max35)
349697
349820
  m.pop();
349698
349821
  }
349822
+ function pushPivot(m, pivot, max35) {
349823
+ const dir = Math.sign(pivot[3]);
349824
+ const k = m.length;
349825
+ if (k >= 1) {
349826
+ if (Math.sign(m[k - 1][3]) === Math.sign(dir))
349827
+ throw new Error("Direction mismatch");
349828
+ if (k >= 2) {
349829
+ const value = pivot[0];
349830
+ const llastValue = m[k - 2][0];
349831
+ pivot[3] = gt1076(dir * value, dir * llastValue) ? dir * 2 : dir;
349832
+ }
349833
+ }
349834
+ m.push(pivot);
349835
+ if (m.length > max35)
349836
+ m.shift();
349837
+ }
349699
349838
  function nextLevel2(m, max35) {
349700
- let ml = [];
349839
+ const ml = [];
349701
349840
  if (m.length > 0) {
349702
- const bullish = [];
349703
- const bearish = [];
349704
- const set = (target, values) => {
349705
- target.length = 0;
349706
- target.push(...values);
349841
+ let bullish = null;
349842
+ let bearish = null;
349843
+ const copy = (src) => {
349844
+ const row = src.slice();
349845
+ row[4] = row[4] + 1;
349846
+ return row;
349707
349847
  };
349708
349848
  for (let i = m.length - 1; i >= 0; i--) {
349709
- const row = m[i].slice();
349710
- const dir = row[3];
349849
+ const src = m[i];
349850
+ const dir = src[3];
349711
349851
  const newDir = Math.sign(dir);
349712
- const value = row[0];
349713
- row[4] = row[4] + 1;
349852
+ const value = src[0];
349714
349853
  if (ml.length > 0) {
349715
- const lastDir = Math.sign(ml[0][3]);
349716
- const lastPivot = ml[0][0];
349854
+ const lastDir = Math.sign(ml[ml.length - 1][3]);
349855
+ const lastPivot = ml[ml.length - 1][0];
349717
349856
  if (Math.abs(dir) === 2) {
349718
349857
  if (lastDir === newDir) {
349719
349858
  if (lt880(dir * lastPivot, dir * value)) {
349720
- ml.shift();
349859
+ ml.pop();
349721
349860
  } else {
349722
349861
  const tempRow = newDir > 0 ? bearish : bullish;
349723
- if (tempRow.length > 0)
349724
- addNewPivot2(ml, tempRow.slice(), max35);
349862
+ if (tempRow)
349863
+ pushPivot(ml, copy(tempRow), max35);
349725
349864
  else
349726
349865
  continue;
349727
349866
  }
349728
349867
  } else {
349729
349868
  const first = newDir > 0 ? bullish : bearish;
349730
349869
  const second = newDir > 0 ? bearish : bullish;
349731
- if (first.length > 0 && second.length > 0) {
349732
- if (gt1076(newDir * first[0], newDir * row[0])) {
349733
- addNewPivot2(ml, first.slice(), max35);
349734
- addNewPivot2(ml, second.slice(), max35);
349870
+ if (first && second) {
349871
+ if (gt1076(newDir * first[0], newDir * value)) {
349872
+ pushPivot(ml, copy(first), max35);
349873
+ pushPivot(ml, copy(second), max35);
349735
349874
  }
349736
349875
  }
349737
349876
  }
349738
- addNewPivot2(ml, row, max35);
349739
- bearish.length = 0;
349740
- bullish.length = 0;
349877
+ pushPivot(ml, copy(src), max35);
349878
+ bearish = null;
349879
+ bullish = null;
349741
349880
  } else {
349742
349881
  const tempRow = newDir > 0 ? bullish : bearish;
349743
- if (tempRow.length !== 0) {
349744
- if (gt1076(row[0] * dir, tempRow[0] * dir))
349745
- set(tempRow, row);
349746
- } else {
349747
- set(tempRow, row);
349882
+ if (!tempRow || gt1076(value * dir, tempRow[0] * dir)) {
349883
+ if (newDir > 0)
349884
+ bullish = src;
349885
+ else
349886
+ bearish = src;
349748
349887
  }
349749
349888
  }
349750
349889
  } else if (Math.abs(dir) === 2) {
349751
- addNewPivot2(ml, row, max35);
349890
+ pushPivot(ml, copy(src), max35);
349752
349891
  }
349753
349892
  }
349754
349893
  }
349755
- if (ml.length >= m.length)
349756
- ml = [];
349757
- return ml;
349894
+ return ml.length >= m.length ? [] : ml.reverse();
349758
349895
  }
349759
349896
  function calculate1732(bars, inputs = {}) {
349760
349897
  const cfg = { ...defaultInputs1732, ...inputs };
@@ -350259,12 +350396,48 @@ function sourceOf10(name, b) {
350259
350396
  return b.volume ?? NaN;
350260
350397
  }
350261
350398
  }
350262
- function pushLimited(list, value, limit, push2 = true) {
350263
- if (list.length > limit)
350264
- list.shift();
350265
- if (push2)
350266
- list.push(value);
350267
- }
350399
+ var MedianList = class {
350400
+ constructor(limit) {
350401
+ this.limit = limit;
350402
+ }
350403
+ list = [];
350404
+ sorted = [];
350405
+ /** First position whose value sorts after x (`after`) or not before x */
350406
+ position(x, after) {
350407
+ let lo = 0;
350408
+ let hi = this.sorted.length;
350409
+ while (lo < hi) {
350410
+ const mid = lo + hi >> 1;
350411
+ const d12 = this.sorted[mid] - x;
350412
+ if (after ? !(d12 > 0) : d12 < 0)
350413
+ lo = mid + 1;
350414
+ else
350415
+ hi = mid;
350416
+ }
350417
+ return lo;
350418
+ }
350419
+ /** Remove the first element when the size is above the limit, then push */
350420
+ pushLimited(value, push2 = true) {
350421
+ if (this.list.length > this.limit) {
350422
+ const first = this.list.shift();
350423
+ if (!Number.isNaN(first))
350424
+ this.sorted.splice(this.position(first, false), 1);
350425
+ }
350426
+ if (!push2)
350427
+ return;
350428
+ this.list.push(value);
350429
+ if (!Number.isNaN(value))
350430
+ this.sorted.splice(this.position(value, true), 0, value);
350431
+ }
350432
+ /** array.median: the middle value, or the mean of the two middle values for an even count; na without values */
350433
+ median() {
350434
+ const sorted = this.sorted;
350435
+ if (!sorted.length)
350436
+ return NaN;
350437
+ const mid = Math.floor(sorted.length / 2);
350438
+ return sorted.length % 2 === 0 ? (sorted[mid - 1] + sorted[mid]) / 2 : sorted[mid];
350439
+ }
350440
+ };
350268
350441
  function calculate1734(bars, inputs = {}, chart) {
350269
350442
  const cfg = { ...defaultInputs1734, ...inputs };
350270
350443
  const n = bars.length;
@@ -350301,8 +350474,8 @@ function calculate1734(bars, inputs = {}, chart) {
350301
350474
  basis = import_oakscriptjs1697.ta.wma(src, len);
350302
350475
  }
350303
350476
  const fair = basis.toArray().map(nan);
350304
- const devUpList = [];
350305
- const devDownList = [];
350477
+ const devUpList = new MedianList(1e3);
350478
+ const devDownList = new MedianList(1e3);
350306
350479
  const upperBand = new Array(n);
350307
350480
  const lowerBand = new Array(n);
350308
350481
  const upperBoosted = new Array(n);
@@ -350313,10 +350486,10 @@ function calculate1734(bars, inputs = {}, chart) {
350313
350486
  const b = bars[i];
350314
350487
  const f = fair[i];
350315
350488
  const inside = lt881(b.low, f) && gt1077(b.high, f);
350316
- pushLimited(devUpList, inside ? b.high / f : NaN, 1e3);
350317
- pushLimited(devDownList, inside ? b.low / f : NaN, 1e3);
350318
- upperBand[i] = f * import_oakscriptjs1697.array.median(devUpList);
350319
- lowerBand[i] = f * import_oakscriptjs1697.array.median(devDownList);
350489
+ devUpList.pushLimited(inside ? b.high / f : NaN);
350490
+ devDownList.pushLimited(inside ? b.low / f : NaN);
350491
+ upperBand[i] = f * devUpList.median();
350492
+ lowerBand[i] = f * devDownList.median();
350320
350493
  upperBoosted[i] = f + (upperBand[i] - f) * cfg.boost;
350321
350494
  lowerBoosted[i] = f - (f - lowerBand[i]) * cfg.boost;
350322
350495
  const prev = i > 0 ? fair[i - 1] : NaN;
@@ -350331,8 +350504,8 @@ function calculate1734(bars, inputs = {}, chart) {
350331
350504
  const spread = import_oakscriptjs1697.Series.fromArray(bars, bars.map((b, i) => (b.open + b.high + b.low + b.close) / 4 / fair[i]));
350332
350505
  const pivotUp = import_oakscriptjs1697.ta.pivothigh(spread, 5, 5).toArray().map(nan);
350333
350506
  const pivotDown = import_oakscriptjs1697.ta.pivotlow(spread, 5, 5).toArray().map(nan);
350334
- const pivotUps = [];
350335
- const pivotDowns = [];
350507
+ const pivotUps = new MedianList(2e3);
350508
+ const pivotDowns = new MedianList(2e3);
350336
350509
  const band1Up = new Array(n);
350337
350510
  const band1Down = new Array(n);
350338
350511
  const band2Up = new Array(n);
@@ -350344,10 +350517,10 @@ function calculate1734(bars, inputs = {}, chart) {
350344
350517
  const f = fair[i];
350345
350518
  const pushUp = gt1077(b.low, upperBand[i]);
350346
350519
  const pushDown = !pushUp && lt881(b.high, lowerBand[i]);
350347
- pushLimited(pivotUps, pivotUp[i], 2e3, pushUp);
350348
- pushLimited(pivotDowns, pivotDown[i], 2e3, pushDown);
350349
- const upSpread = (f * import_oakscriptjs1697.array.median(pivotUps) - f) * cfg.bandBoost;
350350
- const downSpread = (f - f * import_oakscriptjs1697.array.median(pivotDowns)) * cfg.bandBoost;
350520
+ pivotUps.pushLimited(pivotUp[i], pushUp);
350521
+ pivotDowns.pushLimited(pivotDown[i], pushDown);
350522
+ const upSpread = (f * pivotUps.median() - f) * cfg.bandBoost;
350523
+ const downSpread = (f - f * pivotDowns.median()) * cfg.bandBoost;
350351
350524
  band1Up[i] = f + upSpread;
350352
350525
  band1Down[i] = f - downSpread;
350353
350526
  band2Up[i] = band1Up[i] + upSpread;
@@ -361058,6 +361231,7 @@ var MAROON31 = "#880E4F";
361058
361231
  var BLUE98 = "#2962FF";
361059
361232
  var BLACK63 = "#363A45";
361060
361233
  var WHITE78 = "#FFFFFF";
361234
+ var PROJECTION_BG = new Map([GREEN147, LIME77, YELLOW42, RED200, ORANGE41].map((c4) => [c4, String(import_oakscriptjs1728.color.new(c4, 70))]));
361061
361235
  var plotConfig1766 = [
361062
361236
  { id: "plot0", title: "Plot", color: BLUE98, lineWidth: 1, style: "linebr" },
361063
361237
  { id: "plot1", title: "Higher High Range", color: String(import_oakscriptjs1728.color.new(GREEN147, 100)), lineWidth: 1 },
@@ -361223,6 +361397,16 @@ function calculate1766(bars, inputs = {}, chart) {
361223
361397
  let tableMade = false;
361224
361398
  const zigzagLines = [];
361225
361399
  const zigzagLabels = [];
361400
+ const projectionTexts = /* @__PURE__ */ new Map();
361401
+ const projectionLabel = (x, y, colour, style, texts) => {
361402
+ const lb = import_oakscriptjs1728.label.new(x, y, "", "bar_index", "price", PROJECTION_BG.get(colour), style, WHITE78, "small");
361403
+ projectionTexts.set(lb, texts);
361404
+ return lb;
361405
+ };
361406
+ const deleteProjection = (lb) => {
361407
+ import_oakscriptjs1728.label.delete(lb);
361408
+ projectionTexts.delete(lb);
361409
+ };
361226
361410
  const stPlot = new Array(n).fill(NaN);
361227
361411
  const stDirPlot = new Array(n).fill(NaN);
361228
361412
  const hh = new Array(n).fill(NaN);
@@ -361395,7 +361579,7 @@ function calculate1766(bars, inputs = {}, chart) {
361395
361579
  import_oakscriptjs1728.line.delete(v.value);
361396
361580
  for (const v of [hhLabel, lhLabel, htLabel])
361397
361581
  if (v.value)
361398
- import_oakscriptjs1728.label.delete(v.value);
361582
+ deleteProjection(v.value);
361399
361583
  const x1 = Math.sign(currentDir) < 0 ? currentBar : lastBar;
361400
361584
  const hhX2 = x1 + hhBars;
361401
361585
  const lhX2 = x1 + lhBars;
@@ -361408,58 +361592,28 @@ function calculate1766(bars, inputs = {}, chart) {
361408
361592
  hhLine.value = import_oakscriptjs1728.line.new(x1, y12, hhX2, hhY2, "bar_index", void 0, GREEN147, "arrow_right");
361409
361593
  lhLine.value = import_oakscriptjs1728.line.new(x1, y12, lhX2, lhY2, "bar_index", void 0, LIME77, "arrow_right");
361410
361594
  htLine.value = import_oakscriptjs1728.line.new(x1, y12, tX2, tY2, "bar_index", void 0, YELLOW42, "arrow_right");
361411
- const hhPercent = import_oakscriptjs1728.str.tostring(hhStats * 100 / tStats, "percent");
361412
- const lhPercent = import_oakscriptjs1728.str.tostring(lhStats * 100 / tStats, "percent");
361413
- const hhText = `Number of Historical References :${import_oakscriptjs1728.str.tostring(hhStats)}/${import_oakscriptjs1728.str.tostring(tStats)}
361414
- Probability of Higher High :${hhPercent}
361595
+ const hhPercent = () => import_oakscriptjs1728.str.tostring(hhStats * 100 / tStats, "percent");
361596
+ const lhPercent = () => import_oakscriptjs1728.str.tostring(lhStats * 100 / tStats, "percent");
361597
+ hhLabel.value = projectionLabel(hhX2, hhY2, GREEN147, "label_lower_left", () => [
361598
+ `${import_oakscriptjs1728.str.tostring(hhY2)} - ${hhPercent()}`,
361599
+ `Number of Historical References :${import_oakscriptjs1728.str.tostring(hhStats)}/${import_oakscriptjs1728.str.tostring(tStats)}
361600
+ Probability of Higher High :${hhPercent()}
361415
361601
  Average Higher High Ratio :${import_oakscriptjs1728.str.tostring(hhRatio)}
361416
- Average Higher High Bars :${import_oakscriptjs1728.str.tostring(hhBars)}`;
361417
- const lhText = `Number of Historical References :${import_oakscriptjs1728.str.tostring(lhStats)}/${import_oakscriptjs1728.str.tostring(tStats)}
361418
- Probability of Lower High :${lhPercent}
361602
+ Average Higher High Bars :${import_oakscriptjs1728.str.tostring(hhBars)}`
361603
+ ]);
361604
+ lhLabel.value = projectionLabel(lhX2, lhY2, LIME77, "label_upper_left", () => [
361605
+ `${import_oakscriptjs1728.str.tostring(lhY2)} - ${lhPercent()}`,
361606
+ `Number of Historical References :${import_oakscriptjs1728.str.tostring(lhStats)}/${import_oakscriptjs1728.str.tostring(tStats)}
361607
+ Probability of Lower High :${lhPercent()}
361419
361608
  Average Lower High Ratio :${import_oakscriptjs1728.str.tostring(lhRatio)}
361420
- Average Lower High Bars :${import_oakscriptjs1728.str.tostring(lhBars)}`;
361421
- const tText = `Number of Historical References :${import_oakscriptjs1728.str.tostring(tStats)}
361422
- Average Fib Ratio :${import_oakscriptjs1728.str.tostring(tRatio)}
361423
- Average Bars :${import_oakscriptjs1728.str.tostring(tBars)}`;
361424
- hhLabel.value = import_oakscriptjs1728.label.new(
361425
- hhX2,
361426
- hhY2,
361427
- `${import_oakscriptjs1728.str.tostring(hhY2)} - ${hhPercent}`,
361428
- "bar_index",
361429
- "price",
361430
- String(import_oakscriptjs1728.color.new(GREEN147, 70)),
361431
- "label_lower_left",
361432
- WHITE78,
361433
- "small",
361434
- void 0,
361435
- hhText
361436
- );
361437
- lhLabel.value = import_oakscriptjs1728.label.new(
361438
- lhX2,
361439
- lhY2,
361440
- `${import_oakscriptjs1728.str.tostring(lhY2)} - ${lhPercent}`,
361441
- "bar_index",
361442
- "price",
361443
- String(import_oakscriptjs1728.color.new(LIME77, 70)),
361444
- "label_upper_left",
361445
- WHITE78,
361446
- "small",
361447
- void 0,
361448
- lhText
361449
- );
361450
- htLabel.value = import_oakscriptjs1728.label.new(
361451
- tX2,
361452
- tY2,
361609
+ Average Lower High Bars :${import_oakscriptjs1728.str.tostring(lhBars)}`
361610
+ ]);
361611
+ htLabel.value = projectionLabel(tX2, tY2, YELLOW42, "label_left", () => [
361453
361612
  `${import_oakscriptjs1728.str.tostring(tY2)}@${import_oakscriptjs1728.str.tostring(tRatio)}`,
361454
- "bar_index",
361455
- "price",
361456
- String(import_oakscriptjs1728.color.new(YELLOW42, 70)),
361457
- "label_left",
361458
- WHITE78,
361459
- "small",
361460
- void 0,
361461
- tText
361462
- );
361613
+ `Number of Historical References :${import_oakscriptjs1728.str.tostring(tStats)}
361614
+ Average Fib Ratio :${import_oakscriptjs1728.str.tostring(tRatio)}
361615
+ Average Bars :${import_oakscriptjs1728.str.tostring(tBars)}`
361616
+ ]);
361463
361617
  hhValue = hhY2;
361464
361618
  lhValue = lhY2;
361465
361619
  hhProbability = hhStats * 100 / tStats;
@@ -361526,7 +361680,7 @@ Average Bars - ${import_oakscriptjs1728.str.tostring(tBars)}`
361526
361680
  import_oakscriptjs1728.line.delete(v.value);
361527
361681
  for (const v of [llLabel, hlLabel, ltLabel])
361528
361682
  if (v.value)
361529
- import_oakscriptjs1728.label.delete(v.value);
361683
+ deleteProjection(v.value);
361530
361684
  const x1 = Math.sign(currentDir) > 0 ? currentBar : lastBar;
361531
361685
  const llX2 = x1 + llBars;
361532
361686
  const hlX2 = x1 + hlBars;
@@ -361539,58 +361693,28 @@ Average Bars - ${import_oakscriptjs1728.str.tostring(tBars)}`
361539
361693
  llLine.value = import_oakscriptjs1728.line.new(x1, y12, llX2, llY2, "bar_index", void 0, RED200, "arrow_right");
361540
361694
  hlLine.value = import_oakscriptjs1728.line.new(x1, y12, hlX2, hlY2, "bar_index", void 0, ORANGE41, "arrow_right");
361541
361695
  ltLine.value = import_oakscriptjs1728.line.new(x1, y12, tX2, tY2, "bar_index", void 0, YELLOW42, "arrow_right");
361542
- const llPercent = import_oakscriptjs1728.str.tostring(llStats * 100 / tStats, "percent");
361543
- const hlPercent = import_oakscriptjs1728.str.tostring(hlStats * 100 / tStats, "percent");
361544
- const llText = `Number of Historical References :${import_oakscriptjs1728.str.tostring(llStats)}/${import_oakscriptjs1728.str.tostring(tStats)}
361545
- Probability of Lower Low :${llPercent}
361696
+ const llPercent = () => import_oakscriptjs1728.str.tostring(llStats * 100 / tStats, "percent");
361697
+ const hlPercent = () => import_oakscriptjs1728.str.tostring(hlStats * 100 / tStats, "percent");
361698
+ llLabel.value = projectionLabel(llX2, llY2, RED200, "label_upper_left", () => [
361699
+ `${import_oakscriptjs1728.str.tostring(llY2)} - ${llPercent()}`,
361700
+ `Number of Historical References :${import_oakscriptjs1728.str.tostring(llStats)}/${import_oakscriptjs1728.str.tostring(tStats)}
361701
+ Probability of Lower Low :${llPercent()}
361546
361702
  Average Lower Low Ratio :${import_oakscriptjs1728.str.tostring(llRatio)}
361547
- Average Lower Low Bars :${import_oakscriptjs1728.str.tostring(llBars)}`;
361548
- const hlText = `Number of Historical References :${import_oakscriptjs1728.str.tostring(hlStats)}/${import_oakscriptjs1728.str.tostring(tStats)}
361549
- Probability of Higher Low :${hlPercent}
361703
+ Average Lower Low Bars :${import_oakscriptjs1728.str.tostring(llBars)}`
361704
+ ]);
361705
+ hlLabel.value = projectionLabel(hlX2, hlY2, ORANGE41, "label_lower_left", () => [
361706
+ `${import_oakscriptjs1728.str.tostring(hlY2)} - ${hlPercent()}`,
361707
+ `Number of Historical References :${import_oakscriptjs1728.str.tostring(hlStats)}/${import_oakscriptjs1728.str.tostring(tStats)}
361708
+ Probability of Higher Low :${hlPercent()}
361550
361709
  Average Higher Low Ratio :${import_oakscriptjs1728.str.tostring(hlRatio)}
361551
- Average Higher Low Bars :${import_oakscriptjs1728.str.tostring(hlBars)}`;
361552
- const tText = `Number of Historical References :${import_oakscriptjs1728.str.tostring(tStats)}
361553
- Average Fib Ratio :${import_oakscriptjs1728.str.tostring(tRatio)}
361554
- Average Bars :${import_oakscriptjs1728.str.tostring(tBars)}`;
361555
- llLabel.value = import_oakscriptjs1728.label.new(
361556
- llX2,
361557
- llY2,
361558
- `${import_oakscriptjs1728.str.tostring(llY2)} - ${llPercent}`,
361559
- "bar_index",
361560
- "price",
361561
- String(import_oakscriptjs1728.color.new(RED200, 70)),
361562
- "label_upper_left",
361563
- WHITE78,
361564
- "small",
361565
- void 0,
361566
- llText
361567
- );
361568
- hlLabel.value = import_oakscriptjs1728.label.new(
361569
- hlX2,
361570
- hlY2,
361571
- `${import_oakscriptjs1728.str.tostring(hlY2)} - ${hlPercent}`,
361572
- "bar_index",
361573
- "price",
361574
- String(import_oakscriptjs1728.color.new(ORANGE41, 70)),
361575
- "label_lower_left",
361576
- WHITE78,
361577
- "small",
361578
- void 0,
361579
- hlText
361580
- );
361581
- ltLabel.value = import_oakscriptjs1728.label.new(
361582
- tX2,
361583
- tY2,
361710
+ Average Higher Low Bars :${import_oakscriptjs1728.str.tostring(hlBars)}`
361711
+ ]);
361712
+ ltLabel.value = projectionLabel(tX2, tY2, YELLOW42, "label_left", () => [
361584
361713
  `${import_oakscriptjs1728.str.tostring(tY2)}@${import_oakscriptjs1728.str.tostring(tRatio)}`,
361585
- "bar_index",
361586
- "price",
361587
- String(import_oakscriptjs1728.color.new(YELLOW42, 70)),
361588
- "label_left",
361589
- WHITE78,
361590
- "small",
361591
- void 0,
361592
- tText
361593
- );
361714
+ `Number of Historical References :${import_oakscriptjs1728.str.tostring(tStats)}
361715
+ Average Fib Ratio :${import_oakscriptjs1728.str.tostring(tRatio)}
361716
+ Average Bars :${import_oakscriptjs1728.str.tostring(tBars)}`
361717
+ ]);
361594
361718
  llValue = llY2;
361595
361719
  hlValue = hlY2;
361596
361720
  llProbability = llStats * 100 / tStats;
@@ -361700,6 +361824,11 @@ Average Bars - ${import_oakscriptjs1728.str.tostring(tBars)}`
361700
361824
  llProb[i] = llProbability;
361701
361825
  }
361702
361826
  (0, import_oakscriptjs1728.setDrawingBar)(null);
361827
+ for (const [lb, texts] of projectionTexts) {
361828
+ const [text, tooltip] = texts();
361829
+ import_oakscriptjs1728.label.set_text(lb, text);
361830
+ import_oakscriptjs1728.label.set_tooltip(lb, tooltip);
361831
+ }
361703
361832
  const fin26 = (v) => Number.isFinite(v) ? v : NaN;
361704
361833
  const P2 = (vals, show, colorOf3) => bars.map((bar, i) => ({ time: bar.time, value: show ? fin26(vals[i]) : NaN, ...colorOf3 ? { color: colorOf3(i) } : {} }));
361705
361834
  const probColour = (p, above2, below2) => String(import_oakscriptjs1728.color.new(gt1099(p, 50) ? above2 : lt899(p, 50) ? below2 : SILVER23, 90));
@@ -377243,6 +377372,8 @@ var metadata1808 = {
377243
377372
  };
377244
377373
  var usesVisibleRange8 = true;
377245
377374
  var LIMITS5 = { box: 50, label: 50, line: 144, polyline: 50 };
377375
+ var LAST_DRAWING_BARS = 7;
377376
+ var MAX_BARS_BACK8 = 1e4;
377246
377377
  var EPS1132 = 1e-10;
377247
377378
  var ge540 = (a, b) => !isNaN(a) && !isNaN(b) && !(b - a > EPS1132);
377248
377379
  var le390 = (a, b) => !isNaN(a) && !isNaN(b) && !(a - b > EPS1132);
@@ -377261,6 +377392,17 @@ function calculate1808(bars, inputs = {}, chart) {
377261
377392
  const cperc = [cfg.curve1, cfg.curve2, cfg.curve3, cfg.curve4, cfg.curve5, cfg.curve6];
377262
377393
  const ccol = [cfg.curveCol1, cfg.curveCol2, cfg.curveCol3, cfg.curveCol4, cfg.curveCol5, cfg.curveCol6];
377263
377394
  const acol = cfg.angleCol;
377395
+ const boxBg = c4.map((col2) => String(import_oakscriptjs1769.color.new(col2, 50)));
377396
+ const boxBorder = c4.map((col2) => String(import_oakscriptjs1769.color.new(col2, 80)));
377397
+ const labelText2 = ["0", ...perc.map((p) => import_oakscriptjs1769.str.tostring(p)), "1"];
377398
+ if (cfg.reverse)
377399
+ labelText2.reverse();
377400
+ const curveSin = [];
377401
+ const curveCos = [];
377402
+ for (let j = 0; j <= 90; j++) {
377403
+ curveSin.push(import_oakscriptjs1769.math.sin(import_oakscriptjs1769.math.toradians(j)));
377404
+ curveCos.push(import_oakscriptjs1769.math.cos(import_oakscriptjs1769.math.toradians(j)));
377405
+ }
377264
377406
  (0, import_oakscriptjs1769.resetDrawings)(LIMITS5);
377265
377407
  let hi = NaN;
377266
377408
  let lo = NaN;
@@ -377276,11 +377418,21 @@ function calculate1808(bars, inputs = {}, chart) {
377276
377418
  import_oakscriptjs1769.line.delete(l);
377277
377419
  };
377278
377420
  const levels3 = [0, 1, 2, 3, 4, 5].map(() => new Array(n).fill(NaN));
377421
+ const isVisible = (i) => {
377422
+ const t = bars[i].time * toMs;
377423
+ return t >= range7.leftTime && t <= range7.rightTime;
377424
+ };
377425
+ let drawFrom = cfg.showAngles ? 0 : n;
377426
+ for (let i = n - 1, count = 0; !cfg.showAngles && i >= 0 && count < LAST_DRAWING_BARS; i--) {
377427
+ if (isVisible(i)) {
377428
+ drawFrom = i;
377429
+ count++;
377430
+ }
377431
+ }
377279
377432
  for (let i = 0; i < n; i++) {
377280
377433
  (0, import_oakscriptjs1769.setDrawingBar)(i, i === n - 1);
377281
377434
  const b = bars[i];
377282
- const t = b.time * toMs;
377283
- const visible2 = t >= range7.leftTime && t <= range7.rightTime;
377435
+ const visible2 = isVisible(i);
377284
377436
  if (visible2 && ge540(b.high, isNaN(hi) ? b.high : hi)) {
377285
377437
  hi = b.high;
377286
377438
  hLoc = i;
@@ -377304,7 +377456,8 @@ function calculate1808(bars, inputs = {}, chart) {
377304
377456
  y.push(y6);
377305
377457
  for (let k = 0; k <= 5; k++)
377306
377458
  levels3[k][i] = x[k];
377307
- if (cfg.showBox && visible2) {
377459
+ const draw = visible2 && (i >= drawFrom || i - Math.min(...x) > MAX_BARS_BACK8);
377460
+ if (cfg.showBox && draw) {
377308
377461
  for (const bx of boxes)
377309
377462
  import_oakscriptjs1769.box.delete(bx);
377310
377463
  boxes = [];
@@ -377318,22 +377471,20 @@ function calculate1808(bars, inputs = {}, chart) {
377318
377471
  y[z + 1],
377319
377472
  right2,
377320
377473
  y[z],
377321
- String(import_oakscriptjs1769.color.new(c4[z], 50)),
377474
+ boxBg[z],
377322
377475
  void 0,
377323
377476
  void 0,
377324
377477
  void 0,
377325
377478
  void 0,
377326
- String(import_oakscriptjs1769.color.new(c4[z], 80))
377479
+ boxBorder[z]
377327
377480
  );
377328
377481
  boxes.unshift(bx);
377329
377482
  }
377330
377483
  }
377331
377484
  }
377332
377485
  }
377333
- if (cfg.showLabel && visible2) {
377334
- const s = ["0", ...perc.map((p) => import_oakscriptjs1769.str.tostring(p)), "1"];
377335
- if (cfg.reverse)
377336
- s.reverse();
377486
+ if (cfg.showLabel && draw) {
377487
+ const s = labelText2;
377337
377488
  for (let k = 0; k <= 6; k++) {
377338
377489
  const xx = x[k];
377339
377490
  for (let z = 0; z <= 6; z++) {
@@ -377363,7 +377514,7 @@ function calculate1808(bars, inputs = {}, chart) {
377363
377514
  }
377364
377515
  }
377365
377516
  }
377366
- if (cfg.showFan && visible2) {
377517
+ if (cfg.showFan && draw) {
377367
377518
  for (let k = 0; k <= 5; k++) {
377368
377519
  if (fperc[k]) {
377369
377520
  const l1 = import_oakscriptjs1769.line.new(x0, y0, x[k + 1], y6, "bar_index", void 0, fcol[k]);
@@ -377375,13 +377526,13 @@ function calculate1808(bars, inputs = {}, chart) {
377375
377526
  }
377376
377527
  }
377377
377528
  }
377378
- if (cfg.showCurve && visible2) {
377529
+ if (cfg.showCurve && draw) {
377379
377530
  for (let k = 1; k <= arr5.length - 1; k++) {
377380
377531
  if (cperc[k - 1]) {
377381
377532
  const points = [];
377382
377533
  for (let j = 0; j <= 90; j++) {
377383
- const xx = x0 - (x0 - x[k]) * import_oakscriptjs1769.math.sin(import_oakscriptjs1769.math.toradians(j));
377384
- const yy = y0 + import_oakscriptjs1769.math.cos(import_oakscriptjs1769.math.toradians(j)) * (y[k] - y0);
377534
+ const xx = x0 - (x0 - x[k]) * curveSin[j];
377535
+ const yy = y0 + curveCos[j] * (y[k] - y0);
377385
377536
  points.push(import_oakscriptjs1769.chartPoint.from_index(import_oakscriptjs1769.math.round(xx), yy));
377386
377537
  }
377387
377538
  const poly2 = import_oakscriptjs1769.polyline.new(points, false, false, "bar_index", ccol[k - 1]);
@@ -377392,7 +377543,7 @@ function calculate1808(bars, inputs = {}, chart) {
377392
377543
  }
377393
377544
  }
377394
377545
  }
377395
- if (cfg.showAngles && visible2) {
377546
+ if (cfg.showAngles && draw) {
377396
377547
  for (let k = 0; k <= 6; k++) {
377397
377548
  const xx = x[k];
377398
377549
  const yy = y[k];
@@ -407961,4 +408112,4 @@ var registryPart12 = [
407961
408112
  }
407962
408113
  ];
407963
408114
  var indicatorRegistry = [...registryPart1, ...registryPart11, ...registryPart2, ...registryPart3, ...registryPart4, ...registryPart5, ...registryPart6, ...registryPart7, ...registryPart8, ...registryPart9, ...registryPart10, ...registryPart12].map(withReferenceNames).map(withValueFormat).map(withStyleOutputs).map(withAlertConditions);
407964
- var version = "0.19.0";
408115
+ var version = "0.19.2";