Skip to content

Pattern Texture Codex

🌵 Market Texture Context

The Pattern Texture Codex (PTC) is the TradingView Suite’s market-texture component: a complexity gauge that reads how price moves, rather than how far or how fast. It implements permutation entropy , a measure from dynamical-systems theory that quantifies whether price evolves in ordered, repeating patterns or in chaotic noise.

Standard technical analysis works in two dimensions: amplitude (how far price moves) and momentum (how fast). The Pattern Texture Codex adds a third — structure (how price moves). We call this reading market texture: Smooth texture (low entropy) marks ordered conditions where trends tend to be durable, whilst Rough texture (high entropy) marks chaotic conditions where moves are fragile.

WaveTrend 4D Other Signal Providers External Indicators Pattern Texture Codex Flux Composer Market Regime Detector Kinetic Trend Envelope Order Orchestrator

Hover over components to see details. Lines indicate data flow between components.

A smooth uptrend and a choppy consolidation can share identical volatility yet have entirely different texture. Volatility measures the size of moves; texture measures their order. Permutation entropy captures this by analysing the sequence of price movements — the temporal micro-structure — not their distribution or magnitude.

The indicator maps every market moment onto a scale from 0 to 1:

🫧 Smooth Texture — Low Entropy

Price evolves in ordered, repeating patterns. Causality is high, trends are durable, and momentum approaches are favoured.

🌵 Rough Texture — High Entropy

Price evolves chaotically. The market is noisy, trends are fragile, and mean reversion or defensive sizing deserves priority.

Neutral Zone

Entropy sits between the two thresholds — typical market behaviour with no strong claim about structure in either direction.

Because the measure is built from rank orderings rather than raw values, it is scale-invariant — the same reading is comparable across instruments, timeframes, and price levels. That property is also the source of the indicator’s most important limitation, discussed honestly below.

Instead of analysing raw prices, permutation entropy converts each window of consecutive data points into an ordinal pattern — the relative ordering of those points. With embedding dimension D = 3 (three points per pattern), there are 3! = 6 possible patterns:

PatternOrderingShape
012first < second < thirdAscending
210first > second > thirdDescending
102Middle value smallestValley
Remaining threeMixed orderingsPeaks and partial rises or falls

The indicator slides this window across the chart, counts how often each pattern appears over the lookback, and computes the Shannon entropy of that frequency distribution:

H = − Σ p(π) · ln p(π) / ln(D!)

where p(π) is the observed probability of each ordinal pattern π, and dividing by ln(D!) normalises the result to the range 0–1:

  • H → 0: one pattern dominates — highly structured, predictable sequencing.
  • H → 1: all patterns are equally likely — indistinguishable from randomness.

The intuition is direct. In a clean uptrend, the ascending pattern keeps recurring and entropy falls. In choppy consolidation, every pattern appears in roughly equal measure and entropy climbs towards 1.

  1. Encode each window of D points (spaced by the configured delay) as an ordinal pattern.
  2. Count pattern frequencies over the last N patterns in a sliding window.
  3. Compute the Shannon entropy of the frequency distribution.
  4. Normalise by ln(D!) so the output always lives in the 0–1 range.
  5. Smooth optionally with a 2-pole Ultimate Smoother, clipped back to 0–1.
  6. Classify the result against the Smooth and Rough thresholds into a ternary texture state.

Many indicators on TradingView carry the word “entropy” whilst measuring something else: Shannon entropy of price histograms (which captures value distribution but ignores temporal sequence), approximate entropy (which measures amplitude similarity at quadratic computational cost), or volatility metrics rebranded with entropy terminology. The Pattern Texture Codex provides true ordinal-pattern analysis — the sequence of movements, with a mathematically valid probability distribution underneath.

Computing each pattern from scratch requires sorting every embedding window. The Pattern Texture Codex instead exploits a structural insight from Unakafova and Keller (2013): successive ordinal patterns in overlapping windows share D − 1 data points, so the new pattern can be derived from the previous one with a single lookup in a precomputed transition table. This reduces the per-bar cost to O(D) work — at most 2D − 2 comparisons — via precomputed transition tables.

The tables come from the open-source PatternTransitionTables library, published as part of the GYTS open-source foundation:

  • Enabled by default for Delay 1 and Dimension 3, 4, or 5.
  • Dimension 2 and 6 fall back automatically to the standard from-scratch calculation.

The settings panel moves from data source through the entropy engine, threshold logic, visual styling, and alerts. Start with the defaults, then adjust one group at a time.

SettingDefaultNotes
SourceclosePrice series analysed for ordinal patterns.
Smoothing critical period0Range 0–1000. Smooths the entropy line with a 2-pole Ultimate Smoother to reveal the underlying texture; 0 disables smoothing.

Raw entropy can be jittery bar to bar. A modest smoothing period (for example 20–50) often clarifies the texture reading without materially delaying transitions; the smoothed value is clipped back into the 0–1 range so overshoot cannot produce impossible readings.

SettingDefaultNotes
Dimension4Range 2–6. Points per ordinal pattern — the embedding dimension D.
Pattern Window (N)100Range 10–10000. Number of patterns used for entropy estimation. Hard minimum: D × 5.
Delay1Range 1–10. Stride between the points in each pattern (the embedding delay τ).
Lookup accelerationtrueUses precomputed transition tables; active for Dimension 3–5 with Delay 1.

Choosing the dimension. Each value of D trades sensitivity against statistical appetite:

DimensionPossible patternsCharacter
22Binary up/down only — minimal, no lookup acceleration.
36Fast and stable; good when history is limited.
424Balanced; captures V-shaped reversals. Recommended default.
5120Sensitive; captures W- and M-shaped patterns, but noisier.
6720Maximum sensitivity; no lookup acceleration and may be slow.

Sizing the window. The indicator enforces a hard minimum of D × 5 patterns and refuses to run below it, because entropy estimates from tiny samples are meaningless. The academic recommendation is stricter still: 5 × D! patterns (120 for D = 4, 600 for D = 5). Shorter windows above the hard minimum work in practice but reduce statistical reliability. Note that patterns overlap, so the total bars consumed is N + (D − 1) × Delay — for D = 4 with N = 100 and Delay 1, that is 103 bars.

Delay. The default of 1 suits nearly all financial series; increase it only for oversampled or otherwise exotic data.

Smooth and Rough detection are configured independently — each side has its own mode, and mixing modes is deliberate design, not a workaround. Four modes are available per side:

  • Static — a fixed threshold value you define.
  • Dynamic — adaptive bands built from an entropy baseline (2-pole Super Smoother) plus or minus a standard-deviation multiple.
  • Percentile — the threshold sits at the Nth percentile of recent entropy history.
  • Disabled — no detection for that side.
SettingDefaultNotes
🌵 Rough Threshold ModeDisabledMode for the upper (Rough) threshold.
🫧 Smooth Threshold ModeDynamicMode for the lower (Smooth) threshold.
🌵 Rough Value (Static)0.9Range 0.1–1.0. Entropy above this value flags Rough texture (Static mode only).
🫧 Smooth Value (Static)0.7Range 0.0–0.9. Entropy below this value flags Smooth texture (Static mode only).
🌵 Std Dev Multiplier (Rough)2.0Range 0.5–5.0. Band width above the baseline (Dynamic mode).
🫧 Std Dev Multiplier (Smooth)2.0Range 0.5–5.0. Band width below the baseline (Dynamic mode).
Baseline Length (Dynamic)1000Period of the Super Smoother baseline for dynamic thresholds.
Std Dev Length (Dynamic)1000Lookback for the standard-deviation estimate of the dynamic bands.
Percentile Lookback1000Range 20–10000. History used for percentile thresholds.
🌵 Rough Percentile90Range 50–100. For example 90 flags only the top 10% of entropy readings.
🫧 Smooth Percentile10Range 0–50. For example 10 flags only the bottom 10%.

Mode-specific settings are only active when their mode is selected — the panel greys out the rest, so an ignored input is never silently misleading. Dynamic thresholds are capped so the Rough band never exceeds 1.0 and the Smooth band never drops below 0.0.

SettingDefaultNotes
PaletteGYTS PurpleColour scheme for the entropy line and texture fills.
Colouring barstruePaints chart candles with the detected texture colour.
Dark ModetrueAdjusts colour intensity for dark chart backgrounds.
Line Transparency0Range 0–100. Transparency of the entropy line.
Fill Transparency25Range 0–100. Transparency of the texture-zone fills at their strongest.
Indicator Name(empty)Custom on-chart label, useful when running several instances with different settings (for example “D=3, N=100” versus “D=5, N=500”).
Repeat Name Every N Bars300Range 0–10000. Repeats the label through history; 0 shows it only on the most recent bar.

The entropy line is coloured by percentile rank over recent history, so the full palette is always in use: warm tones for high entropy (Rough), cool tones for low entropy (Smooth). Zone fills intensify as entropy pushes deeper past a threshold — a faint fill means a marginal breach, a strong fill means conviction.

SettingDefaultNotes
Alert: Texture → RoughtrueFires when texture transitions into Rough.
Alert: Texture → SmoothtrueFires when texture transitions into Smooth.

Alerts trigger on confirmed bar close, on the transition into a texture state rather than on every bar within it. Two routes exist when creating the alert in TradingView:

  • “Any alert() function call” — webhook-friendly messages carrying the ticker, timeframe, entropy value, active threshold, and threshold mode.
  • “Texture → Rough” / “Texture → Smooth” — simpler dedicated conditions selectable individually in TradingView’s Create Alert dialog.

The Pattern Texture Codex exports two hidden data streams. They do not clutter the chart, but any indicator on the same chart — GYTS or your own — can select them as an input source.

Stream titleMeaningValues
🔗 STREAM PTC 🌵 Entropy (continuous)Normalised permutation entropyFloat, 0–1
🔗 STREAM PTC 🌵 Entropy (ternary)Texture state+1 Rough, 0 Neutral, −1 Smooth

The continuous stream can feed the Flux Composer as a signal or filter input through its threshold-based signal processing:

  1. Add both the Pattern Texture Codex and the Flux Composer to the same chart.
  2. In the Flux Composer’s settings, select 🔗 STREAM PTC 🌵 Entropy (continuous) as an external input source.
  3. Define the threshold condition that turns entropy into a contribution — for example, treat readings below your smooth threshold as trend confirmation, or readings above your rough threshold as a veto on new signals.
  4. Where a discrete filter is all you need, the ternary stream provides the classification directly, with no threshold configuration on the Flux Composer side.

The Market Regime Detector and the Pattern Texture Codex answer different questions, and the distinction matters:

  • The Market Regime Detector classifies what the market is doing: trending bullish, trending bearish, or cycling.
  • The Pattern Texture Codex classifies how orderly it is doing it: structured or chaotic.

A trending regime with Rough texture is a fragile trend; a cyclic regime with Smooth texture is an orderly oscillation. Use the ternary stream as a complexity filter alongside — not instead of — the regime context. The two readings together give a far more complete picture than either alone.

The four core applications, in increasing order of subtlety:

  • Trend filtering — only take trend-following entries whilst texture is Smooth; structure is the precondition for momentum to persist.
  • Mean-reversion timing — elevated entropy often precedes mean reversion; Rough texture marks the conditions where fading extremes has the better odds.
  • Position-sizing context — reduce exposure during Rough texture; chaotic sequencing degrades the reliability of any directional thesis.
  • Exit management — when entropy rises whilst a position is open, the trend is losing coherence; tightening stops before the reversal is visible in price is exactly the edge a texture reading offers.

For interpretation, the absolute level carries meaning as well as the threshold crossings: readings below roughly 0.6 indicate strong pattern dominance, the 0.7–0.9 band is typical market behaviour, and values above 0.95 are effectively indistinguishable from randomness. Transitions matter most — entropy rising sharply after a prolonged smooth period is an early warning that the trend is losing structure, whilst entropy falling from elevated levels suggests a new trend may be establishing.

The GYTS Signal Sentinel’s first live strategy, Pattern Texture Codex Ignition, builds on exactly this playbook and is delivered in the GYTS Discord.

Window-length guidance. Shorter pattern windows react faster but estimate less reliably: 50–100 suits intraday regime detection, 100–200 is a balanced swing-trading range, and 200–500 provides stability for position trading or noisy instruments. The default of 100 sits at the responsive end of the balanced swing range; raise it towards 200–500 for greater stability on noisy instruments or longer horizons.

The Pattern Texture Codex measures exactly one thing — ordinal structure — and it is worth being precise about what that excludes:

  • Amplitude blindness. Permutation entropy treats all patterns equally regardless of magnitude. A 0.1% drift and a 10% crash produce identical entropy if their ordinal patterns match. This is the flip side of scale invariance: deliberate, but it means texture must never be your only risk input.
  • Equal values (ties). Ties are resolved by temporal tie-breaking (more recent values rank higher). This is a principled convention, but heavily discretised data — instruments with very coarse tick sizes — may produce edge-case behaviour.
  • Sample-size requirements. Entropy estimates from short windows are unreliable. The indicator enforces a hard minimum of D × 5 patterns and will refuse to run below it, but statistical comfort genuinely begins around 5 × D!.
  • Not predictive alone. Low entropy indicates that structure exists, not that the trend will continue. Texture is a condition filter; combine it with directional analysis before trading on it.
  • Lag during transitions. The sliding window means the entropy reading is always a blend of recent history. When texture changes abruptly, the indicator needs time to reflect it — inherent to the method, not a tuning defect.

🚀 Coming Soon The Professional Edition is in development along two axes that address the honest limitations above: amplitude-aware entropy variants, which weigh patterns by the magnitude of the moves that form them, and statistical-significance filtering, which distinguishes genuine structure from sampling noise. Details will be published when the edition is released; the Community Edition remains fully open source and methodologically complete in its own right.

The entropy line does not appear on the left of the chart

  • The window must accumulate a minimum number of patterns before the estimate is valid; the output is deliberately na during ramp-up.
  • Total bars consumed is N + (D − 1) × Delay — on instruments with short history, reduce Pattern Window (N) or Dimension.

The indicator raises a configuration error

  • Pattern Window (N) is below the hard minimum of Dimension × 5. The error message states the required value; either increase the window or reduce the dimension.

Ready to Master Algorithmic Trading?

Join many traders using GYTS to refine their edge.

Choose Your Path

The Pattern Texture Codex stands on published research and GYTS open-source libraries.

SourceReference
Bandt & PompeC. Bandt and B. Pompe, “Permutation Entropy: A Natural Complexity Measure for Time Series”, 2002, Physical Review Letters (DOI)
Unakafova & KellerV. Unakafova and K. Keller, “Efficiently Measuring Complexity on the Basis of Real-World Data”, 2013, Entropy (DOI)
PatternTransitionTablesGYTS PatternTransitionTables Library — open-source precomputed ordinal-pattern transition tables (TradingView)
FiltersToolkitGYTS FiltersToolkit Library — Ultimate Smoother and Super Smoother filters (documentation)