Returns the median of source over the last length bars: the middle value of the sorted window.
ta.median sorts the window and returns the middle value. With an even window length, it averages the two middle values.
A single extreme bar cannot drag the median the way it moves a mean. A value is produced from the point the window holds length bars.
Syntax
ta.median(source: series int/float, length: series int) -> series float
ta.median(source: series int, length: series int) -> series intArguments
| Name | Type | Default | Description |
|---|---|---|---|
| source | series int/ | required | Series to take the median of. |
| length | series int | required | Number of bars in the window. A whole number of 1 or more. |
Returns
series float or series int: the median of the window, or na while it is not full.
Remarks
- Use it as a spike-resistant alternative to
ta.smaon noisy data.
Example
//@version=6
indicator("Median vs SMA", overlay = true)
plot(ta.median(close, 15), "Median", color = color.blue, linewidth = 2)
plot(ta.sma(close, 15), "SMA", color = color.orange)See also
Runs on Sidechair