PulseHub
OPEN-SOURCE SCRIPT
Updated

Moving Average Structure Matrix

249
Moving Average Structure Matrix is not a basic multi-MA ribbon.

The moving-average lines are only the visible base layer. The main contribution is a neutral MA structure layer that quantifies how the enabled moving averages are ordered, clustered, twisting, and positioned relative to the selected source.

This script is designed for traders who want quick structural context from multiple EMA/SMA lines without relying only on visual inspection. It is a context and visualization tool only. It does not provide trade-action instructions and it is not a trading system.

What it shows

- Up to 8 user-configurable EMA/SMA slots.
- A moving-average ensemble centerline.
- The high and low boundary of the enabled MA group.
- Optional fill between the MA bundle boundaries.
- A compact context table.
- Optional factual event labels.
- Neutral alert conditions for structure changes.

The MA lines are useful visually, but the structure layer is the main feature.

Core structure fields

Pairwise Stack Score

The script compares enabled moving averages pair by pair.

For each pair with different lengths, the shorter-length MA is treated as the faster MA and the longer-length MA as the slower MA.

If the faster MA is meaningfully above the slower MA, the pair contributes positively.
If the faster MA is meaningfully below the slower MA, the pair contributes negatively.
If the pair is too close to classify, it contributes as tied.

The Stack Score summarizes this pairwise ordering on an approximate -100 to +100 scale.

A positive Stack Score means shorter MAs are generally above longer MAs.
A negative Stack Score means shorter MAs are generally below longer MAs.
A value near zero means the group is mixed or tied.

Order Purity

Order Purity measures how much of the eligible pairwise structure agrees with the dominant side.

For example, a high positive Stack Score with high Order Purity describes a cleaner upward ordering of shorter and longer averages. A mixed pair structure will usually show lower purity.

Order Purity is descriptive only. It is not a forecast or a trade instruction.

Tie Ratio

Tie Ratio measures how many eligible MA pairs are too close to classify after applying the stack-separation threshold.

A higher Tie Ratio means more of the MA group is structurally tied or compressed into similar values.

Slope Consensus

Slope Consensus measures how many enabled moving averages are rising, falling, or flat over the selected slope lookback.

Each enabled MA receives a slope sign:

- rising
- falling
- flat

The Slope Score summarizes the group on an approximate -100 to +100 scale.

Bundle Width and Width Rank

The script calculates the high and low values of the enabled MA group.

Bundle Width measures the distance between those two boundaries.

Bundle Width % expresses that distance relative to the MA centroid.

Width Rank compares the current bundle width with its own recent history. This is a moving-average bundle context only. It is not a volatility regime and it does not forecast future movement.

Width context can read as:

- Clustered
- Middle width
- Wide bundle
- n/a

Twist Rate

Twist Rate describes internal reordering of the MA group.

For each eligible fast/slow pair, the script compares the current pair relationship with the previous bar's relationship. When a pair changes from one ordered side to the other, it counts as a twist.

Twist Rate summarizes how much internal crossing or reordering has occurred over the selected lookback.

This helps distinguish a clean MA structure from a churning or mixed MA group.

Fast/Slow Cohort Spread

The script can compare shorter-length and longer-length MA groups.

The fast cohort contains shorter MAs.
The slow cohort contains longer MAs.

Cohort Spread % compares the average position of the fast cohort with the average position of the slow cohort.

This gives a second view of the structure beyond individual pair comparisons.

Source-vs-Bundle location

The selected source can be:

- Above bundle
- Inside bundle
- Below bundle
- n/a

The script also calculates Bundle Position %, which describes where the source sits relative to the current MA bundle.

Values can be below 0 or above 100 when the source is outside the bundle.

Structure State

The script combines stack ordering, order purity, slope consensus, bundle width context, twist rate, and source location into a neutral state label.

Possible states include:

- Need 2+ MAs
- Need different MA lengths
- Warming up
- Ordered upward
- Ordered downward
- Upward stack / mixed slopes
- Downward stack / mixed slopes
- Churning bundle
- Clustered mixed bundle
- Flat bundle
- Transitioning upward
- Transitioning downward
- Intermixed

These states describe the current MA structure. They do not imply continuation or reversal.

Structure Age

Structure Age counts how long the current structure state has persisted.

The script uses distinct internal state IDs, so the age resets when the actual structure state changes, not just when broad direction changes.

Structure Fingerprint

The Fingerprint is a compact summary of the current MA structure.

Example:

O+ S+ Wm Pa A34

Meaning:

- O+ means positive stack polarity.
- O- means negative stack polarity.
- O0 means no clear stack polarity.
- S+ means positive slope consensus.
- S- means negative slope consensus.
- S0 means no clear slope consensus.
- Wc means clustered width.
- Wm means middle width.
- Ww means wide bundle.
- Wn means width unavailable.
- Pa means source above the bundle.
- Pi means source inside the bundle.
- Pb means source below the bundle.
- Pn means source location unavailable.
- A shows the current structure age.

The Fingerprint is a compact context summary. It is not a trade instruction.

Structure Footprint

The Footprint expands the context by combining:

- Structure age
- Previous state age
- Width motion
- Twist Rate
- Order Purity
- Tie Ratio

This helps users read how the MA group is currently organized without relying only on line spacing.

Context table

The default context table is compact and placed in the upper-right area.

Compact layout shows:

- State
- Fingerprint
- Stack Score
- Slope Score
- Width / Twist
- Price location
- Structure Age

Standard and Detailed layouts add more research fields, including:

- Footprint
- Order Purity
- Tie Ratio
- Twist Rate
- Cohort Spread
- Bundle Width %
- Width Rank
- Bundle Position %
- Enabled MA count
- Eligible pairs
- Equal-length pairs skipped
- Up / Down / Tied pair counts
- Fast / Slow cohort counts
- Centroid
- Bundle high
- Bundle low
- Active warm-up bars
- State ID
- Enabled MA names

Research fields are available in the Detailed context table without adding extra chart plots. The context table is the primary research surface.

Events and labels

Event labels are optional and off by default.

When enabled, labels are factual and neutral. They describe events such as:

- structure became ordered upward
- structure became ordered downward
- structure became intermixed
- bundle entered churning context
- bundle entered clustered width context
- bundle left clustered width context
- source moved above the MA bundle
- source moved below the MA bundle
- source crossed the MA centroid

Event markers use capped labels rather than plotshape markers, so the script stays within PulseWire's plot-count limit. Older labels are removed after the user-defined label cap is reached.

Alerts

The script includes factual alert conditions for the same structure events.

Alerts respect the selected confirmed-bar behavior by default. Intrabar mode is available, but realtime values can update until the bar closes.

Customization

Users can adjust:

- source
- slope lookback
- warm-up behavior
- EMA/SMA type for each MA slot
- length for each MA slot
- color, width, transparency, and name for each MA slot
- stack separation threshold
- ordered stack threshold
- order purity threshold
- slope flat threshold
- slope consensus threshold
- width-rank lookback
- clustered / wide width thresholds
- twist lookback
- churning twist threshold
- cohort split length
- automatic cohort split
- event persistence
- event cooldown
- context table layout
- context table position
- table text size
- table colors
- marker colors
- envelope colors
- fill transparency

Visual customization does not affect calculations.

Most input values are hidden from the chart status line by default to keep the chart label compact. All inputs remain available in the Settings / Inputs tab.

Different from other tools

This script does not use ATR channels, session shading, volatility-regime classification, VWAP, volume weighting, or RSI slope divergence.

It focuses only on the geometry of an enabled EMA/SMA ensemble.

Limitations

Moving averages lag by design.

A clean MA structure does not guarantee continuation.

A churning MA structure does not imply reversal.

MA order can persist, unwind, or flip.

Default lengths are common visual reference points, not optimized settings.

Width and cluster context are descriptive of the enabled MA group and its own history.

Changing enabled MAs, lengths, or thresholds changes the structure readings.

This script is not financial advice and not a trading system.

Japanese notes

このスクリプトは単なる複数移動平均線ではなく、EMA/SMA群の並び、純度、近接度、傾きの一致、束の広がり、ねじれ、価格位置、状態の継続時間を構造として表示する可視化ツールです。売買判断や将来予測ではなく、MA群の現在の構造を把握するための補助として設計しています。
Release Notes
This update expands the script from a static moving-average structure display into a research framework for observing MA alignment, lifecycle phases, higher-timeframe context, and historical regime behavior.

- Added a weighted structure engine that evaluates order coherence, order purity, tie ratio, reorder rate, slope breadth, slope energy, slope coherence, bundle width, cohort spread, and overall structure clarity.

- Separated directional bias from lifecycle phase. Bias is classified as Bullish, Bearish, or Neutral. Lifecycle phases are classified as Compression, Release, Expansion, Pullback, Deceleration, or Churn / Transition.

- Added chart, anchor, and macro timeframe comparison using confirmed higher-timeframe values. The MTF context distinguishes full alignment, aligned pullbacks, countertrend conditions, mixed structures, and pending higher-timeframe confirmation.

- Added Short Horizon, Balanced Trend, Long Horizon, Investor, and Custom presets. Presets are general reference configurations and are not optimized settings.

- Added manual horizon ranking and support for EMA, SMA, WMA, RMA, HMA, DEMA, TEMA, VWMA, ALMA, and KAMA calculations.

- Added ATR, percentage, and rolling standard-deviation normalization modes for comparing MA distances and slopes across different symbols and price scales.

- Added structure memory for completed regime episodes. The research output includes sample count, duration distribution, current age percentile, persistence frequency, and commonly observed next-phase transitions.

- Added an event outcome study for Compression Release, Pullback Reclaim, Structural Failure, MTF Alignment, and Expansion Entry. Available statistics include completed sample count, median forward return, interquartile range, positive-outcome frequency, confidence interval, median maximum favorable excursion, and median maximum adverse excursion.

- Reworked the chart display around fast and slow MA cohorts, an ensemble centerline, an optional full bundle envelope, and optional individual MA plots.

- Added lifecycle-aware ribbon coloring and optional background tinting while keeping visual settings separate from the underlying structure calculations.

- Replaced the previous context table with a compact fixed bottom-left HUD. The HUD displays bias, lifecycle phase, structure clarity, MTF context, chart / anchor / macro states, confirmation status, and the most recent structural event.

- Increased HUD text size, applied bold formatting, added status icons and visual meters, and added configurable clearance above the PulseWire logo.

- Simplified chart markers to reduce overlap with candles and MA plots. Structural Failure and MTF Alignment notices are no longer drawn over price. They remain available in the fixed HUD, alerts, and research calculations.

- Marker visibility remains configurable for Compression Release, Pullback Reclaim, First Bundle Touch, Expansion, Compression, and Churn / Transition events.

- Added neutral alert conditions for the main lifecycle, interaction, structural-failure, and MTF-alignment events. Event evaluation can be restricted to confirmed bar closes.

- Updated the source header to the Mozilla Public License 2.0 format and retained the ©SG Group attribution.

All statistics are descriptive and depend on the selected symbol, timeframe, settings, and available chart history. The script does not issue buy or sell recommendations.

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by PulseWire. Read more in the Terms of Use.