Indicator · Pine Script v5 · On the chart

Kalman Gain Parameter Mechanics

by techteam92· code credited to capissimo

This indicator calculates multiple smoothed versions of a chosen dataset using Kalman filters with adjustable gain parameters.

View on GitHub

GitHub stars1on the repository
Pine versionv5runs as is
Lines of code71
Settings12inputs
LicenceNone statedfile: MPL-2.0
Last update1 year ago20 Nov 2024

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

71 lines of Pine Script v5 from scripts/127-Kalman Gain-Parameter-Mechanics.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

127-Kalman Gain-Parameter-Mechanics.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © capissimo

//@version=5
indicator('Kalman Gain Parameter Mechanics', '', true)

// Explanation of Gain parameter of Kalman function in HMA-Kalman & Trendlines script.
// To see better results set your Chart's timeframe to Daily.

//-- Inputs

ds    = input.source(close, 'Dataset')

g1    = input.bool(true,    'Kalman', inline='g1') 
g2    = input.bool(false,   'Kalman', inline='g2') 
g3    = input.bool(false,   'Kalman', inline='g3') 
g4    = input.bool(false,   'Kalman', inline='g4') 
g5    = input.bool(false,   'Kalman', inline='g5') 

gain1 = input.int(1,        'Gain1', 1, step=1, inline='g1') 
gain2 = input.int(10,       'Gain2', 1, step=1, inline='g2')
gain3 = input.int(100,      'Gain3', 1, step=1, inline='g3')
gain4 = input.int(1000,     'Gain4', 1, step=1, inline='g4')
gain5 = input.int(10000,    'Gain5', 1, step=1, inline='g5')

strat = input.bool(false, 'Show Strategy Code')

//-- Functions

kalman(x, g) =>
    gn = g/1000000  //-- smoothing magnitude adjustment
    kf = 0.0
    dk = x - nz(kf[1], x)
    smooth = nz(kf[1],x)+dk*math.sqrt(gn*2)  //-- serves as a smoothing factor
    velo = 0.0
    velo := nz(velo[1],0) + (gn*dk)
    kf := smooth+velo

//-- Logic

k1 = kalman(ds, gain1)
k2 = kalman(ds, gain2)
k3 = kalman(ds, gain3)
k4 = kalman(ds, gain4)
k5 = kalman(ds, gain5)

//-- Visuals

plot(g1 ? k1 : na, 'K1', color.orange)
plot(g2 ? k2 : na, 'K2', color.red)
plot(g3 ? k3 : na, 'K3', color.green)
plot(g4 ? k4 : na, 'K4', color.olive)
plot(g5 ? k5 : na, 'K5', color.gray)

//-- Strategy Logic

var int signal = 0
signal := ta.crossover(k4,k5) ? -1 : ta.crossunder(k4,k5) ? 1 : nz(signal[1])

changed = ta.change(signal)

long  = changed and signal== 1
short = changed and signal==-1

//-- Visuals

plot(strat? k4 : na, 'K4', color.olive, 2)
plot(strat? k5 : na, 'K5', color.gray,  2)

plotshape(strat and long ?low :na, '', shape.labelup,   location.belowbar, color.green, size=size.small)
plotshape(strat and short?high:na, '', shape.labeldown, location.abovebar, color.red,   size=size.small)

Overview

Kalman Gain Parameter Mechanics plots the resulting lines on the price chart for visual comparison. The main settings allow selection of the input source and toggling each gain level along with their values. A strategy section can be enabled to generate crossover signals between two of the filtered outputs, producing long and short entries. The filter helps reduce noise in price data while preserving trend direction. Users should test it on higher timeframes such as daily for optimal smoothing effects.

Details

Published by

techteam92 on GitHub

Code credit

capissimo, as written in the script's header

Type

Indicator, Pine Script v5

Draws

On the price chart

Category

Oscillators & momentum, Moving averages, Trend

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Datasetsourcecloseds
Kalmanbooltrueg1
Kalmanboolfalseg2
Kalmanboolfalseg3
Kalmanboolfalseg4
Kalmanboolfalseg5
Gain1int1gain1
Gain2int10gain2
Gain3int100gain3
Gain4int1000gain4
Gain5int10000gain5
Show Strategy Codeboolfalsestrat
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

948 stars

The Adaptive RSI Moving Average (ARSIMA) is an overlay indicator that dynamically adjusts its smoothing factor based on the Relative Strength Index (RSI). When the RSI moves toward extreme overbought or oversold conditions, the smoothing factor increases to ma

Indicator v4 Moving averagesOscillators & momentum
Updated 10 days ago · GPL-3.0 GitHub repository of Adaptive RSI Moving Average
218 stars

TradersPost Trading Checklist is an overlay indicator that evaluates a suite of popular technical conditions for long and short trade setups. It checks session-anchored VWAP, fast and slow EMA alignments and crosses, 200 SMA, RSI overbought or oversold conditi

Indicator v6 Screeners & dashboardsTrend
Updated 3 months ago · None stated GitHub repository of TradersPost Trading Checklist

Daily Trend Filter

by agutinbaigo28
147 stars

Calculates market regime conditions by combining RSI, MACD, and ADX/DMI indicators. It evaluates whether the market is in a strong bullish, strong bearish, neutral, or non-trending regime. The script plots a colored line overlaying the close price to reflect t

Indicator v5 TrendOscillators & momentum
Updated 6 weeks ago · MIT GitHub repository of Daily Trend Filter

AAPP

by capissimo
114 stars

This indicator plots an adaptive moving average or scaled RSI divergence line directly on the price chart. It calculates dual RSI series to measure momentum divergence, scales the values to the chart's price range, and constructs an adaptive average filtered b

Indicator v4 Moving averagesTrend
Updated 1 year ago · None stated GitHub repository of AAPP

Signal Strategy 15m

by tripolskypetr
72 stars

This indicator generates trend-following trade signals on the price chart by combining moving average crossovers with multi-factor filters. It triggers entry alerts when fast and slow EMAs cross in the direction of a baseline trend EMA, confirmed by non-extrem

Indicator v5 TrendMoving averages
Updated 3 days ago · MIT GitHub repository of Signal Strategy 15m
56 stars

Double Screened Decision is a multi-timeframe trend and momentum indicator overlaid directly on the price chart. It dynamically selects a higher timeframe based on the active chart resolution to evaluate higher-timeframe MACD, Bollinger Bands, RSI, and Stochas

Indicator v5 TrendMoving averages Repaints
Updated 4 months ago · None stated GitHub repository of Double Screened Decision

More indicators

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers