OPEN-SOURCE SCRIPT
Kalman Moving Average For Loop

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.
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.
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.