# Baseline Templates

The bundled set of strategies, indicators, and notebooks shipped under built-in/. Two classes coexist here: showcase examples to learn from, and baseline indicators expected to "just be there" without authoring.

Templates live in `templates/workspace/{strategies,indicators,notebooks}/built-in/{python,rust}/` and seed the user workspace at `your workspace/`. The v5 baseline migration deletes the older grab-bag of templates and re-seeds this final set; user-authored files outside the built-in/ folder are never touched.

Every file opens with the Quant Charts LLC disclaimer header and a one-paragraph "Demonstrates: ..." or "Baseline:" docstring.

### Notes

- Workspace path: `your workspace/`
- Edit templates freely. The migration only touches the baseline filenames.
- TBBO bucket uses TBBO-only metrics. No EMA / SMA on tick streams - those go in the Python / OHLC bucket.

<a id="multi_setup-py"></a>
## multi_setup.py

```python
multi_setup.pyPython OHLC strategy
```

Demonstrates: define_tag per-setup labeling (breakout vs pullback) + block_entries gating + breakeven_when on regime flip.

Two long-entry conditions feed entry_long with separate tags. After backtesting, the analyzer per-tag panel shows breakout vs pullback win rate and PnL separately. block_entries gates new trades during a vol_spike; breakeven_when snaps the stop to entry on a regime flip.

<a id="trail_sltp-py"></a>
## trail_sltp.py

```python
trail_sltp.pyPython OHLC strategy
```

Demonstrates: uses_sltp=True with emit_sltp="per_tick" chandelier trail plus a shift_levels tighten.

Computes per-tick SL/TP arrays every bar for a fully custom chandelier trail. The engine ratchets them favorably so the stop only ever protects profit; a shift_levels() call shows how to tighten the stop from a tag.

<a id="optimize-py"></a>
## optimize.py

```python
optimize.pyPython OHLC strategy
```

Demonstrates: heavy @day_start hoisting, _DAY_CACHE pattern, parameter sweep performance reference.

Top docstring lists the five hoisting rules with one-line examples. Body is a simple EMA crossover so the perf pattern, not the strategy logic, is the focus. Read this before writing any optimization-heavy strategy.

<a id="vp_zone-rs"></a>
## vp_zone.rs

```python
vp_zone.rsRust TBBO strategy
```

Demonstrates: VP zone trading (HVN reject / LVN break / shelf break), parameterized behavior, canonical Rust perf reference.

Heavy prepare(), tight calculate(). Three zone-trading modes selectable per parameter combo. emit_sltp="entry_only" keeps the bracket bundle sparse on large sweeps.

<a id="vp_shelf-rs"></a>
## vp_shelf.rs

```python
vp_shelf.rsRust TBBO strategy
```

Demonstrates: VP shelf rejection on the last completed VP (no lookahead), per-tick chandelier trail.

Trades shelf rejections off the previous-period VP only - strict no-lookahead. Companion to the indicator-side VP for visual parity.

<a id="imbalance-rs"></a>
## imbalance.rs

```python
imbalance.rsRust TBBO strategy
```

Demonstrates: bid/ask imbalance + CVD slope entry, imbalance-flip exit (no SL/TP). TBBO-only metric.

No EMA / SMA / RSI - entries fire purely from bid_size vs ask_size dominance with CVD slope confirmation. SignalOutput without with_sl_*/with_tp_* skips the bracket bundle.

<a id="regime-py"></a>
## regime.py

```python
regime.pyPython OHLC indicator
```

Demonstrates: regime classification tags an owning strategy can consume via use_indicator().

Emits volatility-regime tags. A strategy that calls use_indicator("regime") can read the regime array and feed it into block_entries or breakeven_when to gate or adjust trades.

<a id="bands-py"></a>
## bands.py

```python
bands.pyPython OHLC indicator
```

Demonstrates: EMA + ATR bands, multi-state regime tags, use_indicator() composition.

Pattern: a higher-level indicator that can be called from a strategy via use_indicator('bands', ema_period=..., atr_mult=...). Useful for stacking primitives.

<a id="orderflow-py"></a>
## orderflow.py

```python
orderflow.pyPython OHLC indicator
```

Demonstrates: volume / delta / vwap column access, cvd() / vwap_band() / imbalance() helpers, graceful degradation.

Designed for TBBO-converted OHLC bars (carries volume + delta + bid_vol + ask_vol per bar) but degrades gracefully on plain OHLC where only volume is present.

<a id="atr-py"></a>
## atr.py

```python
atr.pyPython OHLC indicator (baseline)
```

Baseline: ATR line + low / medium / high regime tags relative to the day's median ATR.

Always-available indicator for tag-based filtering. Drop it on any strategy to slice trades by ATR regime in the analyzer or notebook.

<a id="vwap-py"></a>
## vwap.py

```python
vwap.pyPython OHLC indicator (baseline)
```

Baseline: session VWAP with deviation bands and above_vwap_band / inside_vwap_band / below_vwap_band tags.

Builds VWAP from typical price * volume; falls back to a parquet-shipped vwap column when present. Tags are membership-only, no entry signals.

<a id="volume-py"></a>
## volume.py

```python
volume.pyPython OHLC indicator (baseline)
```

Baseline: bar volume + CVD with high_vol / vol_spike / cvd_up / cvd_down tags.

Plots per-bar volume colored by close-vs-prior direction and overlays CVD. Useful as a tag source for filtering trades by participation regime.

<a id="vp-rs"></a>
## vp.rs

```python
vp.rsRust TBBO indicator (baseline + showcase)
```

Baseline tick-fidelity Volume Profile. Tags: at_poc, inside_value_area, above_vah, below_val, near_hvn, near_lvn.

Six essential parameters (anchor, row_size, value_area_pct, hvn_threshold, lvn_threshold, proximity_ticks). Renders one right-side horizontal histogram per archived period plus the live one. Highly customizable for tag analysis.

<a id="vp_orderflow-rs"></a>
## vp_orderflow.rs

```python
vp_orderflow.rsRust TBBO indicator
```

Demonstrates: VP combined with bid/ask dominance at zones. Tags: bid_dom_at_poc / ask_dom_at_poc / bid_dom_at_hvn / ask_dom_at_hvn.

Tag-conditioned: fires when the mid is at a VP zone AND the smoothed imbalance points one way. Useful for "tag a trade as bid-supported HVN" analysis.

<a id="orderflow-rs"></a>
## orderflow.rs

```python
orderflow.rsRust TBBO indicator
```

Demonstrates: pure imbalance + CVD across the day. Tags: bid_dominant / ask_dominant / cvd_rising / cvd_falling.

Normalized [0,1] indicator pane. Microprice intentionally NOT plotted here - mixing a price-scale line with a normalized pane collapses the y-axis.

<a id="atr-rs"></a>
## atr.rs

```python
atr.rsRust TBBO indicator (baseline)
```

Baseline: bar-aggregated Wilder ATR with low / medium / high regime tags.

Aggregates ticks into N-minute bars (default 1m), runs Wilder ATR over `period` bars, maps back to per-tick. Lookback is in BARS not ticks, so `period=14` at `bar_minutes=1` = a 14-minute ATR.

<a id="vwap-rs"></a>
## vwap.rs

```python
vwap.rsRust TBBO indicator (baseline)
```

Baseline: session VWAP from tick mid * (bid_size + ask_size) with deviation-band tags.

Cumulative running sums over tick mid weighted by tick size. Each session resets via the day-prep boundary, so multi-day sweeps are session-anchored automatically.

<a id="volume-rs"></a>
## volume.rs

```python
volume.rsRust TBBO indicator (baseline)
```

Baseline: bar-aggregated volume + CVD with high_vol / vol_spike / cvd_up / cvd_down tags.

Per-bar volume = sum of bid_size + ask_size across ticks in the bar. CVD = cumulative (ask_size - bid_size). Lookbacks in bars.

<a id="getting_started-ipynb"></a>
## getting_started.ipynb

```python
getting_started.ipynbNotebook
```

Entry point. Walks through decorators, data, plotting, backtesting, optimization, tips & tricks.

Open this first when learning the system. Long-form, broad coverage.

<a id="analysis-ipynb"></a>
## analysis.ipynb

```python
analysis.ipynbNotebook
```

Adaptive analysis notebook generated by the Analyzer for any saved run. Auto-tailors cells to what the run contains: MAE/MFE + optimal SL/TP, Monte Carlo, by-hour, per-tag stats, parameter sensitivity, raw [`r.trades`](https://quantchartsllc.com/docs/python/py-backtest.md#r-trades) DataFrame.

Two ways to get one:

  1. From the Analyzer: run a backtest, click "Send to Notebook ↗" in the top bar, name the run. The notebook opens pre-loaded via `r = qc.load_run("<name>")`. Saved runs persist on disk and never get clobbered by future runs.

  2. From a notebook: call `qc.run(...)` / `qc.optimize(...)` / `qc.wfa(...)` to fire a fresh backtest inline; the returned BacktestResults object exposes the same surface (`.summary()`, `.monte_carlo()`, `.mae_mfe_analysis()`, `.by_tag()`, etc.).

List saved runs from any notebook with `qc.runs()`. Delete with `qc.delete_run(name)`. The Analyzer also exposes a "Saved Runs" dropdown for the same registry.

<a id="multi_day-ipynb"></a>
## multi_day.ipynb

```python
multi_day.ipynbNotebook
```

runner.run / runner.optimize multi-day workflow + Monte Carlo + parameter sweep.

Run multi-day backtests and grid sweeps from Python via quant_charts.runner. Same engine the Analyzer tab uses; works for both .py and .rs strategies.
