FlyTV
code

How this is put together

No magic: Python computes the reference, a generator turns the graph into Pine, and Pine reproduces the reference bar for bar.

1

ETL

Pull the subgraph from the public MaleCNS bucket: command neurons, looming detectors, mushroom bodies. 5,084 neurons, 108,317 connections.

2

Reference

A leaky integrate-and-fire simulator in Python, dopaminergic plasticity, backtest, shuffled-weight control. All the biology lives here.

3

Distill → Pine

Prune to the platform budget and emit .pine: the graph ships inside the script as a packed string.

Trick 1 — the graph inside a string literal

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))

Trick 2 — only compute what fired

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)

Trick 3 — the budget

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.

Get the script

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.

TradingView Community Scripts · open source
FlyTV — a real fruit fly connectome trading on your chart
tradingview.com/script/nmnHkA02-FlyTV-a-real-fruit-fly-connectome-trading-on-your-chart/

Add it to a chart

One click, any symbol, any timeframe. 995 neurons and 17,000 measured connections are recomputed on every bar close, live.

Read the source

648 lines of Pine Script v6, open and moderated. The packed edge list and the event-driven propagation are both in there.

Check the numbers

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.

How to reproduce it

  1. Download three MaleCNS v1.0 files from the public flyem-male-cns bucket — annotations, neurotransmitters, connection weights. No authentication required.
  2. Extract the subgraph: command neurons, LC4/LPLC2, KC/MBON/PAM/PPL1.
  3. Run the LIF simulator over hourly bars and — mandatory — the same run on shuffled weights with the node degree distribution preserved. Without that control, any claim that "the wiring is doing the work" is worthless.
  4. Prune the subgraph to the platform budget and generate the .pine file.
  5. Reconcile Pine and Python decisions bar for bar.

Licence and attribution

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.