Historical Precedent Engine [HPE]WHAT IT DOES
HPE takes the last few candles on your chart, searches that chart's own history for
earlier sequences that resemble them, and shows you what price did after those earlier
sequences. It is an analog study. The output is a summary of precedent, not a forecast.
TUNING IS NOT OPTIONAL — READ THIS FIRST
This is a matcher, and a matcher only speaks when it finds something. Every enabled
filter is a hard gate applied to every candle in the fingerprint, and the gates compound:
a sequence qualifies only if candle 1 passes wick, body and volume, and candle 2 passes
all three, and so on, and the sequence momentum passes, and the direction rule passes.
Tighten two of those and the survivor count does not halve, it collapses.
So the normal failure mode is an empty dashboard. Median outcome, tolerance band, delta
and range all read "—", Bias reads Neutral, and Matches Used reads 0. That is not a bug
and it is not the tool being broken. It means nothing in this chart's history was close
enough to the present under the settings you have. The honest answer for that bar is
silence, and the tool gives it.
The tolerance units
Wick and body are measured as a percentage of the candle's own high-to-low range, not of
price. An upper wick occupying a fifth of its candle scores 20, whether that candle is a
one-minute Bitcoin bar or a daily equity bar. A tolerance of 12 therefore means "within
12 percentage points of range", and it means the same thing on every instrument and every
timeframe.
That is deliberate. Measured against price instead, the same tolerance would need to be
roughly a hundred times larger on a daily equity chart than on a one-minute crypto chart,
and no single default could serve both — one setting would accept everything on one chart
and nothing on the other.
On Auto-Tune, which ships OFF
Auto-Tune moves the wick and body tolerances based on how well recent projections
resolved. It ships disabled, for two measured reasons.
It cannot start from nothing. It does not act until at least five projections have been
scored, so if your tolerances are too tight to ever produce a match, there are no
projections, nothing is scored, and it never moves. It is a regulator, not a starter
motor.
And once it does start, it tends not to stop. It can only travel between a quarter and
four times your input, and when widening fails to improve fit — which is the usual case
if the matches were poor to begin with — it widens every bar until it pins at four times
your input and stays there. On the test chart it did exactly that, and the difference it
made was 50 resolved projections instead of 49. It bought one projection out of fifty
while making the number in the settings box a fiction.
So it is off, and what you type is what runs. Turn it on if you want it, knowing both of
the above.
The order to loosen in, most effective first:
1. Strict Direction off. With it on, every candle must match direction, which is a
1-in-2^N filter before any tolerance is applied. This is the single biggest lever.
2. Shorten Sequence Length. Fewer candles means fewer conjunctive conditions. Three is
the minimum and is the default for that reason.
3. Raise Wick and Body Tolerance, in the units described above.
4. Turn off Require Per-Candle Volume Match and Require Momentum Match. Volume ratios in
particular are noisy on short timeframes and reject a lot for little gain.
5. Lower Min Matches Required. It ships at 2 rather than 3 because on the instrument
these defaults were measured on, 3 never fires. Read the last paragraph of this
description before you take that as a recommendation.
Where the defaults came from
They were measured with a full 1,000-sequence library on three charts chosen to be as
unalike as possible, and they were picked to make the engine speak at all rather than to
make it look good:
COINBASE:BTCUSD 1-minute 73 projections over 25,837 bars
COINBASE:BTCUSD 1-hour 33 projections over 22,764 bars
AMEX:SPY daily 29 projections over 8,436 bars
That is between one bar in 290 and one bar in 690 — the same order of magnitude across a
crypto intraday chart and an equity daily chart, with no per-instrument tuning. It should
still be quiet, and you should still retune for your own instrument and horizon, but the
defaults are a measured starting point rather than a guess.
One note on reading the dashboard while you do that. The calibration row shows total
projections alongside how many sit in the calibration window, and that window is capped by
Calibration window (samples) — 50 by default. Watch the total, not the window. The window
fills early and then stops moving, which makes a well-tuned setup and a barely-working one
look identical.
ON LIBRARY SIZE
Max Stored Sequences is the pool the matcher searches, and a bigger pool is the one way
to get more matches without making each match mean less. It is capped at 1,000 by default
for a practical reason: raising it substantially can push the script past PulseWire's
calculation limit, at which point it stops reporting entirely. If you raise it and the
indicator goes blank rather than merely empty, that is what happened. Put it back. This
cap is also the real ceiling on how often the engine can fire at a tolerance tight enough
to be meaningful, and it is worth knowing that before you go hunting for settings.
HOW IT WORKS
1. Fingerprint. On every confirmed bar, the last N candles are reduced to a five-field
vector per candle: upper wick, lower wick, body, direction, and volume measured
against its own moving average.
2. Store. That fingerprint is written to a rolling library along with what price did over
the following bars.
3. Match. The current fingerprint is compared against every stored sequence. A stored
sequence qualifies only if each candle falls inside the wick, body and volume
tolerances, and only if the sequence momentum falls inside its tolerance. Direction
matching is separate: with Strict Direction on, every candle must match direction;
with it off, only the final candle must. An optional session filter restricts matches
to the same trading session.
4. Summarise. Qualifying matches are ranked by how well their own past projections
resolved, and the strongest are combined into a single percentile outcome — the median
by default. If fewer than Min Matches Required qualify, nothing is drawn.
5. Calibrate. Once the horizon elapses, each projection is scored against what actually
happened. That score weights how much a stored sequence counts in future matches, and
feeds Auto-Tune if you have enabled it.
READING THE CHART
Projection line and band — the percentile outcome of the current match set, extended to
the horizon.
Consensus paths — the individual paths of the top matches, drawn separately, so you can
see the spread the single summary line came from. A tight cluster and a wide scatter
produce the same median.
Rolling projection trail — past projections left on the chart beside what price actually
did. This is deliberate. A tool that hides its misses is not worth reading.
Dashboard — match count, median outcome, ±1σ range, session, library size, live
tolerances, and the calibration block. The projection values — median outcome, tolerance
band, delta, range, bias, match count and best-match error — are cleared at the start of
every confirmed bar, so those rows always show that bar's answer and never a leftover
from an earlier bar that happened to match. The library and calibration counters are
cumulative by design and do not clear.
The same state is also published to the Data Window as plain numbers, which is easier to
read than canvas text while you are tuning.
ON THE CALIBRATION NUMBERS
The dashboard reports mean projection error, not accuracy.
It is the average distance between projection and outcome, expressed as a share of the
size of the move that actually occurred, measured over the most recent resolved
projections on the chart you are looking at. It is computed in-sample, on bars the engine
had already stored, and it is not a forward result.
It is there so you can tell whether your tolerances are set sensibly. It is not evidence
that the tool works, and it should not be read as a hit rate. Because the actual move is
the denominator, the figure also moves with volatility regime rather than with skill
alone — quiet bars punish it, large moves flatter it.
ON REPAINTING
Two specific claims, both checkable in the source:
There are no request.security() calls anywhere in this script. Every value is computed
from the chart's own bars, so there is no higher-timeframe lookahead question to get
wrong in the first place.
Every drawing and every dashboard write sits inside a single barstate.isconfirmed gate.
Nothing is created, moved or deleted while the live bar is still forming.
A projection does extend to bars that have not happened yet. It does not move once drawn.
It is simply right or wrong, and the trail is there so you can see which.
SETTINGS WORTH KNOWING
Sequence Length — how many candles form the fingerprint. Longer is stricter and finds
fewer matches, and the effect is multiplicative rather than linear.
Min Matches Required — below this count nothing is drawn.
Delta Percentile — 50 is the median. Move it to read the pessimistic or optimistic tail
of the same match set rather than its centre.
Auto-Tune Tolerances — off by default; see above before enabling.
Strict Direction — the difference between "these candles had the same shape" and "these
candles had the same shape and went the same way."
WHAT THIS IS NOT
This is a visualization and analysis tool, not a trading system. It does not produce
advice. Nothing here is a signal to enter or exit a position, and no performance is
claimed or implied. Markets change regime, and any tool built on historical structure
will fail when they do. Use it as context alongside your own analysis.
One more thing worth saying plainly, and it is the honest counterweight to the tuning
advice above: a small sample of matches is a small sample. Two historical analogs tell
you very little, and the engine will draw a line from two just as readily as from thirty.
Min Matches ships at 2 because that is what it took to get the engine to speak on the
instrument it was measured on — which is a statement about how hard analogs are to find
in a 1,000-sequence library, not a claim that two is enough to believe. Loosening the
filters until something appears is easy, and it is exactly how you end up reading noise.
Watch the match count before you read the line, and treat a projection drawn from a
handful of precedents as the weak evidence it is.
Indicator

Khabib Takedown Fractal Nest Breakdown ViprasolKhabib Takedown — Fractal Nest Breakdown 🤼
CONCEPT
This tool looks for SELF-SIMILARITY in a decline: a big bearish leg (lower high -> lower low)
with a smaller bearish leg nested inside it that is a scaled copy — same shape, a fraction of
the size. When the small "fractal" completes in the direction of the big one (a break of the
last low), the structure grounds price -> SHORT. It is a fractal-echo measurement, not a plain
lower-low. The nesting ratio between the small leg and the big leg is the core filter.
HOW IT DETECTS
- Swings are found with confirmed pivot highs/lows (left/right bar lookback) and chained into a
lightweight zigzag.
- The tool reads the last four alternating swings (high, low, high, low).
- Big leg = first high minus first low; small leg = second high minus second low.
- A valid nest requires: lower high and lower low (bearish structure); big leg >= (Min big x ATR);
small leg positive; and the nesting ratio (small/big) inside the band .
- The signal fires when price closes below the most recent swing low and the bar closes red.
- ATR (Wilder) scales the minimum big-leg size across instruments and timeframes.
ENTRY / STOP / TARGET
- Entry: SHORT on the close of the confirming (red) bar that breaks the last low.
- Stop: above the second (inner) swing high plus an ATR buffer (default 0.3 x ATR).
- Target: entry minus R multiple x risk (default 2R, where risk = stop distance).
- The script draws the big leg and the nested small leg, plus filled TP and SL zones that extend
to the right until price touches one of them.
NON-REPAINTING
Pivots are only used once fully confirmed (they require the right-side bars), and the signal is
evaluated on bar close (barstate.isconfirmed). Drawings are created on the confirmed bar. The tool
does not repaint completed signals. Live, the forming bar can still change until it closes, as with
any bar-close tool.
FEATURES
- Fractal nesting (scaled self-similar legs), not a plain lower-low break.
- ATR-scaled minimum big-leg requirement and adjustable nesting-ratio band.
- Automatic R-multiple TP and ATR-buffered SL, drawn as zones that extend until hit.
- One-trade-at-a-time option and a minimum-bars-between-signals gap to reduce clustering.
- On-chart status table (open trades) and an alertcondition for automation.
INPUTS OVERVIEW
- Swing pivot left/right bars: swing sensitivity.
- Nesting ratio band (ratLo/ratHi): how close in scale the small leg must be to the big leg.
- Min big leg (x ATR) and ATR length: minimum move and volatility scaling.
- TP R multiple, SL buffer (x ATR), min bars between signals, one-trade-at-a-time.
- Visual colors, label offset, and zone transparency.
HOW TO USE
1. Add to any liquid symbol and timeframe; start with defaults.
2. Tighten the nesting-ratio band for stricter self-similarity, or widen it for more signals.
3. Raise Min big leg (x ATR) to demand larger, cleaner declines before a nest counts.
4. Use the drawn TP/SL zones for context; set an alert on the signal for hands-off monitoring.
5. Combine with your own trend/context read before acting.
LIMITATIONS
- This is a pattern/education tool, not a signal service, and not financial advice.
- Breakdown patterns fail; nesting geometry is a filter, not a guarantee. Losing signals will occur.
- Pivot confirmation adds inherent lag (it needs bars to the right of a swing to confirm).
- Very choppy or illiquid markets can produce misshapen legs and weak signals.
- Requires user discretion, risk management, and position sizing. No performance is implied.
CREDITS
The name is an inspirational sports homage only; it does not imply any endorsement or affiliation.
ATR uses Wilder's average true range. Pivot/zigzag swing detection uses standard public techniques.
The fractal-nest (scaled self-similar leg) geometry, the detection assembly, and the trade/zone
visualization are original Viprasol work.
Original Viprasol work; no third-party Pine code reused.
Indicator

Indicator

Multi Asset Similarity MatrixProvides a unique and visually stunning way to analyze the similarity between various stock market indices. This script uses a range of mathematical measures to calculate the correlation between different assets, such as indices, forex, crypto, etc..
Key Features:
Similarity Measures: The script offers a range of similarity measures to choose from, including SSD (Sum of Squared Differences), Euclidean Distance, Manhattan Distance, Minkowski Distance, Chebyshev Distance, Correlation Coefficient, Cosine Similarity, Camberra Index, Mean Absolute Error (MAE), Mean Squared Error (MSE), Lorentzian Function, Intersection, and Penrose Shape.
Asset Selection: Users can select the assets they want to analyze by entering a comma-separated list of tickers in the "Asset List" input field.
Color Gradient: The script uses a color gradient to represent the similarity values between each pair of indices, with red indicating low similarity and blue indicating high similarity.
How it Works:
The script calculates the source method (Returns or Volume Modified Returns) for each index using the sec function.
It then creates a matrix to hold the current values of each index over a specified window size (default is 10).
For each pair of indices, it applies the selected similarity measure using the select function and stores the result in a separate matrix.
The script calculates the maximum and minimum values of the similarity matrix to normalize the color gradient.
Finally, it creates a table with the index names as rows and columns, displaying the similarity values for each pair of indices using the calculated colors.
Visual Insights:
The indicator provides an intuitive way to visualize the relationships between different assets. By analyzing the color-coded tables, traders can gain insights into:
Which assets are highly correlated (blue) or uncorrelated (red)
The strength and direction of these correlations
Potential trading opportunities based on similarities and differences between assets
Overall, MASM is a powerful tool for market analysis and visualization, offering a unique perspective on the relationships between various assets.
~llama3 Indicator

Indicator

SimilarityMeasuresLibrary "SimilarityMeasures"
Similarity measures are statistical methods used to quantify the distance between different data sets
or strings. There are various types of similarity measures, including those that compare:
- data points (SSD, Euclidean, Manhattan, Minkowski, Chebyshev, Correlation, Cosine, Camberra, MAE, MSE, Lorentzian, Intersection, Penrose Shape, Meehl),
- strings (Edit(Levenshtein), Lee, Hamming, Jaro),
- probability distributions (Mahalanobis, Fidelity, Bhattacharyya, Hellinger),
- sets (Kumar Hassebrook, Jaccard, Sorensen, Chi Square).
---
These measures are used in various fields such as data analysis, machine learning, and pattern recognition. They
help to compare and analyze similarities and differences between different data sets or strings, which
can be useful for making predictions, classifications, and decisions.
---
References:
en.wikipedia.org
cran.r-project.org
numerics.mathdotnet.com
github.com
github.com
github.com
Encyclopedia of Distances, doi.org
ssd(p, q)
Sum of squared difference for N dimensions.
Parameters:
p (float ) : `array` Vector with first numeric distribution.
q (float ) : `array` Vector with second numeric distribution.
Returns: Measure of distance that calculates the squared euclidean distance.
euclidean(p, q)
Euclidean distance for N dimensions.
Parameters:
p (float ) : `array` Vector with first numeric distribution.
q (float ) : `array` Vector with second numeric distribution.
Returns: Measure of distance that calculates the straight-line (or Euclidean).
manhattan(p, q)
Manhattan distance for N dimensions.
Parameters:
p (float ) : `array` Vector with first numeric distribution.
q (float ) : `array` Vector with second numeric distribution.
Returns: Measure of absolute differences between both points.
minkowski(p, q, p_value)
Minkowsky Distance for N dimensions.
Parameters:
p (float ) : `array` Vector with first numeric distribution.
q (float ) : `array` Vector with second numeric distribution.
p_value (float) : `float` P value, default=1.0(1: manhatan, 2: euclidean), does not support chebychev.
Returns: Measure of similarity in the normed vector space.
chebyshev(p, q)
Chebyshev distance for N dimensions.
Parameters:
p (float ) : `array` Vector with first numeric distribution.
q (float ) : `array` Vector with second numeric distribution.
Returns: Measure of maximum absolute difference.
correlation(p, q)
Correlation distance for N dimensions.
Parameters:
p (float ) : `array` Vector with first numeric distribution.
q (float ) : `array` Vector with second numeric distribution.
Returns: Measure of maximum absolute difference.
cosine(p, q)
Cosine distance between provided vectors.
Parameters:
p (float ) : `array` 1D Vector.
q (float ) : `array` 1D Vector.
Returns: The Cosine distance between vectors `p` and `q`.
---
angiogenesis.dkfz.de
camberra(p, q)
Camberra distance for N dimensions.
Parameters:
p (float ) : `array` Vector with first numeric distribution.
q (float ) : `array` Vector with second numeric distribution.
Returns: Weighted measure of absolute differences between both points.
mae(p, q)
Mean absolute error is a normalized version of the sum of absolute difference (manhattan).
Parameters:
p (float ) : `array` Vector with first numeric distribution.
q (float ) : `array` Vector with second numeric distribution.
Returns: Mean absolute error of vectors `p` and `q`.
mse(p, q)
Mean squared error is a normalized version of the sum of squared difference.
Parameters:
p (float ) : `array` Vector with first numeric distribution.
q (float ) : `array` Vector with second numeric distribution.
Returns: Mean squared error of vectors `p` and `q`.
lorentzian(p, q)
Lorentzian distance between provided vectors.
Parameters:
p (float ) : `array` Vector with first numeric distribution.
q (float ) : `array` Vector with second numeric distribution.
Returns: Lorentzian distance of vectors `p` and `q`.
---
angiogenesis.dkfz.de
intersection(p, q)
Intersection distance between provided vectors.
Parameters:
p (float ) : `array` Vector with first numeric distribution.
q (float ) : `array` Vector with second numeric distribution.
Returns: Intersection distance of vectors `p` and `q`.
---
angiogenesis.dkfz.de
penrose(p, q)
Penrose Shape distance between provided vectors.
Parameters:
p (float ) : `array` Vector with first numeric distribution.
q (float ) : `array` Vector with second numeric distribution.
Returns: Penrose shape distance of vectors `p` and `q`.
---
angiogenesis.dkfz.de
meehl(p, q)
Meehl distance between provided vectors.
Parameters:
p (float ) : `array` Vector with first numeric distribution.
q (float ) : `array` Vector with second numeric distribution.
Returns: Meehl distance of vectors `p` and `q`.
---
angiogenesis.dkfz.de
edit(x, y)
Edit (aka Levenshtein) distance for indexed strings.
Parameters:
x (int ) : `array` Indexed array.
y (int ) : `array` Indexed array.
Returns: Number of deletions, insertions, or substitutions required to transform source string into target string.
---
generated description:
The Edit distance is a measure of similarity used to compare two strings. It is defined as the minimum number of
operations (insertions, deletions, or substitutions) required to transform one string into another. The operations
are performed on the characters of the strings, and the cost of each operation depends on the specific algorithm
used.
The Edit distance is widely used in various applications such as spell checking, text similarity, and machine
translation. It can also be used for other purposes like finding the closest match between two strings or
identifying the common prefixes or suffixes between them.
---
github.com
www.red-gate.com
planetcalc.com
lee(x, y, dsize)
Distance between two indexed strings of equal length.
Parameters:
x (int ) : `array` Indexed array.
y (int ) : `array` Indexed array.
dsize (int) : `int` Dictionary size.
Returns: Distance between two strings by accounting for dictionary size.
---
www.johndcook.com
hamming(x, y)
Distance between two indexed strings of equal length.
Parameters:
x (int ) : `array` Indexed array.
y (int ) : `array` Indexed array.
Returns: Length of different components on both sequences.
---
en.wikipedia.org
jaro(x, y)
Distance between two indexed strings.
Parameters:
x (int ) : `array` Indexed array.
y (int ) : `array` Indexed array.
Returns: Measure of two strings' similarity: the higher the value, the more similar the strings are.
The score is normalized such that `0` equates to no similarities and `1` is an exact match.
---
rosettacode.org
mahalanobis(p, q, VI)
Mahalanobis distance between two vectors with population inverse covariance matrix.
Parameters:
p (float ) : `array` 1D Vector.
q (float ) : `array` 1D Vector.
VI (matrix) : `matrix` Inverse of the covariance matrix.
Returns: The mahalanobis distance between vectors `p` and `q`.
---
people.revoledu.com
stat.ethz.ch
docs.scipy.org
fidelity(p, q)
Fidelity distance between provided vectors.
Parameters:
p (float ) : `array` 1D Vector.
q (float ) : `array` 1D Vector.
Returns: The Bhattacharyya Coefficient between vectors `p` and `q`.
---
en.wikipedia.org
bhattacharyya(p, q)
Bhattacharyya distance between provided vectors.
Parameters:
p (float ) : `array` 1D Vector.
q (float ) : `array` 1D Vector.
Returns: The Bhattacharyya distance between vectors `p` and `q`.
---
en.wikipedia.org
hellinger(p, q)
Hellinger distance between provided vectors.
Parameters:
p (float ) : `array` 1D Vector.
q (float ) : `array` 1D Vector.
Returns: The hellinger distance between vectors `p` and `q`.
---
en.wikipedia.org
jamesmccaffrey.wordpress.com
kumar_hassebrook(p, q)
Kumar Hassebrook distance between provided vectors.
Parameters:
p (float ) : `array` 1D Vector.
q (float ) : `array` 1D Vector.
Returns: The Kumar Hassebrook distance between vectors `p` and `q`.
---
github.com
jaccard(p, q)
Jaccard distance between provided vectors.
Parameters:
p (float ) : `array` 1D Vector.
q (float ) : `array` 1D Vector.
Returns: The Jaccard distance between vectors `p` and `q`.
---
github.com
sorensen(p, q)
Sorensen distance between provided vectors.
Parameters:
p (float ) : `array` 1D Vector.
q (float ) : `array` 1D Vector.
Returns: The Sorensen distance between vectors `p` and `q`.
---
people.revoledu.com
chi_square(p, q, eps)
Chi Square distance between provided vectors.
Parameters:
p (float ) : `array` 1D Vector.
q (float ) : `array` 1D Vector.
eps (float)
Returns: The Chi Square distance between vectors `p` and `q`.
---
uw.pressbooks.pub
stats.stackexchange.com
www.itl.nist.gov
kulczynsky(p, q, eps)
Kulczynsky distance between provided vectors.
Parameters:
p (float ) : `array` 1D Vector.
q (float ) : `array` 1D Vector.
eps (float)
Returns: The Kulczynsky distance between vectors `p` and `q`.
---
github.com Library

Indicator

Library

Indicator
