Docs

ta.winsorize

Clip a value to the tails of its own recent range to limit outliers.

itm
ta.winsorize(source, length, percentage, min=length)

The current observation clipped to its own window's percentage and (100 - percentage) percentiles, both linearly interpolated as ta.percentile takes them. The window includes the current observation. This is the data-driven ta.clip. Use it before a regression, because it pulls an outlier to the edge of the recent distribution instead of to a number you guessed.

Parameters

A series parameter takes a value on every bar. A constant parameter must be known before the first bar, such as a number or an input.

NameKindTypeDefaultRangeDescription
sourceSeriesnumber--The series to read.
lengthConstantnumber-1 to 10000Window in observed bars.
percentageConstantnumber50 to 50How much of each tail to pull in, 0 to 50. 5 clips to the 5th and 95th percentiles.
minConstantnumber-1 to 10000Valid values the window must hold before it reports (an option, written min=15). An na is skipped. Absent = length: the window must be full and gap-free.

Output

NameType
valuenumber

Warm-up and missing values

Warm-up
length bars. Names in the warm-up are this operator’s parameters.
Missing values
Returns na until length consecutive non-na observations are in the window. An na resets the accumulation. With min=, an na is skipped and the value is taken over the valid observations once there are at least min of them. A bar whose own value is na stays na.

Example

itm
ta.winsorize(ta.ret(close), 100, 5)
itm
plot(ta.winsorize(ta.ret(close), 100, 5), "Winsorized return")