ta.median()Median
Returns the median (middle value) of a series over a given number of bars.
Syntax
ta.median(source, length) → series floatArguments
| Parameter | Type | Description |
|---|---|---|
| source | series int/float | Series of values to process. |
| length | series int | Number of bars in the rolling window. |
Returns
Median of source for length bars back.
Remarks
na values in the source series are ignored.
Code Examples
//@version=6
indicator("ta.median", overlay=true)
plot(ta.median(close, 20))
plot(ta.sma(close, 20), color=color.new(color.orange, 0))Trading Applications
Calculate median price for robust trend analysis
Build outlier-resistant moving averages
Create median-based channel indicators
Use for non-parametric price analysis
Frequently Asked Questions
Generate ta.median() Code with AI
Draft Pine Script using ta.median() with Pineify's AI Coding Agent, then review the arguments and test the result on your chart. Usage depends on your plan and available credits.
Related Pine Script Functions
ta.mode() - Mode
Learn how to use ta.mode() in Pine Script. Find the most frequent value in a series.
ta.sma() - Simple Moving Average
Learn how to use ta.sma() in Pine Script. Syntax, parameters, code examples, and trading applications for the Simple Moving Average function.
ta.percentrank() - Percent Rank
Learn how to use ta.percentrank() in Pine Script. Calculate percentile ranking of current value.
ta.percentile_linear_interpolation()
Learn how to use ta.percentile_linear_interpolation() in Pine Script. Calculate percentiles using linear interpolation.
ta.stdev() - Standard Deviation
Learn how to use ta.stdev() in Pine Script. Syntax, parameters, code examples for statistical standard deviation calculation.