Transformation filters

The following functions filter or transform a data series to a different range.

AGC(vars Data, int TimePeriod): var

AGC(vars Data, var alpha): var

Automatic gain control for filters or oscillator indicators, by John Ehlers. Transforms the Data series to the -1 .. +1 range with a fast-attack, slow-decay algorithm. TimePeriod determines the time for reducing the gain by 1.5 db; alternatively, alpha determines the reduction factor per bar period (< 1). Adjustment to higher values happens immediately. The minimum length of the Data series is 1. The function internally creates series and thus must be called in a fixed order in the script. Source available in indicators.c.

Fisher(vars Data): var

Fisher Transform; transforms a normalized Data series to a normal distributed range. The return value has no theoretical limit, but most values are between -1 .. +1. All Data values must be in the -1 .. +1 range, f.i. by normalizing with the AGC or Normalize function. The minimum Data length is 1. Source available in indicators.c.

FisherInv(vars Data): var

Inverse Fisher Transform; compresses the Data series to be between -1 and +1. The minimum length of the Data series is 1. Source available in indicators.c.

FisherN(vars Data, int TimePeriod): var

Fisher Transform with normalizing; normalizes the Data series with the given TimePeriod and then transforms it to a normal distributed range. Similar to a Normalize filter (see below), but more selective due to the normal distribution of the output. The return value has no theoretical limit, but most values are in the -1.5 .. +1.5 range. The minimum length of the Data series is equal to TimePeriod. The function internally creates series and thus must be called in a fixed order in the script. Source available in indicators.c.

Gauss(vars Data, int TimePeriod): var

Gauss Filter, returns a weighted average of the data within the given time period, with the weight curve equal to the Gauss Normal Distribution. Useful for removing noise by smoothing raw data. The minimum length of the Data series is equal to TimePeriod, the lag is half the TimePeriod.

Laguerre(vars Data, var alpha): var

4-element Laguerre filter. Used for smoothing data similar to an EMA, but with less lag and a wide tuning range given by the smoothing factor alpha (0..1). The low frequency components are delayed much more than the high frequency components, which enables very smooth filters with only a short amount of data. The minimum length of the Data series is 1, the minimum lookback period is 4. The function internally creates series and thus must be called in a fixed order in the script. Source available in indicators.c.

Median(vars Data, int TimePeriod): var

Median Filter; sorts the elements of the Data series and returns their middle value within the given time period. Useful for removing noise spikes by eliminating extreme values. The minimum length of the Data series is equal to TimePeriod, the lag is half the TimePeriod.

Normalize(vars Data, int TimePeriod): var

Transforms the Data series to the -1...+1 range within the given TimePeriod. Similar to the AGC function, but does not differentiate between attack and decay. The minimum length of the Data series is equal to TimePeriod. Source available in indicators.c.
 

Standard parameters:

TimePeriod Number of bars for the time period of the function.
Data A data series, often directly derived from the price functions price(), priceClose() etc.. Alternatively a user created series or any other double float array with the given minimum length can be used. If not mentioned otherwise, the minimum length of the Data series is TimePeriod.

Returns:

Filtered or transformed value from the Data series.

Remarks:

Examples:

// plot a filter
function run()
{
  set(PLOTNOW);
  vars Price = series(price());
  plot("Median",Median(Price,10),0,BLUE);
}

See also:

indicators, spectral filters

► latest version online