Appearance
Personalize your experience
Kalman Regime Channel
Admin's Choice NewFreeKalman fair value with sigma channels that change meaning with the regime
Favourites and Admin's Choice analyses are listed in the terminal's indicators window under Analysis Marketplace.
- Language
- QuaScript
- Engine
- Native C++, incremental on live ticks
- Rendering
- WebGPU + Canvas
- Placement
- Price overlay
- Settings
- 9
- Plots
- 12
- Lines of code
- 81
- Source
- presets/analysis/gpu/kalman_regime_channel.qs
About
A Kalman-filtered fair value with 1, 2 and 3 sigma channels whose color is the market regime. The regime comes from the efficiency ratio (how straight the path is) and the Hurst exponent (persistence of the moves): trending up, trending down, mean-reverting or undecided. The same 2 sigma touch means opposite things in those regimes, so the signals change with it: in a trend a close beyond 2 sigma is a breakout, in a mean-reverting market it is a fade back towards fair value.
What it draws
Price overlay · counted from the engine's plot table and the script's draw calls
Series
- Line7 visible · 5 helperFair value
- Band fills (render.band calls)5
Signal marks
Drawings and chart effects
- Dashboard tables1 created
- Tags1 created
- Candle colors
How it runs
From source to the live chart, for this script
- 1Compile
The QuaScript compiler checks the 81-line script (69 lines of code) and lowers it for the native C++ engine. Compile errors point at the exact line and column.
- 2Place
The header sets
overlay = true, so everything is drawn on the price chart, on the same scale as the candles. - 3Compute
The script runs once per bar, oldest to newest. 4
persistvariables keep state (objects, counters) across bars. - 4Stay live
On the terminal the script keeps one live engine session: a tick rolls the forming bar back to its checkpoint and re-executes only that bar, and new bars are appended, so history is never rerun while the market moves. The live result is identical to a full run.
- 5Render
The results are handed to the chart: series on WebGPU, drawings on the Canvas 2D QuaScript layer.
- 6Tune
9 settings in 4 groups appear in the chart's settings dialog. Changing one reruns the engine with the new value.
Rendering
Hybrid: this script draws on 2 surfaces at once
The browser's modern GPU API. The chart uploads every line, band and mark of the script as GPU buffers and draws them in one pass, so dense heatmaps and dozens of series stay smooth while you pan and zoom. Without WebGPU support the chart's GPU layer falls back to WebGL 2, then Canvas 2D.
- • 12 plotted series
- • 5 band fill calls
- • 4 signal mark types
Chosen by render = webgpu in the header.
GPU drawing through WebGL 2, available in every current browser. Used for chart-native profiles and for series that ask for it with backend = "webgl". Fast for large numbers of bars and wide fills.
The browser's 2D drawing API. Text-heavy and object-style output (dashboard tables, zones, tags, segments), candle colors and backgrounds are painted by the QuaScript layer, a Canvas 2D surface over the chart. Series use Canvas when the script's header does not ask for a GPU.
- • 1 dashboard tables (QuaScript layer)
- • 1 tags (QuaScript layer)
- • candle colors (QuaScript layer)
Alerts
2 alert rules declared with alert.rule
A close beyond 2 sigma in the direction of a persistent trend
Price fell back inside 2 sigma in a mean-reverting regime
Settings
9 settings, grouped as in the chart's settings dialog
| Setting | Type | Default | Range / options | Id |
|---|---|---|---|---|
| Source | Price source | close | — | source |
| Setting | Type | Default | Range / options | Id |
|---|---|---|---|---|
| Process noise | Number | 0.01 | 0.0001 – 1, step 0.001 | process_noise |
| Measurement noise | Number | 0.5 | 0.01 – 10, step 0.01 | measurement_noise |
| Residual window | Integer | 60 | 10 – 500 | residual_window |
| Setting | Type | Default | Range / options | Id |
|---|---|---|---|---|
| Hurst window | Integer | 120 | 32 – 1000 | hurst_window |
| Efficiency window | Integer | 30 | 5 – 300 | efficiency_window |
| Trending above efficiency | Number | 0.35 | 0.05 – 0.9, step 0.01 | trending_above_efficiency |
| Mean-reverting below Hurst | Number | 0.45 | 0.1 – 0.6, step 0.01 | mean_reverting_below_hurst |
| Setting | Type | Default | Range / options | Id |
|---|---|---|---|---|
| Color candles | Toggle | 1 | — | color_candles |
Script
packages/quascript/presets/analysis/gpu/kalman_regime_channel.qs
Header
analysis "Kalman Regime Channel" {
overlay = true
render = webgpu
max_objects = 120
}- Total lines
- 81
- Code lines
- 69
- Comment lines
- 7
- Helper functions
- 0
- Loops
- 0
- Persistent variables
- 4
- Higher-interval feeds
- 0
- Engine plots
- 12
Built with
ta.kalmanstat.hurststat.stdevhft.efficiencymath.absmath.clampmath.max
Discussion