Percentile Linear Interpolation (pli)
[[pli]] returns the percentage percentile of its source over the last length values. The block sorts the window from lowest to highest and produces a numeric series at the chosen position in that ordering. A percentile of 0 corresponds to the bottom of the window, 50 to its median, and 100 to its top.
When the requested position falls between two sorted values, the block interpolates linearly instead of selecting either one. The output can therefore be a value that does not appear in the window, but it always lies between the two observations that bracket the percentile.
Block declaration
A strategy can contain multiple [[pli]] blocks. Each block produces one numeric series: the requested percentile of the source over the configured window.
Examples
Minimal setup
This block computes the 50th percentile, the median, of close over 20 candles. Because source is omitted, the block uses the default value "close".
[[pli]]
id = "pli"
length = 20
percentage = 50Specific source
This block computes the same median on the hl2 source (the average of the high and the low) rather than on close.
[[pli]]
id = "pli"
source = "hl2"
length = 20
percentage = 50Source from another indicator
This block takes the 90th percentile of the series produced by the rsi block over 50 candles, a slow upper reference that recent RSI values rarely exceed.
[[rsi]]
id = "rsi"
length = 14
[[pli]]
id = "rsi_p90"
source = "rsi"
length = 50
percentage = 90Finding the optimal length
This block explores a range of values for length to identify the best-performing window, with the percentile held at the median.
[[pli]]
id = "pli"
length.start = 10
length.stop = 30
percentage = 50Searching the optimal percentile
This block keeps length fixed and explores a range of percentage values during the grid search: one backtest runs for each percentile in the range, and ranking the results shows which level performs best.
[[pli]]
id = "pli"
length = 20
percentage.start = 10
percentage.stop = 90
percentage.step = 10Dedicated symbol and timeframe
This block computes the percentile from the daily series of BINANCE:ETHUSDT, independently of the primary symbol and timeframe defined in [backtest]. See Exchanges, Symbols and Timeframes for alignment rules.
[[pli]]
id = "pli"
length = 20
percentage = 50
symbol = "BINANCE:ETHUSDT"
timeframe = "D"Parameters
| Parameter | Description |
|---|---|
idString Required | Unique name identifying the pli series; the block exposes one numeric series with this identifier. |
sourceString or Array Optional | Input series used for the calculation. Accepted forms: source = "hl2" or source = ["close", "hl2"].Each value can be either a standard price source ( open, close, high, low, hl2, hlc3, ohlc4, hlcc4, volume) or the id of another indicator.Default value: "close" |
lengthInteger Required | Number of candles in the window over which the percentile is computed; must be ≥ 1. Usage: • Fixed: length = value• Grid search: – length.start = min_value– length.stop = max_value– length.step = value (optional, default 1) |
percentageDecimal Required | Percentile to read from the sorted window, from 0 (lowest value) to 100 (highest value); 50 is the median.Usage: • Fixed: percentage = value• Grid search: – percentage.start = min_value– percentage.stop = max_value– percentage.step = value (optional, default 1) |
symbolString or Array Optional | Market symbol(s) providing the source series when source holds standard prices (open, close, high, low, hl2, hlc3, ohlc4, hlcc4, volume).If source mixes standard prices and indicator ids, symbol applies only to combinations based on standard prices.If source contains only indicator ids, symbol is ignored.For symbol format and alignment rules, see Exchanges, Symbols and Timeframes. |
timeframeString or Array Optional | Timeframe on which this indicator is computed. If timeframe is omitted, the computation uses the grid’s main timeframe defined in [backtest].For accepted formats and timeframe alignment rules, see Exchanges, Symbols and Timeframes. |
Available variables
The pli block exposes one numeric series, its calculation length, the requested percentile, and metadata about the input source, symbol, and timeframe. Use these identifiers directly in your expressions.
Assume the block is configured as:
[[pli]]
id = "pli"
length = 20
percentage = 50Then:
| Variable | Description |
|---|---|
pli or pli[0]Decimal | Current percentile value. |
pli[n]Decimal | Percentile value from n candles ago. |
pli.lengthDecimal | Window length in use. |
pli.percentageDecimal | Percentile read from the window, from 0 to 100. |
pli.sourceString | Input series name (for example close, hl2, or another indicator’s id). |
pli.symbolString | Symbol the input data is read from. |
pli.timeframeString | Timeframe the percentile is computed on. |
Notes
- During the warm-up phase, while the window does not yet hold
lengthcandles, the series isNaN. percentage = 0returns the lowest value in the window,percentage = 100the highest, andpercentage = 50the median. Withlength = 1the series simply repeats the current source value.- A candle whose source is
NaNstays in the window but is sorted after every numeric value. A highpercentagecan therefore returnNaNwhile those missing values occupy the top of the order, whereas lower percentiles remain computable. - Numeric variables support arithmetic, comparisons, and logical operators.
- Text variables are strings intended for equality/inequality checks only.