• Joined on 2026-09-04

@jean/zeigerwerk (0.1.2)

Published 2026-11-14 13:54:03 +00:00 by jean in jean/zeigerwerk

Installation

@jean:registry=https://code.jeanavril.com/api/packages/jean/npm/
npm install @jean/zeigerwerk@0.1.2
"@jean/zeigerwerk": "0.1.2"

About this package

One indicator catalog for every app: 29 definitions computed by a Rust kernel as WebAssembly, with portable settings, legacy readers, search, form model and a drawing description for kerzwerk. No runtime dependencies.

zeigerwerk

One indicator catalog for every app. The definitions and their computation are written once, in Rust, and used in three ways:

  • natively, as the crate zeigerwerk (strategies' Rust server and its research parity tests);
  • as WebAssembly in the browser and in Node, through the npm package zeigerwerk (trading_book, tws-dashboard, strategies' web app);
  • as a drawing description for the chart library kerzwerk, which draws it with indicatorParts.

Every place computes the same bits for the same bars. Why and how: kerzwerk's specs/004-shared-indicators/. What changes against the apps' old code: docs/migrations.md; which variant equals which research function: docs/research.md.

29 definitions: sma, ema, wma, vwap, psar, ichimoku, supertrend, rsi, macd, stoch, stochrsi, cci, willr, roc, momentum, ao, bbands, keltner, donchian, atr, stddev, adx, volume, obv, mfi, cmf (tws-dashboard's 26) and atrzone, adr, rs (strategies').

Install

npm install zeigerwerk

It has no runtime dependencies and carries the WebAssembly module inside (about 75 kB), so no bundler or server has to find a .wasm file. It loads with import and with require.

Settings

An indicator is stored as a portable setting: its id, its definition and only what differs from the defaults.

import { newSetting, parseSetting, resolve, writeSetting, type Setting } from 'zeigerwerk';

const rsi: Setting = { id: 'rsi-1', def: 'rsi', params: { period: 21 }, styles: { value: { color: '#7c3aed' } } };

const r = resolve(rsi); // defaults filled, numbers clamped and rounded
r.values.period;        // 21
r.issues;               // [] — or { code: 'clamped', path: 'params.period', message: 'issue.clamped' }

const { setting, issues } = parseSetting(JSON.parse(stored)); // never throws
const toStore = writeSetting(setting!); // defaults dropped, unknown fields kept

resolve never refuses: a value it cannot use is replaced and reported. Issues carry a word key (issue.clamped) for the app's language.

Computing

Runs need the module once per process:

import { load, resolve, run, compute, warmup } from 'zeigerwerk';

await load();

const r = resolve({ id: 'bb', def: 'bbands' });
const x = run(r, bars, { clock: { zone: 'America/New_York' } });
x.outputs(); // { upper, middle, lower }: Float64Array each, NaN for a gap

x.append(nextBar);      // one bar more: one row computed
x.replaceLast(forming); // the forming bar changed
x.free();

compute(r, bars); // the same in one call, for a job
warmup(r);        // 20: bars of history after which the start no longer matters

bars holds columns: time in Unix seconds (UTC), open, high, low, close, optionally volume (null and undefined are gaps). Inputs beyond the bars:

  • clock: the exchange's time zone, for definitions that read sessions (VWAP per trading day). sessionKeys(time, clock) shows the keys.
  • benchmark: the benchmark's closes aligned to the bars, for relative strength (alignByTime(time, { time, close })).

The values are causal: a row depends on its bar and the bars before. Ichimoku's spans are drawn shifted; valueAt(resolved, outputs, key, i) gives what is drawn at bar i, shift included, for a legend or an alert.

warmup is Infinity where no count exists: OBV, VWAP over all bars, relative strength and Parabolic SAR depend on where the bars start.

Drawing with kerzwerk

import { drawing } from 'zeigerwerk';
import { indicatorParts } from 'kerzwerk';

const settings = [rsiSetting, bbSetting];
const drawings = settings.map((s) => drawing(resolve(s), 'de'));
const values = Object.fromEntries(settings.map((s) => [s.id, compute(resolve(s), bars, inputs)]));
const parts = indicatorParts(drawings, values, { length: n, open: bars.open, close: bars.close });
// parts.panes, parts.series, parts.levels and parts.ahead go into the chart's spec.

drawing() merges the definition's defaults with the setting: placement, pane height and range, colours (roles such as @ind-violet, defined by kerzwerk's theme.css), line styles, shifts, fills and levels, and the legend label ("RSI 14"). zeigerwerk does not depend on kerzwerk; a type check in js/test/kerzwerk.check.ts keeps the two descriptions equal.

Picker and form

import { categories, formFields, resetField, search, setField } from 'zeigerwerk';

search('bänder', { lang: 'de' }); // [Bollinger]; every word, any language, accents folded
categories('de');                 // Trend, Momentum, Volatilität, Volumen

formFields(setting, 'de');        // parameters, shift, then colour, width, line, visible per output
const { setting: next, issue } = setField(setting, 'period', 0); // refused: issue out-of-range
resetField(setting, 'style.upper.color'); // back to the default: the key is removed

The catalog ships no components: each app renders the fields its own way. Words: word(key, lang), name(def, lang), label(resolved, lang); the dictionaries are words/en.json and words/de.json, also served as zeigerwerk/words/*.

Reading the apps' stored indicators

import { fromTwsDashboard, fromTwsAlert, fromTradingBook, fromTradingBookStorage, fromStrategies } from 'zeigerwerk/legacy';

const { settings, issues } = fromTradingBookStorage((key) => localStorage.getItem(key));

None of them throws. What they cannot read becomes an issue with the raw value in its path; what they read and changed is reported as legacy. fixtures/corpus/ holds real stored settings of the three apps and what they read as.

Rust

use zeigerwerk::{definition, compute, Run, Columns};

let def = definition("sma").unwrap();
let rows = compute(def, &def.defaults(), &columns)?; // one Vec per output

let mut run = Run::new(def, &[50.0, 3.0])?;          // period 50, close
run.reset(&columns)?;
run.append(&bar);
run.replace_last(&bar);
let warm = (def.warmup)(&def.defaults());            // zeigerwerk::NEVER if none

The crate has no dependencies. Arithmetic in kernels is restricted to correctly rounded operations (tests/arith.rs), which is why native and WebAssembly give the same bits.

Build and test

cargo test --release
cd js && npm install && npm run build && npm test && npm run check
npm run bench   # SC-005: all 29 over 20,000 bars, updates, replay
npm run size    # module and JavaScript against their budgets
npm run check:browser   # the golden digests in a real browser (localhost:5180)

The WebAssembly build needs rustup target add wasm32-unknown-unknown. A changed computation shows in the golden digests (fixtures/golden.json): a released one never changes; a new variant gets a new choice value or a new definition instead.

Releases

The version stands in Cargo.toml and js/package.json; both change together, and the repository gets the tag v<version> (Rust users depend on the crate by Git tag). Every version goes to two registries with the same files: to npm as zeigerwerk, and to the registry on Jean's Gitea as @jean/zeigerwerk, for the apps that install it from there.

git tag -a v0.1.0 -m 0.1.0
cd js && npm publish     # to npm; runs build, check and tests first
npm run publish:gitea    # the same files as @jean/zeigerwerk
git push --follow-tags

Each registry needs a token with write access in the npm config of the machine that publishes, never in a repository. User-visible changes go into CHANGELOG.md.

Dependencies

Development Dependencies

ID Version
@jean/kerzwerk ^0.3.0
@types/node ^26.6.5
typescript ^6.0.3
vitest ^5.0.4

Keywords

indicators technical-analysis trading finance webassembly wasm rust rsi macd bollinger-bands ema kerzwerk
Details
npm
2026-11-14 13:54:03 +00:00
4
Jean Avril
MIT
latest
184 KiB
Assets (1)
Versions (3) View all
0.1.2 2026-11-14
0.1.1 2026-11-12
0.1.0 2026-11-12