No magic: Python computes the reference, a generator turns the graph into Pine, and Pine reproduces the reference bar for bar.
Pull the subgraph from the public MaleCNS bucket: command neurons, looming detectors, mushroom bodies. 5,084 neurons, 108,317 connections.
A leaky integrate-and-fire simulator in Python, dopaminergic plasticity, backtest, shuffled-weight control. All the biology lives here.
Prune to the platform budget
and emit .pine: the graph ships inside the script as a packed string.
An array of 17,000 connections does not fit in the source: Pine caps the token count. But a string literal costs one token regardless of length. So the edge list is encoded at three characters per connection and unpacked on the first bar.
// the graph ships packed and is expanded once var int[] src = array.new_int() var int[] dst = array.new_int() var int[] w = array.new_int() if barstate.isfirst blob = part0() + part1() + part2() // 8 pushes per function: works around CE10295 for i = 0 to str.length(blob) / 3 - 1 decode(str.substring(blob, i * 3, i * 3 + 3))
Sweeping every neuron on every step blows the 500 ms per-bar limit. Event-driven instead: walk a spike queue, let the membrane potential decay lazily.
// state updates only on a closed bar, or the network re-runs on every tick if barstate.isconfirmed for step = 0 to STEPS - 1 for idx in fired // a queue, not all 995 cells for e = rowStart(idx) to rowEnd(idx) charge(dst, w)
Measured on a live chart: roughly 4–6 million operations per second, and the whole run must finish inside 20 seconds. That puts the ceiling near 100 million operations, which is what set the size of the distilled circuit: 995 neurons, 17,000 connections, 20 simulation steps per bar.
It lives on TradingView, in Community Scripts: open source, moderated, and free to add to any chart. That publication is the only copy of it there is.
One click, any symbol, any timeframe. 995 neurons and 17,000 measured connections are recomputed on every bar close, live.
648 lines of Pine Script v6, open and moderated. The packed edge list and the event-driven propagation are both in there.
Strategy Tester, with your own fee and slippage. It ships at 0.02% maker per side — put your venue's in and watch what that does.
The publication carries what this page leaves out on purpose: the split between what is measured and what we modeled, the three layers, the limitations written out in full, and the shuffled-weight control. Questions get answered in the comments under it.
There is no copy of the script on this site, deliberately. The published version is the only one, so what you add to a chart and what you read here can never drift apart.
flyem-male-cns bucket —
annotations, neurotransmitters, connection weights. No authentication required..pine file.Data: MaleCNS v1.0 under CC BY 4.0 — FlyEM/HHMI Janelia, University of Cambridge, MRC Laboratory of Molecular Biology, Google Research. The FlyWire connectome is deliberately not used: it carries a non-commercial licence.
Nothing on this site is investment advice.