Appearance

Personalize your experience

Mode
Accent Color
Direction
Analysis Marketplace
QuaScript

Kalman Regime Channel

Admin's Choice NewFree

Kalman fair value with sigma channels that change meaning with the regime

WebGPU StudioPrice overlay WebGPU CanvasHybridDashboardCandle colorsSignalsAlerts
quascriptgpuwebgpukalmanregimehurst

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
Kalman Regime Channelengine result
Loading the engine result…
quatick-charts · QuaScript engine on synthetic 1-minute bars · drag to pan · scroll to zoom · Run executes the script on the engine (⌘/Ctrl+Enter while editing)

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.

12
Plotted series
4
Signal marks
2
Drawings
2
Alert rules
9
Settings
69
Lines of code

What it draws

Price overlay · counted from the engine's plot table and the script's draw calls

Series

  • Line7 visible · 5 helper
    Fair value
  • Band fills (render.band calls)5
Legend
Fair value

Signal marks

Trend breakout upTrend breakout downFade shortFade long

Drawings and chart effects

  • Dashboard tables1 created
  • Tags1 created
  • Candle colors

How it runs

From source to the live chart, for this script

  1. 1
    Compile

    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.

  2. 2
    Place

    The header sets overlay = true, so everything is drawn on the price chart, on the same scale as the candles.

  3. 3
    Compute

    The script runs once per bar, oldest to newest. 4 persist variables keep state (objects, counters) across bars.

  4. 4
    Stay 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.

  5. 5
    Render

    The results are handed to the chart: series on WebGPU, drawings on the Canvas 2D QuaScript layer.

  6. 6
    Tune

    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

WebGPUSeries renderer

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.

In this script
  • • 12 plotted series
  • • 5 band fill calls
  • • 4 signal mark types

Chosen by render = webgpu in the header.

WebGLNot used

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.

CanvasUsed

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.

In this script
  • • 1 dashboard tables (QuaScript layer)
  • • 1 tags (QuaScript layer)
  • • candle colors (QuaScript layer)

Alerts

2 alert rules declared with alert.rule

Regime breakout

A close beyond 2 sigma in the direction of a persistent trend

Mean-reversion fade

Price fell back inside 2 sigma in a mean-reverting regime

Settings

9 settings, grouped as in the chart's settings dialog

General
SettingTypeDefaultRange / optionsId
SourcePrice sourceclose—source
Filter
SettingTypeDefaultRange / optionsId
Process noiseNumber0.010.0001 – 1, step 0.001process_noise
Measurement noiseNumber0.50.01 – 10, step 0.01measurement_noise
Residual windowInteger6010 – 500residual_window
Regime
SettingTypeDefaultRange / optionsId
Hurst windowInteger12032 – 1000hurst_window
Efficiency windowInteger305 – 300efficiency_window
Trending above efficiencyNumber0.350.05 – 0.9, step 0.01trending_above_efficiency
Mean-reverting below HurstNumber0.450.1 – 0.6, step 0.01mean_reverting_below_hurst
Style
SettingTypeDefaultRange / optionsId
Color candlesToggle1—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

Technical analysis (ta.*)
ta.kalman
Statistics (stat.*)
stat.hurststat.stdev
Microstructure kernels (hft.*)
hft.efficiency
Math (math.*)
math.absmath.clampmath.max

Discussion

Sign in to join the discussion. Your posts and replies show up on your profile.