Sinc MAKaiser Windowed Sinc Moving Average Indicator
The Kaiser Windowed Sinc Moving Average is an advanced technical indicator that combines the sinc function with the Kaiser window to create a highly customizable finite impulse response (FIR) filter for financial time series analysis.
Sinc Function: The Ideal Low-Pass Filter
At the core of this indicator is the sinc function, which represents the impulse response of an ideal low-pass filter. In signal processing and technical analysis, the sinc function is crucial because it allows for the creation of filters with precise frequency cutoff characteristics. When applied to financial data, this means the ability to separate long-term trends from short-term fluctuations with remarkable accuracy.
The primary advantage of using a sinc-based filter is the independent control over two critical parameters: the cutoff frequency and the number of samples used. The cutoff frequency, analogous to the "length" in traditional moving averages, determines which price movements are considered significant (low frequency) and which are treated as noise (high frequency). By adjusting the cutoff, analysts can fine-tune the filter to respond to specific market cycles or timeframes of interest.
The number of samples used in the filter doesn't affect the cutoff frequency but instead influences the filter's accuracy and steepness. Increasing the sample size results in a better approximation of the ideal low-pass filter, leading to sharper transitions between passed and attenuated frequencies. This allows for more precise trend identification and noise reduction without changing the fundamental frequency response characteristics.
Kaiser Window: Optimizing the Sinc Filter
While the sinc function provides excellent frequency domain characteristics, it has infinite length in the time domain, which is impractical for real-world applications. This is where the Kaiser window comes into play. By applying the Kaiser window to the sinc function, we create a finite-length filter that approximates the ideal response while minimizing unwanted oscillations (known as the Gibbs phenomenon) in the frequency domain.
The Kaiser window introduces an additional parameter, alpha, which controls the trade-off between the main-lobe width and side-lobe levels in the frequency response. This parameter allows users to fine-tune the filter's behavior, balancing between sharp cutoffs and minimal ripple effects.
Customizable Parameters
The Kaiser Windowed Sinc Moving Average offers several key parameters for customization:
Cutoff: Controls the filter's cutoff frequency, determining the divide between trends and noise.
Length: Sets the number of samples used in the FIR filter calculation, affecting the filter's accuracy and computational complexity.
Alpha: Influences the shape of the Kaiser window, allowing for fine-tuning of the filter's frequency response characteristics.
Centered and Non-Centered Modes
The indicator provides two operational modes:
Non-Centered (Real-time) Mode: Uses half of the windowed sinc function, suitable for real-time analysis and current market conditions.
Centered Mode: Utilizes the full windowed sinc function, resulting in a zero-phase filter. This mode introduces a delay but offers the most accurate trend identification for historical analysis.
Visualization Features
To enhance the analytical value of the indicator, several visualization options are included:
Gradient Coloring: Offers a range of color schemes to represent trend direction and strength.
Glow Effect: An optional visual enhancement for improved line visibility.
Background Fill: Highlights the area between the moving average and price, aiding in trend visualization.
Applications in Technical Analysis
The Kaiser Windowed Sinc Moving Average is particularly useful for precise trend identification, cycle analysis, and noise reduction in financial time series. Its ability to create custom low-pass filters with independent control over cutoff and filter accuracy makes it a powerful tool for analyzing various market conditions and timeframes.
Compared to traditional moving averages, this indicator offers superior frequency response characteristics and reduced lag in trend identification when properly tuned. It provides greater flexibility in filter design, allowing analysts to create moving averages tailored to specific trading strategies or market behaviors.
Conclusion
The Kaiser Windowed Sinc Moving Average represents an advanced approach to price smoothing and trend identification in technical analysis. By making the ideal low-pass filter characteristics of the sinc function practically applicable through Kaiser windowing, this indicator provides traders and analysts with a sophisticated tool for examining price trends and cycles.
Its implementation in Pine Script contributes to the TradingView community by making advanced signal processing techniques accessible for experimentation and further development in technical analysis. This indicator serves not only as a practical tool for market analysis but also as an educational resource for those interested in the intersection of signal processing and financial markets.
Related script:
FIR
PhiSmoother Moving Average Ribbon [ChartPrime]DSP FILTRATION PRIMER:
DSP (Digital Signal Processing) filtration plays a critical role with financial indication analysis, involving the application of digital filters to extract actionable insights from data. Its primary trading purpose is to distinguish and isolate relevant signals separate from market noise, allowing traders to enhance focus on underlying trends and patterns. By smoothing out price data, DSP filters aid with trend detection, facilitating the formulation of more effective trading techniques.
Additionally, DSP filtration can play an impactful role with detecting support and resistance levels within financial movements. By filtering out noise and emphasizing significant price movements, identifying key levels for entry and exit points become more apparent. Furthermore, DSP methods are instrumental in measuring market volatility, enabling traders to assess volatility levels with improved accuracy.
In summary, DSP filtration techniques are versatile tools for traders and analysts, enhancing decision-making processes in financial markets. By mitigating noise and highlighting relevant signals, DSP filtration improves the overall quality of trading analysis, ultimately leading to better conclusions for market participants.
APPLYING FIR FILTERS:
FIR (Finite Impulse Response) filters are indispensable tools in the realm of financial analysis, particularly for trend identification and characterization within market data. These filters effectively smooth out price fluctuations and noise, enabling traders to discern underlying trends with greater fidelity. By applying FIR filters to price data, robust trading strategies can be developed with grounded trend-following principles, enhancing their ability to capitalize on market movements.
Moreover, FIR filter applications extend into wide-ranging utility within various fields, one being vital for informed decision-making in analysis. These filters help identify critical price levels where assets may tend to stall or reverse direction, providing traders with valuable insights to aid with identification of optimal entry and exit points within their indicator arsenal. FIRs are undoubtedly a cornerstone to modern trading innovation.
Additionally, FIR filters aid in volatility measurement and analysis, allowing traders to gauge market volatility accurately and adjust their risk management approaches accordingly. By incorporating FIR filters into their analytical arsenal, traders can improve the quality of their decision-making processes and achieve better trading outcomes when contending with highly dynamic market conditions.
INTRODUCTORY DEBUT:
ChartPrime's " PhiSmoother Moving Average Ribbon " indicator aims to mark a significant advancement in technical analysis methodology by removing unwanted fluctuations and disturbances while minimizing phase disturbance and lag. This indicator introduces PhiSmoother, a powerful FIR filter in it's own right comparable to Ehlers' SuperSmoother.
PhiSmoother leverages a custom tailored FIR filter to smooth out price fluctuations by mitigating aliasing noise problematic to identification of underlying trends with accuracy. With adjustable parameters such as phase control, traders can fine-tune the indicator to suit their specific analytical needs, providing a flexible and customizable solution.
Mathemagically, PhiSmoother incorporates various color coding preferences, enabling traders to visualize trends more effectively on a volatile landscape. Whether utilizing progression, chameleon, or binary color schemes, you can more fluidly interpret market dynamics and make informed visual decisions regarding entry and exit points based on color-coded plotting.
The indicator's alert system further enhances its utility by providing notifications of specifically chosen filter crossings. Traders can customize alert modes and messages while ensuring they stay informed about potential opportunities aligned with their trading style.
Overall, the "PhiSmoother Moving Average Ribbon" visually stands out as a revolutionary mechanism for technical analysis, offering traders a comprehensive solution for trend identification, visualization, and alerting within financial markets to achieve advantageous outcomes.
NOTEWORTHY SETTINGS FEATURES:
Price Source Selection - The indicator offers flexibility in choosing the price source for analysis. Traders can select from multiple options.
Phase Control Parameter - One of the notable standout features of this indicator is the phase control parameter. Traders can fine-tune the phase or lag of the indicator to adapt it to different market conditions or timeframes. This feature enables optimization of the indicator's responsiveness to price movements and align it with their specific trading tactics.
Coloring Preferences - Another magical setting is the coloring features, one being "Chameleon Color Magic". Traders can customize the color scheme of the indicator based on their visual preferences or to improve interpretation. The indicator offers options such as progression, chameleon, or binary color schemes, all having versatility to dynamically visualize market trends and patterns. Two colors may be specifically chosen to reduce overlay indicator interference while also contrasting for your visual acuity.
Alert Controls - The indicator provides diverse alert controls to manage alerts for specific market events, depending on their trading preferences.
Alertable Crossings: Receive an alert based on selectable predefined crossovers between moving average neighbors
Customizable Alert Messages: Traders can personalize alert messages with preferred information details
Alert Frequency Control: The frequency of alerts is adjustable for maximum control of timely notifications
Filtered, N-Order Power-of-Cosine, Sinc FIR Filter [Loxx]Filtered, N-Order Power-of-Cosine, Sinc FIR Filter is a Discrete-Time, FIR Digital Filter that uses Power-of-Cosine Family of FIR filters. This is an N-order algorithm that allows up to 50 values for alpha, orders, of depth. This one differs from previous Power-of-Cosine filters I've published in that it this uses Windowed-Sinc filtering. I've also included a Dual Element Lag Reducer using Kalman velocity, a standard deviation filter, and a clutter filter. You can read about each of these below.
Impulse Response
What are FIR Filters?
In discrete-time signal processing, windowing is a preliminary signal shaping technique, usually applied to improve the appearance and usefulness of a subsequent Discrete Fourier Transform. Several window functions can be defined, based on a constant (rectangular window), B-splines, other polynomials, sinusoids, cosine-sums, adjustable, hybrid, and other types. The windowing operation consists of multipying the given sampled signal by the window function. For trading purposes, these FIR filters act as advanced weighted moving averages.
A finite impulse response (FIR) filter is a filter whose impulse response (or response to any finite length input) is of finite duration, because it settles to zero in finite time. This is in contrast to infinite impulse response (IIR) filters, which may have internal feedback and may continue to respond indefinitely (usually decaying).
The impulse response (that is, the output in response to a Kronecker delta input) of an Nth-order discrete-time FIR filter lasts exactly {\displaystyle N+1}N+1 samples (from first nonzero element through last nonzero element) before it then settles to zero.
FIR filters can be discrete-time or continuous-time, and digital or analog.
A FIR filter is (similar to, or) just a weighted moving average filter, where (unlike a typical equally weighted moving average filter) the weights of each delay tap are not constrained to be identical or even of the same sign. By changing various values in the array of weights (the impulse response, or time shifted and sampled version of the same), the frequency response of a FIR filter can be completely changed.
An FIR filter simply CONVOLVES the input time series (price data) with its IMPULSE RESPONSE. The impulse response is just a set of weights (or "coefficients") that multiply each data point. Then you just add up all the products and divide by the sum of the weights and that is it; e.g., for a 10-bar SMA you just add up 10 bars of price data (each multiplied by 1) and divide by 10. For a weighted-MA you add up the product of the price data with triangular-number weights and divide by the total weight.
What is a Standard Deviation Filter?
If price or output or both don't move more than the (standard deviation) * multiplier then the trend stays the previous bar trend. This will appear on the chart as "stepping" of the moving average line. This works similar to Super Trend or Parabolic SAR but is a more naive technique of filtering.
What is a Clutter Filter?
For our purposes here, this is a filter that compares the slope of the trading filter output to a threshold to determine whether to shift trends. If the slope is up but the slope doesn't exceed the threshold, then the color is gray and this indicates a chop zone. If the slope is down but the slope doesn't exceed the threshold, then the color is gray and this indicates a chop zone. Alternatively if either up or down slope exceeds the threshold then the trend turns green for up and red for down. Fro demonstration purposes, an EMA is used as the moving average. This acts to reduce the noise in the signal.
What is a Dual Element Lag Reducer?
Modifies an array of coefficients to reduce lag by the Lag Reduction Factor uses a generic version of a Kalman velocity component to accomplish this lag reduction is achieved by applying the following to the array:
2 * coeff - coeff
The response time vs noise battle still holds true, high lag reduction means more noise is present in your data! Please note that the beginning coefficients which the modifying matrix cannot be applied to (coef whose indecies are < LagReductionFactor) are simply multiplied by two for additional smoothing .
Whats a Windowed-Sinc Filter?
Windowed-sinc filters are used to separate one band of frequencies from another. They are very stable, produce few surprises, and can be pushed to incredible performance levels. These exceptional frequency domain characteristics are obtained at the expense of poor performance in the time domain, including excessive ripple and overshoot in the step response. When carried out by standard convolution, windowed-sinc filters are easy to program, but slow to execute.
The sinc function sinc (x), also called the "sampling function," is a function that arises frequently in signal processing and the theory of Fourier transforms.
In mathematics, the historical unnormalized sinc function is defined for x ≠ 0 by
sinc x = sinx / x
In digital signal processing and information theory, the normalized sinc function is commonly defined for x ≠ 0 by
sinc x = sin(pi * x) / (pi * x)
For our purposes here, we are used a normalized Sinc function
Included
Bar coloring
Loxx's Expanded Source Types
Signals
Alerts
Related indicators
Variety, Low-Pass, FIR Filter Impulse Response Explorer
STD-Filtered, Variety FIR Digital Filters w/ ATR Bands
STD/C-Filtered, N-Order Power-of-Cosine FIR Filter
STD/C-Filtered, Truncated Taylor Family FIR Filter
STD/Clutter-Filtered, Kaiser Window FIR Digital Filter
STD/Clutter Filtered, One-Sided, N-Sinc-Kernel, EFIR Filt
Variety, Low-Pass, FIR Filter Impulse Response Explorer [Loxx]Variety Low-Pass FIR Filter, Impulse Response Explorer is a simple impulse response explorer of 16 of the most popular FIR digital filtering windowing techniques. Y-values are the values of the coefficients produced by the selected algorithms; X-values are the index of sample. This indicator also allows you to turn on Sinc Windowing for all window types except for Rectangular, Triangular, and Linear. This is an educational indicator to demonstrate the differences between popular FIR filters in terms of their coefficient outputs. This is also used to compliment other indicators I've published or will publish that implement advanced FIR digital filters (see below to find applicable indicators).
Inputs:
Number of Coefficients to Calculate = Sample size; for example, this would be the period used in SMA or WMA
FIR Digital Filter Type = FIR windowing method you would like to explore
Multiplier (Sinc only) = applies a multiplier effect to the Sinc Windowing
Frequency Cutoff = this is necessary to smooth the output and get rid of noise. the lower the number, the smoother the output.
Turn on Sinc? = turn this on if you want to convert the windowing function from regular function to a Windowed-Sinc filter
Order = This is used for power of cosine filter only. This is the N-order, or depth, of the filter you wish to create.
What are FIR Filters?
In discrete-time signal processing, windowing is a preliminary signal shaping technique, usually applied to improve the appearance and usefulness of a subsequent Discrete Fourier Transform. Several window functions can be defined, based on a constant (rectangular window), B-splines, other polynomials, sinusoids, cosine-sums, adjustable, hybrid, and other types. The windowing operation consists of multipying the given sampled signal by the window function. For trading purposes, these FIR filters act as advanced weighted moving averages.
A finite impulse response (FIR) filter is a filter whose impulse response (or response to any finite length input) is of finite duration, because it settles to zero in finite time. This is in contrast to infinite impulse response (IIR) filters, which may have internal feedback and may continue to respond indefinitely (usually decaying).
The impulse response (that is, the output in response to a Kronecker delta input) of an Nth-order discrete-time FIR filter lasts exactly {\displaystyle N+1}N+1 samples (from first nonzero element through last nonzero element) before it then settles to zero.
FIR filters can be discrete-time or continuous-time, and digital or analog.
A FIR filter is (similar to, or) just a weighted moving average filter, where (unlike a typical equally weighted moving average filter) the weights of each delay tap are not constrained to be identical or even of the same sign. By changing various values in the array of weights (the impulse response, or time shifted and sampled version of the same), the frequency response of a FIR filter can be completely changed.
An FIR filter simply CONVOLVES the input time series (price data) with its IMPULSE RESPONSE. The impulse response is just a set of weights (or "coefficients") that multiply each data point. Then you just add up all the products and divide by the sum of the weights and that is it; e.g., for a 10-bar SMA you just add up 10 bars of price data (each multiplied by 1) and divide by 10. For a weighted-MA you add up the product of the price data with triangular-number weights and divide by the total weight.
What's a Low-Pass Filter?
A low-pass filter is the type of frequency domain filter that is used for smoothing sound, image, or data. This is different from a high-pass filter that is used for sharpening data, images, or sound.
Whats a Windowed-Sinc Filter?
Windowed-sinc filters are used to separate one band of frequencies from another. They are very stable, produce few surprises, and can be pushed to incredible performance levels. These exceptional frequency domain characteristics are obtained at the expense of poor performance in the time domain, including excessive ripple and overshoot in the step response. When carried out by standard convolution, windowed-sinc filters are easy to program, but slow to execute.
The sinc function sinc (x), also called the "sampling function," is a function that arises frequently in signal processing and the theory of Fourier transforms.
In mathematics, the historical unnormalized sinc function is defined for x ≠ 0 by
sinc x = sinx / x
In digital signal processing and information theory, the normalized sinc function is commonly defined for x ≠ 0 by
sinc x = sin(pi * x) / (pi * x)
For our purposes here, we are used a normalized Sinc function
Included Windowing Functions
N-Order Power-of-Cosine (this one is really N-different types of FIR filters)
Hamming
Hanning
Blackman
Blackman Harris
Blackman Nutall
Nutall
Bartlet Zero End Points
Bartlet-Hann
Hann
Sine
Lanczos
Flat Top
Rectangular
Linear
Triangular
If you wish to dive deeper to get a full explanation of these windowing functions, see here: en.wikipedia.org
Related indicators
STD-Filtered, Variety FIR Digital Filters w/ ATR Bands
STD/C-Filtered, N-Order Power-of-Cosine FIR Filter
STD/C-Filtered, Truncated Taylor Family FIR Filter
STD/Clutter-Filtered, Kaiser Window FIR Digital Filter
STD/Clutter Filtered, One-Sided, N-Sinc-Kernel, EFIR Filt
STD-Filtered, Variety FIR Digital Filters w/ ATR Bands [Loxx]STD-Filtered, Variety FIR Digital Filters w/ ATR Bands is a FIR Digital Filter indicator with ATR bands. This indicator contains 12 different digital filters. Some of these have already been covered by indicators that I've recently posted. The difference here is that this indicator has ATR bands, allows for frequency filtering, adds a frequency multiplier, and attempts show causality by lagging price input by 1/2 the period input during final application of weights. Period is restricted to even numbers.
The 3 most important parameters are the frequency cutoff, the filter window type and the "causal" parameter.
Included filter types:
- Hamming
- Hanning
- Blackman
- Blackman Harris
- Blackman Nutall
- Nutall
- Bartlet Zero End Points
- Bartlet Hann
- Hann
- Sine
- Lanczos
- Flat Top
Frequency cutoff can vary between 0 and 0.5. General rule is that the greater the cutoff is the "faster" the filter is, and the smaller the cutoff is the smoother the filter is.
You can read more about discrete-time signal processing and some of the windowing functions in this indicator here:
Window function
Window Functions and Their Applications in Signal Processing
What are FIR Filters?
In discrete-time signal processing, windowing is a preliminary signal shaping technique, usually applied to improve the appearance and usefulness of a subsequent Discrete Fourier Transform. Several window functions can be defined, based on a constant (rectangular window), B-splines, other polynomials, sinusoids, cosine-sums, adjustable, hybrid, and other types. The windowing operation consists of multipying the given sampled signal by the window function. For trading purposes, these FIR filters act as advanced weighted moving averages.
A finite impulse response (FIR) filter is a filter whose impulse response (or response to any finite length input) is of finite duration, because it settles to zero in finite time. This is in contrast to infinite impulse response (IIR) filters, which may have internal feedback and may continue to respond indefinitely (usually decaying).
The impulse response (that is, the output in response to a Kronecker delta input) of an Nth-order discrete-time FIR filter lasts exactly {\displaystyle N+1}N+1 samples (from first nonzero element through last nonzero element) before it then settles to zero.
FIR filters can be discrete-time or continuous-time, and digital or analog.
A FIR filter is (similar to, or) just a weighted moving average filter, where (unlike a typical equally weighted moving average filter) the weights of each delay tap are not constrained to be identical or even of the same sign. By changing various values in the array of weights (the impulse response, or time shifted and sampled version of the same), the frequency response of a FIR filter can be completely changed.
An FIR filter simply CONVOLVES the input time series (price data) with its IMPULSE RESPONSE. The impulse response is just a set of weights (or "coefficients") that multiply each data point. Then you just add up all the products and divide by the sum of the weights and that is it; e.g., for a 10-bar SMA you just add up 10 bars of price data (each multiplied by 1) and divide by 10. For a weighted-MA you add up the product of the price data with triangular-number weights and divide by the total weight.
What is a Standard Deviation Filter?
If price or output or both don't move more than the (standard deviation) * multiplier then the trend stays the previous bar trend. This will appear on the chart as "stepping" of the moving average line. This works similar to Super Trend or Parabolic SAR but is a more naive technique of filtering.
Included
Bar coloring
Loxx's Expanded Source Types
Signals
Alerts
Related indicators
STD/C-Filtered, N-Order Power-of-Cosine FIR Filter
STD/C-Filtered, Power-of-Cosine FIR Filter
STD/C-Filtered, Truncated Taylor Family FIR Filter
STD/Clutter-Filtered, Variety FIR Filters
STD/Clutter-Filtered, Kaiser Window FIR Digital Filter
STD/C-Filtered, N-Order Power-of-Cosine FIR Filter [Loxx]STD/C-Filtered, N-Order Power-of-Cosine FIR Filter is a Discrete-Time, FIR Digital Filter that uses Power-of-Cosine Family of FIR filters. This is an N-order algorithm that turns the following indicator from a static max 16 orders to a N orders, but limited to 50 in code. You can change the top end value if you with to higher orders than 50, but the signal is likely too noisy at that level. This indicator also includes a clutter and standard deviation filter.
See the static order version of this indicator here:
STD/C-Filtered, Power-of-Cosine FIR Filter
Amplitudes for STD/C-Filtered, N-Order Power-of-Cosine FIR Filter:
What are FIR Filters?
In discrete-time signal processing, windowing is a preliminary signal shaping technique, usually applied to improve the appearance and usefulness of a subsequent Discrete Fourier Transform. Several window functions can be defined, based on a constant (rectangular window), B-splines, other polynomials, sinusoids, cosine-sums, adjustable, hybrid, and other types. The windowing operation consists of multipying the given sampled signal by the window function. For trading purposes, these FIR filters act as advanced weighted moving averages.
What is Power-of-Sine Digital FIR Filter?
Also called Cos^alpha Window Family. In this family of windows, changing the value of the parameter alpha generates different windows.
f(n) = math.cos(alpha) * (math.pi * n / N) , 0 ≤ |n| ≤ N/2
where alpha takes on integer values and N is a even number
General expanded form:
alpha0 - alpha1 * math.cos(2 * math.pi * n / N)
+ alpha2 * math.cos(4 * math.pi * n / N)
- alpha3 * math.cos(4 * math.pi * n / N)
+ alpha4 * math.cos(6 * math.pi * n / N)
- ...
Special Cases for alpha:
alpha = 0: Rectangular window, this is also just the SMA (not included here)
alpha = 1: MLT sine window (not included here)
alpha = 2: Hann window (raised cosine = cos^2)
alpha = 4: Alternative Blackman (maximized roll-off rate)
This indicator contains a binomial expansion algorithm to handle N orders of a cosine power series. You can read about how this is done here: The Binomial Theorem
What is Pascal's Triangle and how was it used here?
In mathematics, Pascal's triangle is a triangular array of the binomial coefficients that arises in probability theory, combinatorics, and algebra. In much of the Western world, it is named after the French mathematician Blaise Pascal, although other mathematicians studied it centuries before him in India, Persia, China, Germany, and Italy.
The rows of Pascal's triangle are conventionally enumerated starting with row n = 0 at the top (the 0th row). The entries in each row are numbered from the left beginning with k=0 and are usually staggered relative to the numbers in the adjacent rows. The triangle may be constructed in the following manner: In row 0 (the topmost row), there is a unique nonzero entry 1. Each entry of each subsequent row is constructed by adding the number above and to the left with the number above and to the right, treating blank entries as 0. For example, the initial number in the first (or any other) row is 1 (the sum of 0 and 1), whereas the numbers 1 and 3 in the third row are added to produce the number 4 in the fourth row.
Rows of Pascal's Triangle
0 Order: 1
1 Order: 1 1
2 Order: 1 2 1
3 Order: 1 3 3 1
4 Order: 1 4 6 4 1
5 Order: 1 5 10 10 5 1
6 Order: 1 6 15 20 15 6 1
7 Order: 1 7 21 35 35 21 7 1
8 Order: 1 8 28 56 70 56 28 8 1
9 Order: 1 9 36 34 84 126 126 84 36 9 1
10 Order: 1 10 45 120 210 252 210 120 45 10 1
11 Order: 1 11 55 165 330 462 462 330 165 55 11 1
12 Order: 1 12 66 220 495 792 924 792 495 220 66 12 1
13 Order: 1 13 78 286 715 1287 1716 1716 1287 715 286 78 13 1
For a 12th order Power-of-Cosine FIR Filter
1. We take the coefficients from the Left side of the 12th row
1 13 78 286 715 1287 1716 1716 1287 715 286 78 13 1
2. We slice those in half to
1 13 78 286 715 1287 1716
3. We reverse the array
1716 1287 715 286 78 13 1
This is our array of alphas: alpha1, alpha2, ... alphaN
4. We then pull alpha one from the previous order, order 11, the middle value
11 Order: 1 11 55 165 330 462 462 330 165 55 11 1
The middle value is 462, this value becomes our alpha0 in the calculation
5. We apply these alphas to the cosine calculations
example: + alpha4 * math.cos(6 * math.pi * n / N)
6. We then divide by the sum of the alphas to derive our final coefficient weighting kernel
**This is only useful for orders that are EVEN, if you use odd ordering, the following are the coefficient outputs and these aren't useful since they cancel each other out and result in a value of zero. See below for an odd numbered oder and compare with the amplitude of the graphic posted above of the even order amplitude:
What is a Standard Deviation Filter?
If price or output or both don't move more than the (standard deviation) * multiplier then the trend stays the previous bar trend. This will appear on the chart as "stepping" of the moving average line. This works similar to Super Trend or Parabolic SAR but is a more naive technique of filtering.
What is a Clutter Filter?
For our purposes here, this is a filter that compares the slope of the trading filter output to a threshold to determine whether to shift trends. If the slope is up but the slope doesn't exceed the threshold, then the color is gray and this indicates a chop zone. If the slope is down but the slope doesn't exceed the threshold, then the color is gray and this indicates a chop zone. Alternatively if either up or down slope exceeds the threshold then the trend turns green for up and red for down. Fro demonstration purposes, an EMA is used as the moving average. This acts to reduce the noise in the signal.
Included
Bar coloring
Loxx's Expanded Source Types
Signals
Alerts
STD/C-Filtered, Power-of-Cosine FIR Filter [Loxx]STD/C-Filtered, Power-of-Cosine FIR Filter is a Discrete-Time, FIR Digital Filter that uses Power-of-Cosine Family of FIR filters. This indicator also includes a clutter and standard deviation filter.
Amplitudes
What are FIR Filters?
In discrete-time signal processing, windowing is a preliminary signal shaping technique, usually applied to improve the appearance and usefulness of a subsequent Discrete Fourier Transform. Several window functions can be defined, based on a constant (rectangular window), B-splines, other polynomials, sinusoids, cosine-sums, adjustable, hybrid, and other types. The windowing operation consists of multipying the given sampled signal by the window function. For trading purposes, these FIR filters act as advanced weighted moving averages.
What is Power-of-Sine Digital FIR Filter?
Also called Cos^alpha Window Family. In this family of windows, changing the value of the parameter alpha generates different windows.
f(n) = math.cos(alpha) * (math.pi * n / N) , 0 ≤ |n| ≤ N/2
where alpha takes on integer values and N is a even number
General expanded form:
alpha0 - alpha1 * math.cos(2 * math.pi * n / N)
+ alpha2 * math.cos(4 * math.pi * n / N)
- alpha3 * math.cos(4 * math.pi * n / N)
+ alpha4 * math.cos(6 * math.pi * n / N)
- ...
Special Cases for alpha:
alpha = 0: Rectangular window, this is also just the SMA (not included here)
alpha = 1: MLT sine window (not included here)
alpha = 2: Hann window (raised cosine = cos^2)
alpha = 4: Alternative Blackman (maximized roll-off rate)
For this indicator, I've included alpha values from 2 to 16
What is a Standard Devaition Filter?
If price or output or both don't move more than the (standard deviation) * multiplier then the trend stays the previous bar trend. This will appear on the chart as "stepping" of the moving average line. This works similar to Super Trend or Parabolic SAR but is a more naive technique of filtering.
What is a Clutter Filter?
For our purposes here, this is a filter that compares the slope of the trading filter output to a threshold to determine whether to shift trends. If the slope is up but the slope doesn't exceed the threshold, then the color is gray and this indicates a chop zone. If the slope is down but the slope doesn't exceed the threshold, then the color is gray and this indicates a chop zone. Alternatively if either up or down slope exceeds the threshold then the trend turns green for up and red for down. Fro demonstration purposes, an EMA is used as the moving average. This acts to reduce the noise in the signal.
Included
Bar coloring
Loxx's Expanded Source Types
Signals
Alerts
STD/C-Filtered, Truncated Taylor Family FIR Filter [Loxx]STD/C-Filtered, Truncated Taylor Family FIR Filter is a FIR Digital Filter that uses Truncated Taylor Family of Windows. Taylor functions are obtained by adding a weighted-cosine series to a constant (called a pedestal). A simpler form of these functions can be obtained by dropping some of the higher-order terms in the Taylor series expansion. If all other terms, except for the first two significant ones, are dropped, a truncated Taylor function is obtained. This is a generalized window that is expressed as:
(1 + K) / 2 + (1 - K) / 2 * math.cos(2.0 * math.pi *n / N) where 0 ≤ |n| ≤ N/2
Here k can take the values in the range 0≤k≤1. We note that the Hann 0 ≤ |n| ≤ window is a special case of the truncated Taylor family with k = 0 and Rectangular 0 ≤ |n| ≤ window (SMA) is a special case of the truncated Taylor family with k = 1.
Truncated Taylor Family of Windows amplitudes for this indicator with K = 0.5
This indicator also includes Standard Deviation and Clutter filtering.
What is a Standard Devaition Filter?
If price or output or both don't move more than the (standard deviation) * multiplier then the trend stays the previous bar trend. This will appear on the chart as "stepping" of the moving average line. This works similar to Super Trend or Parabolic SAR but is a more naive technique of filtering.
What is a Clutter Filter?
For our purposes here, this is a filter that compares the slope of the trading filter output to a threshold to determine whether to shift trends. If the slope is up but the slope doesn't exceed the threshold, then the color is gray and this indicates a chop zone. If the slope is down but the slope doesn't exceed the threshold, then the color is gray and this indicates a chop zone. Alternatively if either up or down slope exceeds the threshold then the trend turns green for up and red for down. Fro demonstration purposes, an EMA is used as the moving average. This acts to reduce the noise in the signal.
Included
Bar coloring
Loxx's Expanded Source Types
Signals
Alerts
STD/Clutter-Filtered, Variety FIR Filters [Loxx]STD/Clutter-Filtered, Variety FIR Filters is a FIR filter explorer. The following FIR Digital Filters are included.
Rectangular - simple moving average
Hanning
Hamming
Blackman
Blackman/Harris
Linear weighted
Triangular
There are 10s of windowing functions like the ones listed above. This indicator will be updated over time as I create more windowing functions in Pine.
Uniform/Rectangular Window
The uniform window (also called the rectangular window) is a time window with unity amplitude for all time samples and has the same effect as not applying a window.
Use this window when leakage is not a concern, such as observing an entire transient signal.
The uniform window has a rectangular shape and does not attenuate any portion of the time record. It weights all parts of the time record equally. Because the uniform window does not force the signal to appear periodic in the time record, it is generally used only with functions that are already periodic within a time record, such as transients and bursts.
The uniform window is sometimes called a transient or boxcar window.
For sine waves that are exactly periodic within a time record, using the uniform window allows you to measure the amplitude exactly (to within hardware specifications) from the Spectrum trace.
Hanning Window
The Hanning window attenuates the input signal at both ends of the time record to zero. This forces the signal to appear periodic. The Hanning window offers good frequency resolution at the expense of some amplitude accuracy.
This window is typically used for broadband signals such as random noise. This window should not be used for burst or chirp source types or other strictly periodic signals. The Hanning window is sometimes called the Hann window or random window.
Hamming Window
Computers can't do computations with an infinite number of data points, so all signals are "cut off" at either end. This causes the ripple on either side of the peak that you see. The hamming window reduces this ripple, giving you a more accurate idea of the original signal's frequency spectrum.
Blackman
The Blackman window is a taper formed by using the first three terms of a summation of cosines. It was designed to have close to the minimal leakage possible. It is close to optimal, only slightly worse than a Kaiser window.
Blackman-Harris
This is the original "Minimum 4-sample Blackman-Harris" window, as given in the classic window paper by Fredric Harris "On the Use of Windows for Harmonic Analysis with the Discrete Fourier Transform", Proceedings of the IEEE, vol 66, no. 1, pp. 51-83, January 1978. The maximum side-lobe level is -92.00974072 dB.
Linear Weighted
A Weighted Moving Average puts more weight on recent data and less on past data. This is done by multiplying each bar’s price by a weighting factor. Because of its unique calculation, WMA will follow prices more closely than a corresponding Simple Moving Average.
Triangular Weighted
Triangular windowing is known for very smooth results. The weights in the triangular moving average are adding more weight to central values of the averaged data. Hence the coefficients are specifically distributed. Some of the examples that can give a clear picture of the coefficients progression:
period 1 : 1
period 2 : 1 1
period 3 : 1 2 1
period 4 : 1 2 2 1
period 5 : 1 2 3 2 1
period 6 : 1 2 3 3 2 1
period 7 : 1 2 3 4 3 2 1
period 8 : 1 2 3 4 4 3 2 1
Read here to read about how each of these filters compare with each other: Windowing
What is a Finite Impulse Response Filter?
In signal processing, a finite impulse response (FIR) filter is a filter whose impulse response (or response to any finite length input) is of finite duration, because it settles to zero in finite time. This is in contrast to infinite impulse response (IIR) filters, which may have internal feedback and may continue to respond indefinitely (usually decaying).
The impulse response (that is, the output in response to a Kronecker delta input) of an Nth-order discrete-time FIR filter lasts exactly {\displaystyle N+1}N+1 samples (from first nonzero element through last nonzero element) before it then settles to zero.
FIR filters can be discrete-time or continuous-time, and digital or analog.
A FIR filter is (similar to, or) just a weighted moving average filter, where (unlike a typical equally weighted moving average filter) the weights of each delay tap are not constrained to be identical or even of the same sign. By changing various values in the array of weights (the impulse response, or time shifted and sampled version of the same), the frequency response of a FIR filter can be completely changed.
An FIR filter simply CONVOLVES the input time series (price data) with its IMPULSE RESPONSE. The impulse response is just a set of weights (or "coefficients") that multiply each data point. Then you just add up all the products and divide by the sum of the weights and that is it; e.g., for a 10-bar SMA you just add up 10 bars of price data (each multiplied by 1) and divide by 10. For a weighted-MA you add up the product of the price data with triangular-number weights and divide by the total weight.
Ultra Low Lag Moving Average's weights are designed to have MAXIMUM possible smoothing and MINIMUM possible lag compatible with as-flat-as-possible phase response.
What is a Clutter Filter?
For our purposes here, this is a filter that compares the slope of the trading filter output to a threshold to determine whether to shift trends. If the slope is up but the slope doesn't exceed the threshold, then the color is gray and this indicates a chop zone. If the slope is down but the slope doesn't exceed the threshold, then the color is gray and this indicates a chop zone. Alternatively if either up or down slope exceeds the threshold then the trend turns green for up and red for down. Fro demonstration purposes, an EMA is used as the moving average. This acts to reduce the noise in the signal.
Included
Bar coloring
Loxx's Expanded Source Types
Signals
Alerts
Related Indicators
STD/Clutter-Filtered, Kaiser Window FIR Digital Filter
STD- and Clutter-Filtered, Non-Lag Moving Average
Clutter-Filtered, D-Lag Reducer, Spec. Ops FIR Filter
STD-Filtered, Ultra Low Lag Moving Average
STD/Clutter-Filtered, Kaiser Window FIR Digital Filter [Loxx]STD/Clutter-Filtered, Kaiser Window FIR Digital Filter is an is FIR digital filter using Kaiser Windowing. I've also included a clutter filter to reduce signal noise.
What is a Kaiser Window?
The Kaiser window, also known as the Kaiser–Bessel window, was developed by James Kaiser at Bell Laboratories. It is a one-parameter family of window functions used in finite impulse response filter design and spectral analysis. The Kaiser window approximates the DPSS window which maximizes the energy concentration in the main lobe but which is difficult to compute. Kaiser windowing strikes a balance among the various conflicting goals of amplitude accuracy, side lobe distance, and side lobe height. Choosing this window will often reveal signals close to the noise floor that other windows may obscure. For this reason, many spectrum analyzers default to this window. For our purposes here, we use a the Kaiser–Bessel-derived (KBD) window, which is designed to be suitable for use with the modified discrete cosine transform (MDCT).
You can read more here: The Io-sinh function, calculation of Kaiser windows and design of FIR filters
Kaiser Window Amplitudes (not the default settings)
What is a Finite Impulse Response Filter?
In signal processing, a finite impulse response (FIR) filter is a filter whose impulse response (or response to any finite length input) is of finite duration, because it settles to zero in finite time. This is in contrast to infinite impulse response (IIR) filters, which may have internal feedback and may continue to respond indefinitely (usually decaying).
The impulse response (that is, the output in response to a Kronecker delta input) of an Nth-order discrete-time FIR filter lasts exactly {\displaystyle N+1}N+1 samples (from first nonzero element through last nonzero element) before it then settles to zero.
FIR filters can be discrete-time or continuous-time, and digital or analog.
A FIR filter is (similar to, or) just a weighted moving average filter, where (unlike a typical equally weighted moving average filter) the weights of each delay tap are not constrained to be identical or even of the same sign. By changing various values in the array of weights (the impulse response, or time shifted and sampled version of the same), the frequency response of a FIR filter can be completely changed.
An FIR filter simply CONVOLVES the input time series (price data) with its IMPULSE RESPONSE. The impulse response is just a set of weights (or "coefficients") that multiply each data point. Then you just add up all the products and divide by the sum of the weights and that is it; e.g., for a 10-bar SMA you just add up 10 bars of price data (each multiplied by 1) and divide by 10. For a weighted-MA you add up the product of the price data with triangular-number weights and divide by the total weight.
Ultra Low Lag Moving Average's weights are designed to have MAXIMUM possible smoothing and MINIMUM possible lag compatible with as-flat-as-possible phase response.
What is a Clutter Filter?
For our purposes here, this is a filter that compares the slope of the trading filter output to a threshold to determine whether to shift trends. If the slope is up but the slope doesn't exceed the threshold, then the color is gray and this indicates a chop zone. If the slope is down but the slope doesn't exceed the threshold, then the color is gray and this indicates a chop zone. Alternatively if either up or down slope exceeds the threshold then the trend turns green for up and red for down. Fro demonstration purposes, an EMA is used as the moving average. This acts to reduce the noise in the signal.
Included
Bar coloring
Loxx's Expanded Source Types
Signals
Alerts
Realed Indicators
STD/Clutter Filtered, One-Sided, N-Sinc-Kernel, EFIR Filt
STD- and Clutter-Filtered, Non-Lag Moving Average
Clutter-Filtered, D-Lag Reducer, Spec. Ops FIR Filter
STD-Filtered, Ultra Low Lag Moving Average
STD/Clutter Filtered, One-Sided, N-Sinc-Kernel, EFIR Filt [Loxx]STD/Clutter Filtered, One-Sided, N-Sinc-Kernel, EFIR Filt is a normalized Cardinal Sine Filter Kernel Weighted Fir Filter that uses Ehler's FIR filter calculation instead of the general FIR filter calculation. This indicator has Kalman Velocity lag reduction, a standard deviation filter, a clutter filter, and a kernel noise filter. When calculating the Kernels, the both sides are calculated, then smoothed, then sliced to just the Right side of the Kernel weights. Lastly, blackman windowing is used for our purposes here. You can read about blackman windowing here:
Blackman window
Advantages of Blackman Window over Hamming Window Method for designing FIR Filter
The Kernel amplitudes are shown below with their corresponding values in yellow:
This indicator is intended to be used with Heikin-Ashi source inputs, specially HAB Median. You can read about this here:
Moving Average Filters Add-on w/ Expanded Source Types
What is a Finite Impulse Response Filter?
In signal processing, a finite impulse response (FIR) filter is a filter whose impulse response (or response to any finite length input) is of finite duration, because it settles to zero in finite time. This is in contrast to infinite impulse response (IIR) filters, which may have internal feedback and may continue to respond indefinitely (usually decaying).
The impulse response (that is, the output in response to a Kronecker delta input) of an Nth-order discrete-time FIR filter lasts exactly {\displaystyle N+1}N+1 samples (from first nonzero element through last nonzero element) before it then settles to zero.
FIR filters can be discrete-time or continuous-time, and digital or analog.
A FIR filter is (similar to, or) just a weighted moving average filter, where (unlike a typical equally weighted moving average filter) the weights of each delay tap are not constrained to be identical or even of the same sign. By changing various values in the array of weights (the impulse response, or time shifted and sampled version of the same), the frequency response of a FIR filter can be completely changed.
An FIR filter simply CONVOLVES the input time series (price data) with its IMPULSE RESPONSE. The impulse response is just a set of weights (or "coefficients") that multiply each data point. Then you just add up all the products and divide by the sum of the weights and that is it; e.g., for a 10-bar SMA you just add up 10 bars of price data (each multiplied by 1) and divide by 10. For a weighted-MA you add up the product of the price data with triangular-number weights and divide by the total weight.
Ultra Low Lag Moving Average's weights are designed to have MAXIMUM possible smoothing and MINIMUM possible lag compatible with as-flat-as-possible phase response.
Ehlers FIR Filter
Ehlers Filter (EF) was authored, not surprisingly, by John Ehlers. Read all about them here: Ehlers Filters
What is Normalized Cardinal Sine?
The sinc function sinc (x), also called the "sampling function," is a function that arises frequently in signal processing and the theory of Fourier transforms.
In mathematics, the historical unnormalized sinc function is defined for x ≠ 0 by
sinc x = sinx / x
In digital signal processing and information theory, the normalized sinc function is commonly defined for x ≠ 0 by
sinc x = sin(pi * x) / (pi * x)
What is a Clutter Filter?
For our purposes here, this is a filter that compares the slope of the trading filter output to a threshold to determine whether to shift trends. If the slope is up but the slope doesn't exceed the threshold, then the color is gray and this indicates a chop zone. If the slope is down but the slope doesn't exceed the threshold, then the color is gray and this indicates a chop zone. Alternatively if either up or down slope exceeds the threshold then the trend turns green for up and red for down. Fro demonstration purposes, an EMA is used as the moving average. This acts to reduce the noise in the signal.
What is a Dual Element Lag Reducer?
Modifies an array of coefficients to reduce lag by the Lag Reduction Factor uses a generic version of a Kalman velocity component to accomplish this lag reduction is achieved by applying the following to the array:
2 * coeff - coeff
The response time vs noise battle still holds true, high lag reduction means more noise is present in your data! Please note that the beginning coefficients which the modifying matrix cannot be applied to (coef whose indecies are < LagReductionFactor) are simply multiplied by two for additional smoothing .
Included
Bar coloring
Loxx's Expanded Source Types
Signals
Alerts
STD- and Clutter-Filtered, Non-Lag Moving Average [Loxx]STD- and Clutter-Filtered, Non-Lag Moving Average is a Weighted Moving Average with a minimal lag using a damping cosine wave as the line of weight coefficients. The indicator has two filters. They are static (in points) and dynamic (expressed as a decimal). They allow cutting the price noise giving a stepped shape to the Moving Average. Moreover, there is the possibility to highlight the trend direction by color. This also includes a standard deviation and clutter filter. This filter is a FIR filter.
What is a Generic or Direct Form FIR Filter?
In signal processing, a finite impulse response (FIR) filter is a filter whose impulse response (or response to any finite length input) is of finite duration, because it settles to zero in finite time. This is in contrast to infinite impulse response (IIR) filters, which may have internal feedback and may continue to respond indefinitely (usually decaying).
The impulse response (that is, the output in response to a Kronecker delta input) of an Nth-order discrete-time FIR filter lasts exactly {\displaystyle N+1}N+1 samples (from first nonzero element through last nonzero element) before it then settles to zero.
FIR filters can be discrete-time or continuous-time, and digital or analog.
A FIR filter is (similar to, or) just a weighted moving average filter, where (unlike a typical equally weighted moving average filter) the weights of each delay tap are not constrained to be identical or even of the same sign. By changing various values in the array of weights (the impulse response, or time shifted and sampled version of the same), the frequency response of a FIR filter can be completely changed.
An FIR filter simply CONVOLVES the input time series (price data) with its IMPULSE RESPONSE. The impulse response is just a set of weights (or "coefficients") that multiply each data point. Then you just add up all the products and divide by the sum of the weights and that is it; e.g., for a 10-bar SMA you just add up 10 bars of price data (each multiplied by 1) and divide by 10. For a weighted-MA you add up the product of the price data with triangular-number weights and divide by the total weight.
What is a Clutter Filter?
For our purposes here, this is a filter that compares the slope of the trading filter output to a threshold to determine whether to shift trends. If the slope is up but the slope doesn't exceed the threshold, then the color is gray and this indicates a chop zone. If the slope is down but the slope doesn't exceed the threshold, then the color is gray and this indicates a chop zone. Alternatively if either up or down slope exceeds the threshold then the trend turns green for up and red for down. Fro demonstration purposes, an EMA is used as the moving average. This acts to reduce the noise in the signal.
What is a Dual Element Lag Reducer?
Modifies an array of coefficients to reduce lag by the Lag Reduction Factor uses a generic version of a Kalman velocity component to accomplish this lag reduction is achieved by applying the following to the array:
2 * coeff - coeff
The response time vs noise battle still holds true, high lag reduction means more noise is present in your data! Please note that the beginning coefficients which the modifying matrix cannot be applied to (coef whose indecies are < LagReductionFactor) are simply multiplied by two for additional smoothing .
Included
Bar coloring
Loxx's Expanded Source Types
Signals
Alerts
Clutter-Filtered, D-Lag Reducer, Spec. Ops FIR Filter [Loxx]Clutter-Filtered, D-Lag Reducer, Spec. Ops FIR Filter is a FIR filter moving average with extreme lag reduction and noise elimination technology. This is a special instance of a static weight FIR filter designed specifically for Forex trading. This is not only a useful indictor, but also a demonstration of how one would create their own moving average using FIR filtering weights. This moving average has static period and weighting inputs. You can change the lag reduction and the clutter filtering but you can't change the weights or the numbers of bars the weights are applied to in history.
Plot of weighting coefficients used in this indicator
These coefficients were derived from a smoothed cardinal sine weighed SMA on EURUSD in Matlab. You can see the coefficients in the code.
What is Normalized Cardinal Sine?
The sinc function sinc (x), also called the "sampling function," is a function that arises frequently in signal processing and the theory of Fourier transforms.
In mathematics, the historical unnormalized sinc function is defined for x ≠ 0 by
sinc x = sinx / x
In digital signal processing and information theory, the normalized sinc function is commonly defined for x ≠ 0 by
sinc x = sin(pi * x) / (pi * x)
What is a Generic or Direct Form FIR Filter?
In signal processing, a finite impulse response (FIR) filter is a filter whose impulse response (or response to any finite length input) is of finite duration, because it settles to zero in finite time. This is in contrast to infinite impulse response (IIR) filters, which may have internal feedback and may continue to respond indefinitely (usually decaying).
The impulse response (that is, the output in response to a Kronecker delta input) of an Nth-order discrete-time FIR filter lasts exactly {\displaystyle N+1}N+1 samples (from first nonzero element through last nonzero element) before it then settles to zero.
FIR filters can be discrete-time or continuous-time, and digital or analog.
A FIR filter is (similar to, or) just a weighted moving average filter, where (unlike a typical equally weighted moving average filter) the weights of each delay tap are not constrained to be identical or even of the same sign. By changing various values in the array of weights (the impulse response, or time shifted and sampled version of the same), the frequency response of a FIR filter can be completely changed.
An FIR filter simply CONVOLVES the input time series (price data) with its IMPULSE RESPONSE. The impulse response is just a set of weights (or "coefficients") that multiply each data point. Then you just add up all the products and divide by the sum of the weights and that is it; e.g., for a 10-bar SMA you just add up 10 bars of price data (each multiplied by 1) and divide by 10. For a weighted-MA you add up the product of the price data with triangular-number weights and divide by the total weight.
Ultra Low Lag Moving Average's weights are designed to have MAXIMUM possible smoothing and MINIMUM possible lag compatible with as-flat-as-possible phase response.
What is a Clutter Filter?
For our purposes here, this is a filter that compares the slope of the trading filter output to a threshold to determine whether to shift trends. If the slope is up but the slope doesn't exceed the threshold, then the color is gray and this indicates a chop zone. If the slope is down but the slope doesn't exceed the threshold, then the color is gray and this indicates a chop zone. Alternatively if either up or down slope exceeds the threshold then the trend turns green for up and red for down. Fro demonstration purposes, an EMA is used as the moving average. This acts to reduce the noise in the signal.
What is a Dual Element Lag Reducer?
Modifies an array of coefficients to reduce lag by the Lag Reduction Factor uses a generic version of a Kalman velocity component to accomplish this lag reduction is achieved by applying the following to the array:
2 * coeff - coeff
The response time vs noise battle still holds true, high lag reduction means more noise is present in your data! Please note that the beginning coefficients which the modifying matrix cannot be applied to (coef whose indecies are < LagReductionFactor) are simply multiplied by two for additional smoothing .
Things to note
Due to the computational demands of this indicator, there is a bars back input modifier that controls how many bars back the indicator is calculated on. Because of this, the first few bars of the indicator will sometimes appear crazy, just ignore this as it doesn't effect the calculation.
Related Indicators
STD-Filtered, Ultra Low Lag Moving Average
Included
Bar coloring
Loxx's Expanded Source Types
Signals
Alerts
STD-Filtered, Ultra Low Lag Moving Average [Loxx]STD-Filtered, Ultra Low Lag Moving Average is a FIR filter that smooths price using a low-pass filtering with weights derived from a normalized cardinal since function. This indicator attempts to reduce lag to an extreme degree. Try this on various time frames with various Type inputs, 0 is the default, so see where the sweet spot is for your trading style.
What is a Finite Impulse Response Filter?
In signal processing, a finite impulse response (FIR) filter is a filter whose impulse response (or response to any finite length input) is of finite duration, because it settles to zero in finite time. This is in contrast to infinite impulse response (IIR) filters, which may have internal feedback and may continue to respond indefinitely (usually decaying).
The impulse response (that is, the output in response to a Kronecker delta input) of an Nth-order discrete-time FIR filter lasts exactly {\displaystyle N+1}N+1 samples (from first nonzero element through last nonzero element) before it then settles to zero.
FIR filters can be discrete-time or continuous-time, and digital or analog.
A FIR filter is (similar to, or) just a weighted moving average filter, where (unlike a typical equally weighted moving average filter) the weights of each delay tap are not constrained to be identical or even of the same sign. By changing various values in the array of weights (the impulse response, or time shifted and sampled version of the same), the frequency response of a FIR filter can be completely changed.
An FIR filter simply CONVOLVES the input time series (price data) with its IMPULSE RESPONSE. The impulse response is just a set of weights (or "coefficients") that multiply each data point. Then you just add up all the products and divide by the sum of the weights and that is it; e.g., for a 10-bar SMA you just add up 10 bars of price data (each multiplied by 1) and divide by 10. For a weighted-MA you add up the product of the price data with triangular-number weights and divide by the total weight.
Ultra Low Lag Moving Average's weights are designed to have MAXIMUM possible smoothing and MINIMUM possible lag compatible with as-flat-as-possible phase response.
What is Normalized Cardinal Sine?
The sinc function sinc(x), also called the "sampling function," is a function that arises frequently in signal processing and the theory of Fourier transforms.
In mathematics, the historical unnormalized sinc function is defined for x ≠ 0 by
sinc x = sinx / x
In digital signal processing and information theory, the normalized sinc function is commonly defined for x ≠ 0 by
sinc x = sin(pi * x) / (pi * x)
How this works, (easy mode)
1. Use a HA or HAB source type
2. The lower the Type value the smoother the moving average
3. Standard deviation stepping is added to further reduce noise
Included
Bar coloring
Signals
Alerts
Loxx's Expanded Source Types
TASC 2022.01 Improved RSI w/Hann█ OVERVIEW
TASC's January 2022 edition Traders' Tips includes the "(Yet Another Improved) RSI Enhanced With Hann Windowing" article authored by John Ehlers. Once again John Ehlers revolutionizes the RSI indicator. This is TradingView's Pine Script code for the indicator.
█ CONCEPTS
By employing a Hann windowed finite impulse response filter ( FIR ), John Ehlers has enhanced the "Relative Strength Indicator" ( RSI ) to provide an improved oscillator with exceptional smoothness.
█ NOTES
Calculations
The method of calculations using "closes up" and "closes down" from Welles Wilder's RSI described in his 1978 book is still inherent to Ehlers enhanced formula. However, a finite impulse response (FIR) Hann windowing technique is employed following the closes up/down calculations instead of the original Wilder infinite impulse response averaging filter. The resulting oscillator waveform is confined between +/-1.0 with a 0.0 centerline regardless of chart interval, as opposed to Wilder's original formulation, which was confined between 0 and 100 with a centerline of 50. On any given trading timeframe, the value of Ehlers' enhanced RSI found above the centerline typically represents an overvalued region, while undervalued regions are typically found below the centerline.
Background
The original RSI indicator was designed by J. Welles Wilder and presented in his "New Concepts in Technical Trading Systems" book published in 1978.
Join TradingView!
FIR Hann Window Indicator (Ehlers)From Ehlers' Windowing article:
"A still-smoother weighting function that is easy to program is called the Hann window. The Hann window is often described as a “sine squared” distribution, although it is easier to program as a cosine subtracted from unity. The shape of the coefficient outline looks like a sinewave whose valleys are at the ends of the array and whose peak is at the center of the array. This configuration offers a smooth window transition from the smallest coefficient amplitude to the largest coefficient amplitude."
Ported from: { TASC SEP 2021 FIR Hann Window Indicator } (C) 2021 John F. Ehlers
Stocks & Commodities V. 39:09 (8–14, 23): Windowing by John F. Ehlers
Original code found here: traders.com
FIR Chart: traders.com
ROC Chart: traders.com
Ehlers style implementation mostly maintained for easy verification.
Added optional ROC display.
Style and efficiency updates + Hann windowing as a function coming soon.
Indicator added twice to chart show both FIR and ROC.
Computing FIR Filters Using Arrays [WMA Example]Over the years, many FIR filters have been proposed by the Pine community, with the standard way of computing them being `for` loops. The arrival of arrays allows for a new, more efficient way to compute them.
This script provides a template showing how you can compute FIR filters using Pine arrays.
FIR Filters
FIR stands for "Finite Impulse Response", and is associated with types of filters whose impulse response reaches a steady state.
FIR filters are calculated using convolution, or more simply put, using a weighted sum between a set of filter coefficients and past input values over a finite window.
In Pine, FIR filters are generally computed inside a `for` loop executing three processes:
1- Computing the coefficients.
2- Summing all the computed coefficients.
3- Performing the weighted sum between the inputs values and the computed coefficients.
Then we divide the result of our weighted sum by the sum of the coefficients obtained in step 2.
Because the computations inside the `for` loop execute on each bar, execution time can be significant when the calculation of coefficients is complex. This is where arrays are handy, as we can compute the coefficients just once, store them into an array, and use them in a weighted sum without the need to recalculate them over and over. This drastically reduces the computation time required to calculate a FIR filter.
The new `array.sum()` function helps eliminate step 2, thus further decreasing computation time.
How to Use This Template
All you need to do is to put the code that computes your coefficients in the first `for` loop (variable `w`). If the code that computes your coefficients contains more than one line, just make sure your final coefficient is placed in variable `w` (or change the `value` argument in `array.push()`). Another option is to declare a function that computes the coefficients and use it instead of variable `w`.
Look first. Then leap.
Blackman Filter - The Smoother The BetterIntroduction
Who doesn't like smooth things? I'd like a smooth market price for christmas! But i can't get it, instead its so noisy...so you apply a filter to smooth it, such filters are called low-pass filters, they smooth and its great but they have lag, so nobody really use them, but they are pretty to look at.
Its on a childish note that i will introduce this indicator, so what it is all about? I propose a new FIR filter using a blackman function as filter kernel for financial time-series smoothing, do you prefer the childish tone ? Fear not its surprisingly easy!
The Blackman Function
The blackman function look like a bell shaped curve, look:
The blackman function will produce such curve. This function is called a cosine sum function because she is based on the sum of cosine functions, here only 2.
0.42 - 0.5 * cos(2 * pi * k) + 0.08 * cos(4 * pi * k)
Originally you use this function for windowing , what does it means? In signal processing you have a function called sync function , if you use this function as filter kernel you would get the ideal frequency domain response filter, sometime called brickwall filter, it would be extremely smooth.
Above the optimal low pass filter frequency response.
However the sync function has no ending values and goes on forever, therefore we can't use it for convolution, expect if we apply windowing. Filters using windowing are called windowed-sinc filters, i will describe the procedure below :
1 - Create a sync function = sin(pi*n)/(pi*n)
2 - Truncate it = I only keep the first length points of the sync function.
This create a abrupt end, the frequency of a filter using step 1 as kernel would contain ripples in the pass band and stop band, this is bad! The frequency response would look like this :
3 - I multiply my values of step 2 by a window function, it can the blackman window, i no longer have an abrupt end, its smooth!
The frequency response of the filter using this kernel would no longer have ripples! This is the power of windowing functions.
Here we are not using such thing, but we could in the future. Here instead we use the blackman function as filter kernel, because this function is bell shaped this mean that the filter will certainly be smooth (symmetrical weighting is a rule of thumb for kernels when we want really smooth filters).
The Filter
This filter is quite smooth, unlike the gaussian filter this filter give less weights to recent and past values, this is because the blackman function has fatter tails than the gaussian one. I could make a comparison of both, however they are quite alike, if you often use a gaussian filter its up to you to decide which one you prefer.
The filter can do a better job than the moving average when it comes to preserve the frequency components that constitute the cycles/trend.
We can see that the filter has a greater performance when it comes to keep the shape of the market price, thus it has a slightly better fit.
Conclusion
Ok so in this post you learned a bit about the sync function and windowing, those are basic subjects in signal processing, they allow us to approximate the filter with the ideal frequency response, i also showed you that those windowing function could be used as kernel and that they where pretty smooth on their own, there are many others, but the one i prefer is the blackman windowing function.
I know what you are thinking, "we want trailing stops, alerts, colors, arrows!", and i understand you pal, but sometimes its cool to take a break from all this stuff. However i can tell that i'am working on a side project that aim to estimate rolling maximum/minimum as fast as possible, any experiments will be published here, and i can ensure you that those indicators will make your day quite brighter, we will see that soon.
I hope you learned something from this post! I'am a bit tired (look i'am disappearing !)
Thanks for reading !
Hybrid Convolution FilterIntroduction
Today i propose an hybrid filter that use a classical FIR architecture while using recursion. The proposed method aim to reduce the lag generated by fir filters. This particular filter is a sine weighted moving average, but you can change it since the indicator is built with the custom filter template (1). Even if it use recursion it still is a FIR filter since the impulse response is finite.
The Indicator
In red the hybrid swma and in blue the classic swma of both the same period. The difference can be seen.
The switch between the input price and the past values of the previous convolution values is made by using exponential averaging, the window function is the same as f(x) in the code.
Any filter can use this architecture, the indicator is built around the custom fir template, see (1)
Conclusion
I presented a FIR filter using recursion in its calculation, the integration is made with respect to the proposed template, therefore any user can simply modify f(x) to have different filter without the need to make any change. However curious users might want to change the window function of the exponential averager, in order to do so change sgn = f(i/length) in line 11 for sgn = fun(i/length) where fun is your custom function, make sure to add it at the start of the script where all the other functions declarations are.
Thanks for reading !
(1)
Template For Custom FIR Filters - Make Your Moving AverageIntroduction
FIR filters (finite impulse response) are widely used in technical analysis, there is the simple or arithmetic moving average, the triangular, the weighted, the least squares...etc. A FIR filter is characterized by the fact that its impulse response (the output of a filter using an impulse as input) is finite, this mean that the impulse response won't have infinite outputs unlike IIR filters.
They are extremely simple to design to, even without the Fourier transform, this is why i post this template that will let you create custom filters from step responses. Don't hesitate to post your results.
How It Works
Originally you create your filters from the frequency response you want your filter to have, this is because the inverse Fourier transform of the frequency response is the filter impulse response.
After that step you use convolution (convolution is the sum of the product between the signal and the impulse response) and you will have your filter. But we don't have Fourier transforms in pine so how can we possibly make FIR filters from convolution ? Well here the thing, the impulse response is the derivative of the step response and the step response is the sum of the impulse response, this mean we can create filters from step responses.
Step response of a moving average.
Step responses are easy to design, you just need a function that start at 0 and end up at 1.
How To Use The Template
All the work is done for you, the only thing you need to do is to enter your function at line 5 :
f(x)=> your function
For example if you want your filter to have a step response equal to sqrt(x) just enter :
f(x)=> sqrt(x)
This will give the following filter output :
You can create custom step responses from online graphing tools like fooplot or wolfram alpha, i recommend fooplot.
You can also design your filter step response from the line 14/15/16, b will be your filter step response, just use a , for example b = pow(a,2) , then replace output in plot by b and use overlay false, you can also plot step , if you like your step response copy the content of b and paste after f(x) => .
Filter Characteristics
The impulse response determine how many of a certain signal you want in your filter, this is also called weighting, you can think of filter design as cooking where your ingredients are the the signal at different periods and the impulse response determine how many of an ingredient you must include in the recipe. The step response can also tell you about your filter characteristics, for example :
This one converge faster to the step function, this mean that the filter will have less lag.
However this one converge slower to the step function, this mean the filter might have more lag but could be smoother.
Be aware that you must find a good weighting balance, else you can have output equals to the signal or just a delayed version of the signal without smoothing.
Real Case
Lets design a sine weighted moving average (swma), this FIR filter use the first 180 degrees of a sine wave function as impulse response.
Impulse response of the swma.
We can design it from the step response without much problems, remember that the impulse response is the derivative of the step response, therefore the derivative of the step response is equal to the first 180 degrees of a sine wave, the derivative of the cosine function is a sine function, therefore :
f(x)=> .5*(1 - cos(x*pi))
And voila.
Designing A BandPass Filter
The bandpass filter like a low-pass and high pass filter, you can think of it as a smooth oscillator.
To design a bandpass filter your step response must be bell shaped, or starting at 0 and ending at 0, for example :
f(x)=>sin(x*pi) give :
Conclusion
Just use fooplot and experiment, you could get nice filters, i will try to post some using this template but it would be really nice to have other people use it. If you need further help pm me.
Thanks for reading !
Finite Impulse Response (FIR) FilterFinite Impulse Response (FIR) Filter indicator script.
This indicator was originally developed by John F. Ehlers (Stocks & Commodities V. 20:7 (26-31): Zero-Lag Data Smoothers).
NOTE: Ehlers' favorite FIR filter had 1, 2, 3, 3, 2, 1, 0 coefficients.