OPEN-SOURCE SCRIPT

Kalman Moving Average For Loop

115
Key Features of the Indicator:
Flexible Moving Average Calculation (calcMovingAverage):Description: Allows users to select from 10 moving average types (SMA, EMA, DEMA, TEMA, WMA, VWMA, SMMA, HMA, LSMA, ALMA) to process the input price source (pricesource, default: close).

Parameters:
maType: User selects the moving average type (default: HMA).
period: Length of the moving average (default: 14).
almaSigma: Sigma parameter for ALMA (default: 5).

Purpose: Provides versatility in analyzing price trends, with the chosen moving average (maValue) used for comparison with the smoothed Kalman filter output.

Kalman Filter for Price Smoothing:
Description:
Applies a Kalman filter to the price source to produce a filtered price (kalmanFilteredPrice), which is further smoothed using an HMA to create smoothedKalmanPrice.

Parameters:
process_noise: Controls system model noise (default: 0.01).

measurement_noise:
Controls measurement noise (default: 3).
N: Filter order, determining the number of state estimates (default: 3).
smooth_period: HMA period for smoothing kalmanFilteredPrice (default: 9).

Purpose: Reduces noise in price data, providing a smoother trend line for signal generation and plotting.

Historical Analysis with For-Loop:
Description: Uses a for-loop to calculate the average of calcMovingAverage values over a user-defined historical range (from to to_) for historical bars of the price source (pricesource).

Parameters:
from: Start of the historical range (default: 1).
to_: End of the historical range (default: 25).

Purpose: Computes an average moving average (avgMa) over the specified range to compare with the smoothed Kalman price for signal generation.

Error Handling and Robustness:

Description: Includes checks for na values in the for-loop to ensure only valid calcMovingAverage values contribute to the average (avgMa). Resets signal and plot variables each bar to prevent carryover.

Purpose: Ensures reliable calculations and prevents errors from invalid data.



Declinazione di responsabilità

Le informazioni ed i contenuti pubblicati non costituiscono in alcun modo una sollecitazione ad investire o ad operare nei mercati finanziari. Non sono inoltre fornite o supportate da TradingView. Maggiori dettagli nelle Condizioni d'uso.