StatisticalPine Script v6

ta.mode()Mode

Returns the mode (most frequent value) of a series over a given number of bars.

TradingView language reference

Syntax

Syntax
ta.mode(source, length) → series int / series float

Arguments

ParameterTypeDescription
sourceseries int/floatSeries of values to process.
lengthseries intNumber of bars in the rolling window.

Returns

Mode of source for length bars back.

Remarks

na values in the source series are ignored.

Code Examples

Pine Script v6 Example
//@version=6
indicator("ta.mode", overlay=true)
plot(ta.mode(close, 30))

Trading Applications

Find the most frequent price level (potential support/resistance)

Identify price clustering zones

Count repeated source values; this does not measure volume at price

Detect consolidation price levels

Related Functions

Frequently Asked Questions

ta.mode() estimates the most frequently occurring value in the rolling window (after na removal), highlighting where price has clustered.

Mode counts exact source values in the sampled bars, not nearby price bins or traded volume. With many distinct closes, the tie rule can determine the result; it is not evidence that a level will attract or stop price.

Pine returns the smallest value among values tied for the highest frequency. If every observation occurs once, the smallest value wins; that does not establish a meaningful price cluster.

Generate ta.mode() Code with AI

Draft Pine Script using ta.mode() 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.