OPEN-SOURCE SCRIPT

AetherEdge - Hierarchical Temporal Memory Inspired

272
🖊️ Overview

A sequence-memory engine inspired by HTM (Hierarchical Temporal Memory), a model of how the neocortex learns sequences. Fundamentally different from KNN similarity-search or LSTM weighted regression, HTM stores knowledge as a sparse columnar memory and learns which column tends to follow which. Each bar's market state is encoded into a Sparse Distributed Representation (SDR) where only a few of many columns activate. A transition memory (permanence weights between columns) learns the sequence "column A → column B," and every new bar the engine predicts which columns should activate next. When an unpredicted column fires instead, that is an anomalous transition — a break in the learned temporal pattern. The mismatch is the anomaly score, and its inverse is sequence stability. Visualization: a faint vertical line only on high-anomaly bars, plus a single Sequence Stability indicator.

🔶 Key Features

HTM-style sequence memory — brain-inspired columnar memory learns temporal patterns (fundamentally unlike KNN/LSTM)
SDR (sparse distributed representation) — encodes each bar into a few active columns
Transition learning — Hebbian strengthening/decay of inter-column permanence stores sequences
Predictive cells — predicts next-bar columns from learned transitions (higher-order capable)
Anomalous-transition detection — scores the firing of unpredicted columns as anomaly
Anomaly-bar emphasis — a faint vertical line only on bars whose anomaly clears the gate (noise excluded)
Sequence Stability — a single lower-pane stability readout (green stable → red anomalous gradient)
Intelligence panel — anomaly score, stability, an active-SDR visualization, predicted/hit counts, and learned-link count

🧠 Technical Architecture

The engine encodes the market state into four features (momentum, RSI deviation, volatility, position-within-range, all normalized) and turns them into an SDR. Each column has a fixed random receptive field (a spatial-pooler proxy); the top activeCols columns by overlap with the current state win and fire (k-winners-take-all). Similar states thus activate similar column sets, different states different ones.
The transition memory is a permanence matrix perm[a→b]. Learning follows the Hebbian rule: if column A fired and B fired on the next bar, the link A→B is strengthened (permanence +permInc); links whose predictions failed decay (−permDec). Only links above the connection threshold can predict.
For prediction, from the recently-fired columns (both t-1 and t-2 for higher order) the engine follows connected links to build the set of columns expected to fire next. Of the columns that actually fire next bar, the predicted fraction is hits/active, and the anomaly score = 1 − hits/active (the share of unpredicted firings). As learning matures and patterns stay stable, predictions land and anomaly is low; when patterns break, predictions miss and anomaly spikes.

⚙️ Recommended Settings & Tuning Guide

BTC (1H–4H): Columns 16, Active Columns 3, Permanence Inc 0.10 / Dec 0.04, Prediction Order 2, Anomaly Threshold 0.55. Standard settings fit well
ETH (1H–4H): As BTC (HTM learns sequences self-supervised, no outcome window needed)
SOL (15m–1H): High volatility favors Anomaly Smoothing 5–6 to smooth the score, Anomaly Threshold 0.6 to suppress false anomalies
XRP (1H–4H): Spike-prone; Columns 20 for more capacity, Prediction Order 1 to weight recent transitions
Columns / Active Columns: more columns add capacity but slow learning; sparsity (Active/Columns) is the heart of HTM — lower is more HTM-like
Permanence Inc/Dec: higher Inc learns faster, higher Dec forgets old memory faster — tune to how fast the market changes
Prediction Order: higher considers longer context (higher-order sequences); lower uses only recent transitions
Anomaly Threshold: higher makes vertical lines rare (only large anomalies); lower more frequent

💡 How to Use in Practice

Reacting to anomaly lines: a vertical line marks a bar where the learned temporal pattern broke — often the onset of a trend change, breakout, or regime shift; a basis for caution or reversal
Reading Sequence Stability: high (green) = the market follows learned patterns (predictable); low (red) = patterns broke, unpredictable. A sudden drop signals an environment change
Interpreting anomalies: sustained anomalies = a regime change in progress; a one-off = a transient shock — stability recovery means adaptation to a new pattern is done
Watching the active SDR: the panel's SDR view (▰▱) shows which columns fire now; recurring SDRs = known patterns, novel SDRs = unfamiliar conditions
Using predicted/hit counts: hits near predicted = stable sequence; a gap = anomaly — also a gauge of learning maturity
Multi-timeframe usage: confirm the big-picture sequence stability on the higher timeframe (4H), then time turns on anomaly lines on the lower one (15m–1H)

⚠️ Important Notes

Initial learning period: right after launch the transition memory is empty and everything looks "anomalous"; treat anomaly as elevated until enough transitions are learned (several hundred bars)
Learning resets: changing parameters, switching symbol/timeframe, or recompiling reinitializes the column receptive fields, transition memory, and SDR history, restarting learning from zero
Anomaly ≠ trade signal: an anomalous transition marks a "pattern break," not a direction (buy/sell); use it as a caution signal of possible change and pair direction calls with other analysis
Sparsity constraint: to fit Pine's compute budget, this is a lightweight build with fewer columns than a true HTM — not as sparse as HTM's ~2%
Adaptive-system nature: historical and live behavior can differ — always forward-test
Constraints: this is a lightweight implementation within Pine's compute budget; it scans a columns × columns transition matrix, so very large column counts affect performance

🚨 Disclaimer

This indicator is an analytical and educational visualization tool. The HTM-style sequence memory, SDR encoding, transition learning, anomaly score, and sequence stability are quantitative heuristics computed on-chart from price data — they are not financial advice, buy/sell signals, or any guarantee of future performance. Anomaly detection can produce false positives. Always combine any tool with your own analysis and disciplined risk management.

Feragatname

Bilgiler ve yayınlar, TradingView tarafından sağlanan veya onaylanan finansal, yatırım, alım satım veya diğer türden tavsiye veya öneriler anlamına gelmez ve teşkil etmez. Kullanım Koşulları bölümünde daha fazlasını okuyun.