OPEN-SOURCE SCRIPT
MICRO SOM

What this is
A Kohonen Self-Organizing Map that learns market structure from scratch, with no labels, no backpropagation, and no predefined regimes. It builds a topological map of every market condition it has observed, then shows you where the current bar sits on that map.
This is unsupervised competitive learning — a fundamentally different approach from the neural networks usually seen on TradingView. Nothing here is trying to predict direction. It is trying to organize market states, and any predictive read is a byproduct you interpret afterward.
How it works
Each bar is encoded as a five-dimensional vector: distance from VWAP, trend-versus-chop efficiency, volatility state, relative volume, and momentum. All five are ATR-normalized so the map transfers across instruments.
Thirty-six nodes arranged in a 6×6 grid compete to be nearest that vector. The closest node wins — and critically, the winner and its grid neighbors shift toward the input, weighted by a Gaussian falloff.
That neighbor update is the entire mechanism. It forces adjacent nodes to represent similar market states, which is what turns 36 independent clusters into a genuine map. Remove it and this is just k-means.
The neighborhood radius decays over training. A wide radius early establishes global topology; a narrow radius later refines local detail. A fixed radius either never organizes or freezes into a poor layout within the first hundred bars.
The map trains on every confirmed bar. Filtering samples would distort the density it exists to represent.
Reading the display
A 6×6 grid renders to the right of price:
Teal — states that historically preceded upward movement
Red — states that preceded downward movement
Gray — neutral or insufficiently visited
Brightness — visit frequency and directional consistency
White border — the node matching the current bar
Watch the highlighted cell move. That is the market traversing learned state space in real time.
BIAS shows the average forward move that historically followed from the current node, in ATR units. This is measured after clustering, not optimized for — the map organized blind, then the script asked what tended to follow from each region.
NOVELTY is the Euclidean distance from the current bar to its nearest node. When it exceeds the 90th percentile of its own recent history, the chart tints orange and a diamond prints. This means current conditions resemble nothing the map has learned.
Why novelty may be the most useful output
Threshold rules cannot tell you when they are outside their domain. This can. An ALIEN reading is a direct signal that historical analogues are unavailable — typically the moment other models are least reliable and position size should be smallest.
Settings
Learn — adaptation rate. Higher adapts faster but organizes less stably.
Radius — initial neighborhood width. Larger enforces smoother global topology.
Decay — bars over which learning rate and radius anneal toward their floor.
Grid X / Grid Size — map placement and cell height in ATR units.
Honest limitations
The map requires roughly 1,200 bars to organize meaningfully. Before that, the topology is still unfolding and bias values are noise.
BIAS is a historical average, not a forecast. A node showing +0.4 ATR means bars in that region tended upward — it says nothing about the sample size behind that average or whether the relationship persists.
Five features cannot capture everything that matters. The map organizes what it is shown, and no more.
This is an analytical and visualization tool. It produces no entry or exit signals, and it is not financial advice.
Open source. The full algorithm is readable in the code, with the competitive learning step, neighborhood update, and radius annealing documented inline.
A Kohonen Self-Organizing Map that learns market structure from scratch, with no labels, no backpropagation, and no predefined regimes. It builds a topological map of every market condition it has observed, then shows you where the current bar sits on that map.
This is unsupervised competitive learning — a fundamentally different approach from the neural networks usually seen on TradingView. Nothing here is trying to predict direction. It is trying to organize market states, and any predictive read is a byproduct you interpret afterward.
How it works
Each bar is encoded as a five-dimensional vector: distance from VWAP, trend-versus-chop efficiency, volatility state, relative volume, and momentum. All five are ATR-normalized so the map transfers across instruments.
Thirty-six nodes arranged in a 6×6 grid compete to be nearest that vector. The closest node wins — and critically, the winner and its grid neighbors shift toward the input, weighted by a Gaussian falloff.
That neighbor update is the entire mechanism. It forces adjacent nodes to represent similar market states, which is what turns 36 independent clusters into a genuine map. Remove it and this is just k-means.
The neighborhood radius decays over training. A wide radius early establishes global topology; a narrow radius later refines local detail. A fixed radius either never organizes or freezes into a poor layout within the first hundred bars.
The map trains on every confirmed bar. Filtering samples would distort the density it exists to represent.
Reading the display
A 6×6 grid renders to the right of price:
Teal — states that historically preceded upward movement
Red — states that preceded downward movement
Gray — neutral or insufficiently visited
Brightness — visit frequency and directional consistency
White border — the node matching the current bar
Watch the highlighted cell move. That is the market traversing learned state space in real time.
BIAS shows the average forward move that historically followed from the current node, in ATR units. This is measured after clustering, not optimized for — the map organized blind, then the script asked what tended to follow from each region.
NOVELTY is the Euclidean distance from the current bar to its nearest node. When it exceeds the 90th percentile of its own recent history, the chart tints orange and a diamond prints. This means current conditions resemble nothing the map has learned.
Why novelty may be the most useful output
Threshold rules cannot tell you when they are outside their domain. This can. An ALIEN reading is a direct signal that historical analogues are unavailable — typically the moment other models are least reliable and position size should be smallest.
Settings
Learn — adaptation rate. Higher adapts faster but organizes less stably.
Radius — initial neighborhood width. Larger enforces smoother global topology.
Decay — bars over which learning rate and radius anneal toward their floor.
Grid X / Grid Size — map placement and cell height in ATR units.
Honest limitations
The map requires roughly 1,200 bars to organize meaningfully. Before that, the topology is still unfolding and bias values are noise.
BIAS is a historical average, not a forecast. A node showing +0.4 ATR means bars in that region tended upward — it says nothing about the sample size behind that average or whether the relationship persists.
Five features cannot capture everything that matters. The map organizes what it is shown, and no more.
This is an analytical and visualization tool. It produces no entry or exit signals, and it is not financial advice.
Open source. The full algorithm is readable in the code, with the competitive learning step, neighborhood update, and radius annealing documented inline.
オープンソーススクリプト
TradingViewの精神に則り、このスクリプトの作者はコードをオープンソースとして公開してくれました。トレーダーが内容を確認・検証できるようにという配慮です。作者に拍手を送りましょう!無料で利用できますが、コードの再公開はハウスルールに従う必要があります。
免責事項
これらの情報および投稿は、TradingViewが提供または承認する金融、投資、取引、またはその他の種類の助言もしくは推奨であることを意図したものではなく、またこれらに該当するものでもありません。詳細は利用規約をご覧ください。
オープンソーススクリプト
TradingViewの精神に則り、このスクリプトの作者はコードをオープンソースとして公開してくれました。トレーダーが内容を確認・検証できるようにという配慮です。作者に拍手を送りましょう!無料で利用できますが、コードの再公開はハウスルールに従う必要があります。
免責事項
これらの情報および投稿は、TradingViewが提供または承認する金融、投資、取引、またはその他の種類の助言もしくは推奨であることを意図したものではなく、またこれらに該当するものでもありません。詳細は利用規約をご覧ください。