Editors' picks
OPEN-SOURCE SCRIPT
Updated

Half Causal Estimator

11 580
Overview

The Half Causal Estimator is a specialized filtering method that provides responsive averages of market variables (volume, true range, or price change) with significantly reduced time delay compared to traditional moving averages. It employs a hybrid approach that leverages both historical data and time-of-day patterns to create a timely representation of market activity while maintaining smooth output.

Core Concept

Traditional moving averages suffer from time lag, which can delay signals and reduce their effectiveness for real-time decision making. The Half Causal Estimator addresses this limitation by using a non-causal filtering method that incorporates recent historical data (the causal component) alongside expected future behavior based on time-of-day patterns (the non-causal component).

This dual approach allows the filter to respond more quickly to changing market conditions while maintaining smoothness. The name "Half Causal" refers to this hybrid methodology—half of the data window comes from actual historical observations, while the other half is derived from time-of-day patterns observed over multiple days. By incorporating these "future" values from past patterns, the estimator can reduce the inherent lag present in traditional moving averages.

How It Works

The indicator operates through several coordinated steps. First, it stores and organizes market data by specific times of day (minutes/hours). Then it builds a profile of typical behavior for each time period. For calculations, it creates a filtering window where half consists of recent actual data and half consists of expected future values based on historical time-of-day patterns. Finally, it applies a kernel-based smoothing function to weight the values in this composite window.

This approach is particularly effective because market variables like volume, true range, and price changes tend to follow recognizable intraday patterns (they are positive values without DC components). By leveraging these patterns, the indicator doesn't try to predict future values in the traditional sense, but rather incorporates the average historical behavior at those future times into the current estimate.

The benefit of using this "average future data" approach is that it counteracts the lag inherent in traditional moving averages. In a standard moving average, recent price action is underweighted because older data points hold equal influence. By incorporating time-of-day averages for future periods, the Half Causal Estimator essentially shifts the center of the filter window closer to the current bar, resulting in more timely outputs while maintaining smoothing benefits.

Understanding Kernel Smoothing

At the heart of the Half Causal Estimator is kernel smoothing, a statistical technique that creates weighted averages where points closer to the center receive higher weights. This approach offers several advantages over simple moving averages. Unlike simple moving averages that weight all points equally, kernel smoothing applies a mathematically defined weight distribution. The weighting function helps minimize the impact of outliers and random fluctuations. Additionally, by adjusting the kernel width parameter, users can fine-tune the balance between responsiveness and smoothness.

The indicator supports three kernel types. The Gaussian kernel uses a bell-shaped distribution that weights central points heavily while still considering distant points. The Epanechnikov kernel employs a parabolic function that provides efficient noise reduction with a finite support range. The Triangular kernel applies a linear weighting that decreases uniformly from center to edges. These kernel functions provide the mathematical foundation for how the filter processes the combined window of past and "future" data points.

Applicable Data Sources

The indicator can be applied to three different data sources: volume (the trading volume of the security), true range (expressed as a percentage, measuring volatility), and change (the absolute percentage change from one closing price to the next).

Each of these variables shares the characteristic of being consistently positive and exhibiting cyclical intraday patterns, making them ideal candidates for this filtering approach.

Practical Applications

The Half Causal Estimator excels in scenarios where timely information is crucial. It helps in identifying volume climaxes or diminishing volume trends earlier than conventional indicators. It can detect changes in volatility patterns with reduced lag. The indicator is also useful for recognizing shifts in price momentum before they become obvious in price action, and providing smoother data for algorithmic trading systems that require reduced noise without sacrificing timeliness.

When volatility or volume spikes occur, conventional moving averages typically lag behind, potentially causing missed opportunities or delayed responses. The Half Causal Estimator produces signals that align more closely with actual market turns.

Technical Implementation

The implementation of the Half Causal Estimator involves several technical components working together. Data collection and organization is the first step—the indicator maintains a data structure that organizes market data by specific times of day. This creates a historical record of how volume, true range, or price change typically behaves at each minute/hour of the trading day.

For each calculation, the indicator constructs a composite window consisting of recent actual data points from the current session (the causal half) and historical averages for upcoming time periods from previous sessions (the non-causal half). The selected kernel function is then applied to this composite window, creating a weighted average where points closer to the center receive higher weights according to the mathematical properties of the chosen kernel. Finally, the kernel weights are normalized to ensure the output maintains proper scaling regardless of the kernel type or width parameter.

This framework enables the indicator to leverage the predictable time-of-day components in market data without trying to predict specific future values. Instead, it uses average historical patterns to reduce lag while maintaining the statistical benefits of smoothing techniques.

Configuration Options

The indicator provides several customization options. The data period setting determines the number of days of observations to store (0 uses all available data). Filter length controls the number of historical data points for the filter (total window size is length × 2 - 1). Filter width adjusts the width of the kernel function. Users can also select between Gaussian, Epanechnikov, and Triangular kernel functions, and customize visual settings such as colors and line width.

These parameters allow for fine-tuning the balance between responsiveness and smoothness based on individual trading preferences and the specific characteristics of the traded instrument.

Limitations

The indicator requires minute-based intraday timeframes, securities with volume data (when using volume as the source), and sufficient historical data to establish time-of-day patterns.

Conclusion

The Half Causal Estimator represents an innovative approach to technical analysis that addresses one of the fundamental limitations of traditional indicators: time lag. By incorporating time-of-day patterns into its calculations, it provides a more timely representation of market variables while maintaining the noise-reduction benefits of smoothing. This makes it a valuable tool for traders who need to make decisions based on real-time information about volume, volatility, or price changes.
Release Notes
New Feature: Selectable Weighting Schemes for Confidence Compensation

The Half Causal Estimator now includes configurable weighting modes that determine how the estimator handles confidence imbalances between real-time data (causal) and pseudo-future estimates (non-causal). This allows for greater control over how the filter adapts to uncertain or inconsistent time-of-day patterns.

What’s New:
You can now choose between three weighting schemes:

Symmetric (Default)
  • If the future estimate (non-causal side) shows low confidence (based on Coefficient of Variation), its influence is reduced.
  • The lost weight is symmetrically transferred to the real-time causal data on the other side of the filter window.
  • Balances the filter around the center using a confidence-driven see-saw approach.


Linear
  • Applies a direct linear boost to the causal side based on the lack of confidence in the non-causal side.


None
  • Applies the filter without adjusting for confidence.
  • Useful as a baseline or when no compensation is needed.


This enhancement adds a layer of adaptive intelligence to the estimator, letting you choose how aggressively the filter responds to uncertain future behavior.

Release Notes
Forgot to remove a reference sma. Renamed one of the plots.
Release Notes
New Features

Blackman Windowed Sinc Kernel
A new kernel type has been added to the existing options (Gaussian, Epanechnikov, and Triangular). The Blackman Windowed Sinc kernel provides improved frequency domain characteristics, which can be particularly useful for filtering out high-frequency noise while preserving important signal components. When this kernel type is selected, the filter length is automatically doubled to accommodate the wider effective width of this kernel.

Test Mode with Sine Squared Function
A new data source option called "Sine Squared Test" has been added. This generates a rectified sine wave with a period of one day, regardless of the selected timeframe. This test option is valuable for:
  • Verifying the indicator's behavior with a known cyclic pattern
  • Testing how different kernel types and settings respond to periodic data
  • Demonstrating the indicator's ability to track recurring patterns


Maximum Confidence Correction Parameter
A significant enhancement in this update is the addition of a parameter that allows users to adjust the intensity of the confidence correction system. While the confidence adjustment system (with its Symmetric, Linear, and None modes) was already available in the previous version, you can now fine-tune exactly how much this correction affects the estimator's output.
The new Maximum Confidence Correction Percent parameter allows fine control over how aggressively the confidence adjustment is applied. This setting (0-100%) lets users scale the effect of variability on weight adjustments. At 100%, the confidence correction is applied in full as in the previous version. At 0%, no correction is applied regardless of the selected correction mode. Values between allow for partial application of the correction, giving users precise control over the balance between lag reduction and consistency.

Technical Implementation Details
The confidence scoring continues to be calculated using the coefficient of variation (standard deviation divided by mean) for each time-of-day data point, but now this adjustment can be scaled by the user's preference. When using the Blackman Windowed Sinc kernel, the system automatically doubles the filter length to ensure proper frequency response. The confidence adjustments are applied as multipliers to the windowed data before the kernel is applied, with the new scaling parameter offering finer control over this process.

Release Notes
Expected Value Feature
A significant enhancement in this update is the addition of an "Expected Value" feature, which provides a pure time-of-day estimation option. Unlike the standard estimator which combines recent data with historical time-of-day patterns, the Expected Value uses only the average historical data for each time of day in its calculations.

This new feature serves two important purposes:
First, it allows users to see what would happen if the market followed purely historical time-of-day patterns without the influence of recent price action. This provides insight into the typical behavior expected for the current time of day based solely on historical patterns.

Second, and perhaps most powerfully, it enables forward extrapolation. Since the Expected Value relies only on time-of-day averages, it can project these patterns into future bars, giving traders a preview of expected volume, volatility, or price change patterns for upcoming periods. Users can specify how many bars to extrapolate through the "Expected Value Extrapolation Length" setting.

The Expected Value is visualized as a separate line with customizable color and width properties, making it easy to distinguish from the primary estimator. This feature is optional and can be toggled on or off according to user preference.

Extra Smoothing Option
The update introduces an "Extra Smoothing" parameter that applies a weighted moving average (WMA) to the estimator output. This additional smoothing layer helps reduce noise in the final signal while maintaining responsiveness.

When set to zero, no additional smoothing is applied. Higher values create progressively smoother outputs at the cost of some additional lag. This option is particularly useful for traders who prefer cleaner signals and are willing to accept a small lag increase in exchange for reduced noise.

Confidence Correction Improvement
This update fixes an important issue with the confidence correction system where division by zero or NaN (Not a Number) values could occur when processing time periods with no data or extreme statistical outliers.

In previous versions, when the standard deviation divided by the average (coefficient of variation) produced undefined results, the system would default to maximum confidence penalty. This could cause unintended behavior in certain market conditions.

The fix now ensures that in cases where the calculation cannot be properly performed, the confidence is preserved rather than penalized, defaulting to a weight of 1 instead of 0. This creates more stable behavior across different market conditions and instruments, particularly for time periods with limited historical data.

Conclusion
This update brings valuable new functionality to the Half Causal Estimator, enhancing both analytical capabilities and user experience. The Expected Value feature with its forward extrapolation provides a new dimension of insight into time-of-day patterns, while the extra smoothing option and confidence correction improvement offer greater flexibility and reliability.
Release Notes
Hooked in the tootip for the maximum confidence correction percent and renamed the expected value line width.

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.