Syntax
public FIR(DataSeries source, string weights, string description)
public static FIR Series(WealthLab.DataSeries source, string weights)
public static double Value(int bar, DataSeries source, params double weightValues)
public static double Value(int bar, DataSeries source, string weights)
Parameter Description
source |
Price series |
weights |
Weights as string e.g. "1,2,2,1" |
weights |
Alternatively, specify weights as double[] array |
Warning! |
Weights must not sum to zero (e.g. -1, -2, 2, 1 would result in error). |
Description
FIR stands for Finite Impulse Response Filter. This is a type of smoothing filter that assigns different weights to price data a number of bars in the past. Pass the Price Series you want to apply the filter to in the first parameter. The second parameter of the FIR is a string that describes the weights that will be applied to the bars of data that compose the filter. The string is formatted as a series of numbers separated by commas.
Interpretation
FIR filters are nothing more than another type of weighted moving average, with different weight levels applied to the various components of the average. As such, you can apply any of the various interpretations of moving averages to FIR.
Calculation
A simple example will make this concept easier to explain. Assume we pass the string value of "1,2,3,4" as the second parameter to FIR, and apply it to closing prices. The function will perform the following calculation:
( ( 1 * Close
bar-3) + ( 2 * Close
bar-2 ) + ( 3 * Close
bar-1 ) + ( 4 x Close
bar) ) / 10
As you can see, each weighting is multiplied by the closing price of the respective lookback bar. The final sum of the weighted price values is divided by the sum of the weights.
Example
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using WealthLab;
using WealthLab.Indicators;
namespace WealthLab.Strategies
{
public class MyStrategy : WealthScript
{
protected override void Execute()
{
// A FIR is used as a signal line for a 200 day moving average
DataSeries SMASer = SMA.Series( Close, 200 );
PlotSeries( PricePane, SMASer, Color.Olive, WealthLab.LineStyle.Solid, 2 );
PlotSeries( PricePane, FIR.Series( SMASer, "1,2,2,1" ), Color.Black, WealthLab.LineStyle.Solid, 1 );
}
}
}