Percentile
systemic:core-percStatisticsInputs
| Name | Type | Description |
|---|---|---|
| Percentile | Whole number | The percentile to compute on each subset, a whole number from 1 to 100. |
| Data | Number series | The series of numbers to analyze. |
Outputs
| Name | Type | Description |
|---|---|---|
| Percentile | Number series | For each bar, the chosen percentile of all values in the series that are less than or equal to that bar's value. |
Cost
0.194 + 0.0119·n + 0.0000000734·n² credits for n bars, rounded up. The marks are each plan's limit of bars.
The Percentile module computes a conditional quantile for each bar of a series. For every value, it keeps only the values of the whole series that are less than or equal to it. It then computes the chosen percentile of that subset.
Where is the -th percentile, and is the Percentile input (1 to 100).
How It Works
flowchart TD
subgraph Input["Input Data"]
D["Data: [10, 25, 15, 30, 20]"]
P["Percentile: 50"]
end
subgraph Process["For Each Value"]
V["Current value = 25"]
F["Filter: values ≤ 25<br/>[10, 25, 15, 20]"]
Q["Compute 50th percentile<br/>of filtered set"]
end
subgraph Output["Result"]
R["Output = 17.5"]
end
D --> V
P --> Q
V --> F --> Q --> R
Step by step for one bar:
- Take the current value (e.g., 25)
- Keep the values of the whole series that are ≤ 25: [10, 25, 15, 20]
- Compute the chosen percentile (e.g., 50th) of that subset
- Result: 17.5 (the median of [10, 15, 20, 25])
The same steps repeat for every bar in the series.
Understanding the Percentile Parameter
The Percentile input (1–100) sets which percentile to compute on the subset:
| Percentile | Meaning |
|---|---|
| 25 | First quartile of values ≤ current |
| 50 | Median of values ≤ current |
| 75 | Third quartile of values ≤ current |
| 100 | Maximum of values ≤ current (equals current value) |
⚠️ Important: This is not a percentile rank (how the current value ranks against history). It is a percentile of a subset that changes with each value.
Practical Applications
1. Dynamic Support Level Detection
With a low Percentile (e.g., 25), the output approximates a dynamic support level: the lower quartile of all values that are not above the current price:
flowchart LR
subgraph Concept["Support Level Logic"]
Price["Current Price"]
Filter["Values ≤ Price"]
Q25["25th Percentile"]
Support["Dynamic Support"]
end
Price --> Filter --> Q25 --> Support
2. Distribution Analysis
Compare the outputs at different Percentile settings:
| Setting | Interpretation |
|---|---|
| PERC(25) vs PERC(75) | The spread of the lower values shows how skewed the distribution is |
| PERC(50) | The middle of the subset |
| PERC(100) | Always equals the input |
3. Conditional Median Tracking
PERC(50) gives the median of all values that are not above each value. It shows where the "typical" lower value sits relative to each observation:
flowchart TD
subgraph Strategy["Conditional Median Strategy"]
Data["Price Series"]
PERC50["PERC(50)"]
Compare{"Price > PERC(50)?"}
Above["Above conditional median<br/>Relative strength"]
Below["At or below<br/>conditional median"]
end
Data --> PERC50 --> Compare
Compare -->|Yes| Above
Compare -->|No| Below
Example Walkthrough
Take the data series [100, 80, 120, 90, 110] with Percentile = 50:
| Index | Current Value | Filtered Set (≤ current) | 50th Percentile | Output |
|---|---|---|---|---|
| 0 | 100 | [100, 80, 90] | 90 | 90.0 |
| 1 | 80 | [80] | 80 | 80.0 |
| 2 | 120 | [100, 80, 120, 90, 110] | 100 | 100.0 |
| 3 | 90 | [80, 90] | 85 | 85.0 |
| 4 | 110 | [100, 80, 90, 110] | 95 | 95.0 |
Note: The filter uses the whole series, not only earlier values.
Key Characteristics
Whole-series analysis: The filter looks at all bars, not a rolling window. Each output depends on the whole input series.
Outputs depend on the distribution: How far the output sits below the input depends on the values in the subset.
Boundary behavior:
- At Percentile = 100, the output always equals the input (the largest value ≤ a value is the value itself)
- At Percentile = 1, the output is close to the lowest value in the series for most inputs
Advantages
- Context-aware — The output describes the distribution below each observation
- Flexible — Different Percentile settings show different aspects of the data
- Non-parametric — No assumption about the shape of the distribution
Limitations
- Not intuitive — The conditional filter is different from a standard percentile rank
- Uses later data — see Non-Causality below
- Sensitive to outliers — Extreme values change which values fall in each subset
Non-Causality
This module is not a running or rolling percentile. Every output is computed against the whole series of the run, including bars that come after it. The output on a past bar can change when later data changes its subset. Past outputs therefore use information that was not known at the time and are not tradeable signals. Only the newest bar's output uses no later data. Do not backtest a strategy that reacts to past PERC values: the result would not match what was knowable on those bars.
Missing Data
An empty (null) value in the data series is left out of every subset. It is never counted as zero or replaced by an earlier value. On the bar where the value itself is empty, the output is empty; no other bar is affected.