Appearance

Personalize your experience

Mode
Accent Color
Direction
QuaScript

Kalman Velocity Trend

Admin's Choice

Local-linear Kalman filter with velocity coloring, forward projection cone and shock alerts

TrendPrice overlay WebGPU CanvasHybridDashboardSignals
quascripttrendkalmanvelocityprojectionstate-space
Kalman Velocity Trendengine 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)
FreeOpen source

Favourites and Admin's Choice analyses appear in the terminal's indicators window under Analyses.

Language
QuaScript
Engine
Native C++, incremental on live ticks
Rendering
WebGPU + Canvas
Placement
Price overlay
Settings
5
Plotted series
5
Lines of code
52
Source
presets/analysis/trend/kalman_velocity_trend.qs

About

A local-linear-trend Kalman filter models price as a level plus a velocity (slope per bar) and re-estimates both on every bar. The level is coloured by velocity in ATRs per bar, the dashed line projects the level forward at the current velocity, and the cone between them shows how far the model expects price to travel. Marks flag velocity reversals and forecast shocks: bars whose one-step forecast error is several standard deviations of the recent errors.

5
Plotted series
4
Signal marks
1
Drawings
2
Signal rules
5
Settings
41
Lines of code

What it draws

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

Series

  • Line4 visible · 1 helper
    Kalman levelProjected level
  • Band fills (render.band calls)2
Legend
Kalman level Projected level Upper tolerance Lower tolerance

Signal marks

Velocity turned positiveVelocity turned negativeUpside forecast shockDownside forecast shock

Drawings and chart effects

  • Dashboard tables1 created

How it runs

From source to the live chart, for this script

  1. 1
    Compile

    The QuaScript compiler checks the 52-line script (41 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. 1 persist variable keeps 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

    5 settings in 3 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
  • • 5 plotted series
  • • 2 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)

Signals

2 signal rules declared with signal.rule

Kalman velocity reversal

The estimated trend velocity changed sign

Kalman forecast shock

Price moved far outside the filter's one-step forecast

Settings

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

Filter
SettingTypeDefaultRange / optionsId
Level agilityNumber0.050.001 – 1, step 0.005level_agility
Velocity agilityNumber0.00050.00001 – 0.05, step 0.0001velocity_agility
Surprise windowInteger5010 – 300surprise_window
Projection
SettingTypeDefaultRange / optionsId
Projection horizon (bars)Integer102 – 60projection_horizon_bars
Signals
SettingTypeDefaultRange / optionsId
Shock threshold (z)Number2.51 – 6, step 0.1shock_threshold_z

Script

packages/quascript/presets/analysis/trend/kalman_velocity_trend.qs

Header

analysis "Kalman Velocity Trend" {
    overlay = true
    render = webgpu
    short_title = KVT
    precision = 2
}
Total lines
52
Code lines
41
Comment lines
5
Helper functions
0
Loops
0
Persistent variables
1
Higher-interval feeds
0
Engine plots
5

Built with

Technical analysis (ta.*)
ta.atrta.kalman_trend
Math (math.*)
math.absmath.clampmath.max
Imported modules
viz/premium

Discussion

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