ta.winsorize
Clip a value to the tails of its own recent range to limit outliers.
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.
| Name | Kind | Type | Default | Range | Description |
|---|---|---|---|---|---|
source | Series | number | - | - | The series to read. |
length | Constant | number | - | 1 to 10000 | Window in observed bars. |
percentage | Constant | number | 5 | 0 to 50 | How much of each tail to pull in, 0 to 50. 5 clips to the 5th and 95th percentiles. |
min | Constant | number | - | 1 to 10000 | Valid 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
| Name | Type |
|---|---|
value | number |
Warm-up and missing values
- Warm-up
lengthbars. Names in the warm-up are this operator’s parameters.- Missing values
- Returns na until
lengthconsecutive 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
ta.winsorize(ta.ret(close), 100, 5)plot(ta.winsorize(ta.ret(close), 100, 5), "Winsorized return")