The templates gallery
Three starter Rhai strategies, each declaring its knobs with param() so it drops straight into the sweep grid — loadable blind from a dropdown, or previewed card by card in the gallery before they overwrite the editor.
The starters live in crates/vike-script/src/templates.rs, and its header says what they are
for: starter Rhai strategies for the Studio, each parameterised via param() so they drop straight
into the sweep grid. templates() returns three (name, source) pairs, and
every_template_compiles_and_is_parameterized compiles every one and checks that it exposes at
least one param(), so a starter that will not build or cannot be swept cannot ship.
The three
- SMA cross —
fast(default 5) andslow(20); long when the fast average is above the slow one, short below, reaching the target throughmarket(...)by the delta fromposition(). The Studio's default editor script is the same idea with hard-coded constants; this is the sweepable form. - RSI reversion —
len(14),lo(30),hi(70); buys one unit belowlowhen not already long, sells one abovehiwhen not already short. - Donchian breakout —
len(20); a symmetric proxy oversma, and the template says so in its own comment:donchianis not bound to scripts because it is multi-output (upper/mid/lower) and the bridge binds single-output indicators only, sodonchian(len)would be a function-not-found at the first call rather than a silent upper-band read. Long whenhigh()breaks above the average, short whenlow()breaks below.
Every template guards its warm-up with is_nan() before acting — the pattern a script over any
indicator needs. Writing a strategy covers the language and
the order vocabulary the verbs.
Two ways to load one
Both live in the Sweep & Validate tool. The Template dropdown plus its Load button loads blind:
the selected template's full source replaces the editor buffer. Below it, the Browse templates
header opens the gallery — crates/vike-studio/src/templates_gallery.rs, whose header states the
difference: richer than the one-line dropdown, because you see the script before loading it. Each
card shows the template's name, the first eight lines of its code in monospace with a trailing …
when the script is longer (template_preview, which is pure and tested), and a Load button hugging
the right edge so every card's action lines up.
Either route overwrites the editor buffer with the full template code and re-baselines the
editor's unsaved-changes tracking, so a freshly loaded template is
not marked dirty. gallery_ui returns true the frame Load is clicked for exactly that purpose,
mirroring the indicators pane's bool-return convention.
The empty results panel offers the same thing as a getting-started action: beside ▶ Run backtest it shows "Load a template", which loads whichever template the dropdown currently selects.
The dropdown selection is workspace state
template_idx — the dropdown's position — is one of the five fields the
workspace snapshot persists, and StudioState::new_with_qa
clamps a restored index against the current templates() length, so a value stored by a build
with more or fewer templates can never index out of bounds.
Into the sweep grid
Because each starter declares its knobs with param(), "Seed from params" in the same pane fills
the parameter grid from the script's declarations through vike_script::discover_params — one row
per parameter, its default as the initial candidate — and ▶ Run Sweep backtests every combination
of the values you type (results covers the ranked table). A
discovery failure, such as a script that does not compile, clears the grid rather than raising an
error; Run and Sweep report the compile error when the script is actually executed.
Not the strategy templates
These are Rhai scripts for the editor. The per-template pages under the strategies tree describe compiled Rust strategies — a different thing. In the Studio a compiled strategy is reached through the Strategy tool's "Native (Rust)" switch, whose dropdown lists the backtest harness registry's own roster, never through this gallery.
The indicators pane
Browse the indicator registry by category, set an indicator's parameters on sliders, and preview it over the picked slice's bars — a synchronous compute the pane asks the shell for, because the pane itself never touches the store.
The research pane
The studies a user has written, the one button that runs one, and the runs that came out — one list for the interpreted and compiled tiers, and a results surface that keeps a study's numbers out of any column a backtest's could share.