> ## Documentation Index
> Fetch the complete documentation index at: https://gocharting.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Extremes, pivots and statistics across languages

> How Lipi maps to MQL4, MQL5, NinjaScript, Pine Script and thinkScript for extremes, pivots and statistics: highest value, offset of the highest value, lowest value, offset of the lowest value, pivot high, pivot low and more, with the differences that matter when converting.

The built-in functions for highs, lows, pivots and statistics over a window of bars. Each row maps one concept from Lipi to the other languages; the word in a cell is the relation, explained in the [language map overview](https://gocharting.com/docs/scripting/reference/language-map.md#relations).

| Concept | Lipi | MQL4 | MQL5 | NinjaScript | Pine Script | thinkScript |
| - | - | - | - | - | - | - |
| [Highest value](#ta-highest) | `ta.highest` | Differs | Differs | Caveat | Caveat | Caveat |
| [Offset of the highest value](#ta-highestbars) | `ta.highestbars` | Caveat | Caveat | Caveat | Caveat | Caveat |
| [Lowest value](#ta-lowest) | `ta.lowest` | Differs | Differs | Caveat | Caveat | Caveat |
| [Offset of the lowest value](#ta-lowestbars) | `ta.lowestbars` | Caveat | Caveat | Caveat | Caveat | Caveat |
| [Pivot high](#ta-pivothigh) | `ta.pivothigh` | Caveat | Caveat | Caveat | Differs | Absent |
| [Pivot low](#ta-pivotlow) | `ta.pivotlow` | Caveat | Caveat | Caveat | Differs | Absent |
| [Range of values](#ta-range) | `ta.range` | Absent | Caveat | Differs | Caveat | Absent |
| [Median](#ta-median) | `ta.median` | Absent | Caveat | Caveat | Caveat | Caveat |
| [Mode](#ta-mode) | `ta.mode` | Absent | Absent | Absent | Caveat | Absent |
| [Percentile by linear interpolation](#ta-percentile_linear_interpolation) | `ta.percentile_linear_interpolation` | Absent | Caveat | Absent | Caveat | Absent |
| [Percentile by nearest rank](#ta-percentile_nearest_rank) | `ta.percentile_nearest_rank` | Absent | Absent | Absent | Caveat | Absent |
| [Percent rank](#ta-percentrank) | `ta.percentrank` | Absent | Absent | Absent | Caveat | Absent |
| [Correlation coefficient](#ta-correlation) | `ta.correlation` | Absent | Caveat | Caveat | Caveat | Caveat |

Each section below gives the Lipi construct first, then the construct in each language, with a note wherever behaviour differs. The language name links to the documentation the row was checked against.

## Highest value

The highest value `source` reached in the last `length` bars.

In Lipi: `ta.highest`. At this build its first valid bars can miss the true maximum.

| Language | Construct | Relation | Note |
| - | - | - | - |
| [MQL4](https://docs.mql4.com/series/ihighest) | `iHighest` | Looks alike, behaves differently | Returns the bar offset of the maximum, not its value; read the searched MODE\_\* series at that offset, e.g. iHigh for MODE\_HIGH. History indexing: result is a shift counted back from the current bar, reusable as the shift in iHigh. |
| [MQL5](https://www.mql5.com/en/docs/series/ihighest) | `iHighest` | Looks alike, behaves differently | Returns the bar shift of the highest value, not the value; read the price at that shift. The series comes from a mode enum. History indexing: Shift 0 is the current bar and counts toward older bars; -1 signals an error. |
| [NinjaScript](https://ninjatrader.com/support/helpGuides/nt8/maximum_max.htm) | `MAX` | Equivalent, with a caveat | At this build Lipi's ta.highest can be wrong on its first valid bars and is na until bar length-1; values match after warm-up. |
| [Pine Script](https://www.tradingview.com/pine-script-reference/v6/) | `ta.highest` | Equivalent, with a caveat | Pine also has a one-argument form that reads high; Lipi always needs the source, so expand ta.highest(n) to ta.highest(high, n). |
| [thinkScript](https://toslc.thinkorswim.com/center/reference/thinkScript/Functions/Tech-Analysis/Highest) | `Highest` | Equivalent, with a caveat | Highest's length defaults to 12, Lipi requires it; Lipi's first valid bars can also be wrong, and it is na until bar length-1. |

## Offset of the highest value

Locates the highest value of `source` within the last `length` bars and returns its position rather than its value.

In Lipi: `ta.highestbars`.

| Language | Construct | Relation | Note |
| - | - | - | - |
| [MQL4](https://docs.mql4.com/series/ihighest) | `iHighest` | Equivalent, with a caveat | Same offset-style result. Source is a MODE\_\* series id, with count and start arguments; returns -1 on error. History indexing: shift counts bars back from the current bar; shift 0 is the still-forming bar, and any shift can be read in one call. |
| [MQL5](https://www.mql5.com/en/docs/series/ihighest) | `iHighest` | Equivalent, with a caveat | Returns the shift of the highest bar, 0 at the current bar, as Lipi's ta.highestbars does; -1 on error. Series come from the mode enum. History indexing: Shift 0 is the current bar and counts toward older bars. |
| [NinjaScript](https://ninjatrader.com/support/helpGuides/nt8/highestbar.htm) | `HighestBar` | Equivalent, with a caveat | Returns an int count of bars ago (0 = current bar); the page documents no value for a not-found case. |
| [Pine Script](https://www.tradingview.com/pine-script-docs/visuals/text-and-shapes/) | `ta.highestbars` | Equivalent, with a caveat | Pine returns 0 or a negative offset (-3 is three bars back). Lipi's docs do not state the sign. Pine's one-argument form reads high. History indexing: Pine offsets are zero or negative; confirm the sign Lipi returns before comparing with positive values. |
| [thinkScript](https://toslc.thinkorswim.com/center/reference/thinkScript/Functions/Tech-Analysis/GetMaxValueOffset) | `GetMaxValueOffset` | Equivalent, with a caveat | Counts bars back with 0 at the current bar, as Lipi's ta.highestbars does. The length defaults to 25. |

## Lowest value

The lowest value `source` reached in the last `length` bars.

In Lipi: `ta.lowest`. At this build it returns 0 on the first length bars after it first has a value.

| Language | Construct | Relation | Note |
| - | - | - | - |
| [MQL4](https://docs.mql4.com/series/ilowest) | `iLowest` | Looks alike, behaves differently | Returns the bar offset of the minimum, not its value; read the value with iLow at that offset. Source is a MODE\_\* series id. History indexing: result is a shift counted back from the current bar, reusable as the shift in iLow. |
| [MQL5](https://www.mql5.com/en/docs/series/ilowest) | `iLowest` | Looks alike, behaves differently | Returns the bar shift of the lowest value, not the value; read the price at that shift. The series comes from a mode enum. History indexing: Shift 0 is the current bar and counts toward older bars; -1 signals an error. |
| [NinjaScript](https://ninjatrader.com/support/helpGuides/nt8/minimum_min.htm) | `MIN` | Equivalent, with a caveat | At this build Lipi's ta.lowest returns 0 on its first length valid bars and is na before that; values match after warm-up. |
| [Pine Script](https://www.tradingview.com/pine-script-reference/v6/) | `ta.lowest` | Equivalent, with a caveat | Pine also has a one-argument form that reads low; Lipi always needs the source, so expand ta.lowest(n) to ta.lowest(low, n). |
| [thinkScript](https://toslc.thinkorswim.com/center/reference/thinkScript/Functions/Tech-Analysis/Lowest) | `Lowest` | Equivalent, with a caveat | Lowest's length defaults to 12, Lipi requires it; Lipi also returns 0 for its first length valid bars and is na before that. |

## Offset of the lowest value

Gives the position of the lowest value of `source` within the last `length` bars, not the value itself.

In Lipi: `ta.lowestbars`.

| Language | Construct | Relation | Note |
| - | - | - | - |
| [MQL4](https://docs.mql4.com/series/ilowest) | `iLowest` | Equivalent, with a caveat | Same offset-style result. Source is a MODE\_\* series id, with count and start arguments; returns -1 on error. History indexing: shift counts bars back from the current bar; shift 0 is the still-forming bar, and any shift can be read in one call. |
| [MQL5](https://www.mql5.com/en/docs/series/ilowest) | `iLowest` | Equivalent, with a caveat | Returns the shift of the lowest bar, 0 at the current bar, as Lipi's ta.lowestbars does; -1 on error. Series come from the mode enum. History indexing: Shift 0 is the current bar and counts toward older bars. |
| [NinjaScript](https://ninjatrader.com/support/helpGuides/nt8/lowestbar.htm) | `LowestBar` | Equivalent, with a caveat | Returns an int count of bars ago (0 = current bar); the page documents no value for a not-found case. |
| [Pine Script](https://www.tradingview.com/pine-script-reference/v6/) | `ta.lowestbars` | Equivalent, with a caveat | Reference states no sign for the offset; the docs' highestbars example negates it, implying zero or negative values. Lipi's sign is undocumented. History indexing: Pine offsets are probably zero or negative; confirm the sign Lipi returns before comparing with positive values. |
| [thinkScript](https://toslc.thinkorswim.com/center/reference/thinkScript/Functions/Tech-Analysis/GetMinValueOffset) | `GetMinValueOffset` | Equivalent, with a caveat | Counts bars back with 0 at the current bar, as Lipi's ta.lowestbars does, which returns -1 during warm-up. The length defaults to 25. |

## Pivot high

Looks for a pivot high in `source`, as this build implements it.

In Lipi: `ta.pivothigh`.

| Language | Construct | Relation | Note |
| - | - | - | - |
| [MQL4](https://docs.mql4.com/indicators/ifractals#iFractals) | `iFractals` | Equivalent, with a caveat | Closest built-in: no leftBars or rightBars arguments, mode picks upper or lower, value read at a shift. History indexing: shift counts bars back from the current bar; shift 0 is the still-forming bar, and any shift can be read in one call. Other timeframes: symbol and timeframe arguments read another symbol or period directly; Lipi ta calls use the chart's own bars. |
| [MQL5](https://www.mql5.com/en/docs/indicators/ifractals) | `iFractals` | Equivalent, with a caveat | Buffers are 0 upper and 1 lower. The page shows no left or right bar-count arguments and gives no window definition. State and side effects: Returns a handle; values are read later with CopyBuffer and are not ready right after creation. History indexing: CopyBuffer start\_pos 0 is the current bar and counts toward the past; copied data lands oldest-first. |
| [NinjaScript](https://ninjatrader.com/support/helpGuides/nt8/swing.htm) | `Swing` | Equivalent, with a caveat | One strength covers both sides. SwingHigh gives 0, not na, when no swing exists; SwingHighBar returns bars ago, or -1. Warm-up and missing values: Zero is returned until the bar count exceeds strength or a pivot is found. Bar timing: A swing is only definite after strength further bars, so earlier values are updated later. |
| [Pine Script](https://www.tradingview.com/pine-script-reference/v6/#fun_ta.pivothigh) | `ta.pivothigh` | Looks alike, behaves differently | Pine returns the price of the pivot bar itself, or na. Lipi returns the current bar's source when the window high sits leftBars back. Bar timing: Pine reports the pivot bar's own price; Lipi's value is the current bar's source, not the pivot bar's. |
| [thinkScript](https://toslc.thinkorswim.com/center/reference/Tech-Indicators/studies-library/V-Z/ZigZagHighLow) | | Not in thinkScript | No left/right-bar pivot function; the ZigZagHighLow study marks swing points filtered by a reversal threshold, and PivotPoints gives previous-period levels. |

## Pivot low

Looks for a pivot low in `source`, as this build implements it.

In Lipi: `ta.pivotlow`.

| Language | Construct | Relation | Note |
| - | - | - | - |
| [MQL4](https://docs.mql4.com/indicators/ifractals#iFractals) | `iFractals` | Equivalent, with a caveat | Closest built-in: no leftBars or rightBars arguments, mode picks upper or lower, value read at a shift. History indexing: shift counts bars back from the current bar; shift 0 is the still-forming bar, and any shift can be read in one call. Other timeframes: symbol and timeframe arguments read another symbol or period directly; Lipi ta calls use the chart's own bars. |
| [MQL5](https://www.mql5.com/en/docs/indicators/ifractals) | `iFractals` | Equivalent, with a caveat | Lower buffer (1) holds the low fractals. The page shows no left or right bar-count arguments and gives no window definition. State and side effects: Returns a handle; values are read later with CopyBuffer and are not ready right after creation. History indexing: CopyBuffer start\_pos 0 is the current bar and counts toward the past; copied data lands oldest-first. |
| [NinjaScript](https://ninjatrader.com/support/helpGuides/nt8/swing.htm) | `Swing` | Equivalent, with a caveat | One strength covers both sides. SwingLow gives 0, not na, when no swing exists; SwingLowBar returns bars ago, or -1. Warm-up and missing values: Zero is returned until the bar count exceeds strength or a pivot is found. Bar timing: A swing is only definite after strength further bars, so earlier values are updated later. |
| [Pine Script](https://www.tradingview.com/pine-script-reference/v6/#fun_ta.pivotlow) | `ta.pivotlow` | Looks alike, behaves differently | Pine returns the price of the pivot bar itself, or na. Lipi returns the current bar's source when the window low sits leftBars back. Bar timing: Pine reports the pivot bar's own price; Lipi's value is the current bar's source, not the pivot bar's. |
| [thinkScript](https://toslc.thinkorswim.com/center/reference/Tech-Indicators/studies-library/V-Z/ZigZagHighLow) | | Not in thinkScript | No left/right-bar pivot function; the ZigZagHighLow study marks swing points filtered by a reversal threshold, and PivotPoints gives previous-period levels. |

## Range of values

How much ground `source` covered over the last `length` bars, expressed as one figure.

In Lipi: `ta.range`.

| Language | Construct | Relation | Note |
| - | - | - | - |
| [MQL4](https://docs.mql4.com/indicators) | | Not in MQL4 | No range function; use iHigh/iHighest and iLow/iLowest over the window. |
| [MQL5](https://www.mql5.com/en/docs/matrix/matrix_statistics) | `vector::Ptp` | Equivalent, with a caveat | Range of values of a whole vector; fill it with the window first. Lipi's range is a per-bar windowed figure. |
| [NinjaScript](https://ninjatrader.com/support/helpGuides/nt8/range.htm) | `Range` | Looks alike, behaves differently | Range() is the current bar's own range with no window length; Lipi's takes a source and length. Use MAX minus MIN for a window. |
| [Pine Script](https://www.tradingview.com/pine-script-reference/v6/#fun_ta.range) | `ta.range` | Equivalent, with a caveat | Equal after warm-up; Lipi's first length valid bars are wrong because its lowest returns 0 there, so the range is overstated. |
| [thinkScript](https://toslc.thinkorswim.com/center/reference/thinkScript/Functions/Tech-Analysis/Highest) | | Not in thinkScript | No range function; subtract Lowest from Highest over the same length. |

## Median

The middle value of the last `length` values of `source`.

In Lipi: `ta.median`.

| Language | Construct | Relation | Note |
| - | - | - | - |
| [MQL4](https://docs.mql4.com/indicators) | | Not in MQL4 | No median function; copy to an array, ArraySort it and read the middle element. |
| [MQL5](https://www.mql5.com/en/docs/standardlibrary/mathematics/stat/array_stat/mathmedian) | `MathMedian, vector::Median` | Equivalent, with a caveat | Takes an array you fill with the window first; it returns NaN on error. A Median method also exists on vectors. |
| [NinjaScript](https://ninjatrader.com/support/helpGuides/nt8/getmedian.htm) | `GetMedian` | Equivalent, with a caveat | A plain method returning one double, not an indicator series. For an even look-back it averages the two middle values. |
| [Pine Script](https://www.tradingview.com/pine-script-reference/v6/#fun_ta.median) | `ta.median` | Equivalent, with a caveat | Pine's reference says na source values are ignored; Lipi's ta.median returns na on a bar whose source is na. |
| [thinkScript](https://toslc.thinkorswim.com/center/reference/thinkScript/Functions/Tech-Analysis/Median) | `Median` | Equivalent, with a caveat | Median's length defaults to 12, Lipi requires it; the middle-or-average-of-two rule matches. |

## Mode

Of the last `length` values of `source`, this reports the one that recurs most often.

In Lipi: `ta.mode`.

| Language | Construct | Relation | Note |
| - | - | - | - |
| [MQL4](https://docs.mql4.com/indicators) | | Not in MQL4 | No mode function; sort a copy and count runs in a loop. |
| [MQL5](https://www.mql5.com/en/docs/standardlibrary/mathematics/stat/array_stat) | | Not in MQL5 | No mode function among the array statistics (mean, variance, skewness, kurtosis, median, deviation). |
| [NinjaScript](https://ninjatrader.com/support/helpGuides/nt8/indicators.htm) | | Not in NinjaScript | No statistical-mode indicator or method in the system list; compute it by hand. |
| [Pine Script](https://www.tradingview.com/pine-script-reference/v6/#fun_ta.mode) | `ta.mode` | Equivalent, with a caveat | Pine ignores na source values; Lipi's ta.mode returns na on a bar whose source is na, and float even for int sources. |
| [thinkScript](https://toslc.thinkorswim.com/center/reference/thinkScript/Functions/Tech-Analysis) | | Not in thinkScript | No mode function; Median is the nearest windowed statistic offered. |

## Percentile by linear interpolation

The requested `percentile` of `source` over `length` bars, interpolating between the two values that straddle the rank.

In Lipi: `ta.percentile_linear_interpolation`.

| Language | Construct | Relation | Note |
| - | - | - | - |
| [MQL4](https://docs.mql4.com/indicators) | | Not in MQL4 | No percentile function; sort a copy with ArraySort and interpolate by hand. |
| [MQL5](https://www.mql5.com/en/docs/matrix/matrix_statistics/matrix_percentile) | `vector::Percentile` | Equivalent, with a caveat | A vector method; percent runs 0 to 100 and a linear algorithm is used. The page asks for sorted input. Fill the vector first. |
| [NinjaScript](https://ninjatrader.com/support/helpGuides/nt8/market_data.htm) | | Not in NinjaScript | No percentile method in the system indicator or Analytical lists; compute it by hand. |
| [Pine Script](https://www.tradingview.com/pine-script-reference/v6/#fun_ta.percentile_linear_interpolation) | `ta.percentile_linear_interpolation` | Equivalent, with a caveat | Same calculation; the third parameter is named percentage in Pine and percentile in Lipi, which matters for named arguments. |
| [thinkScript](https://toslc.thinkorswim.com/center/reference/thinkScript/Functions/Tech-Analysis) | | Not in thinkScript | No percentile function in the functions list or study library. |

## Percentile by nearest rank

Takes the requested `percentile` of `source` over `length` bars at the nearest rank, without interpolating.

In Lipi: `ta.percentile_nearest_rank`.

| Language | Construct | Relation | Note |
| - | - | - | - |
| [MQL4](https://docs.mql4.com/indicators) | | Not in MQL4 | No percentile function; sort a copy with ArraySort and pick the rank by hand. |
| [MQL5](https://www.mql5.com/en/docs/matrix/matrix_statistics/matrix_percentile) | | Not in MQL5 | The documented Percentile method uses a linear algorithm only; no nearest-rank variant is described. |
| [NinjaScript](https://ninjatrader.com/support/helpGuides/nt8/market_data.htm) | | Not in NinjaScript | No percentile method in the system indicator or Analytical lists; compute it by hand. |
| [Pine Script](https://www.tradingview.com/pine-script-reference/v6/#fun_ta.percentile_nearest_rank) | `ta.percentile_nearest_rank` | Equivalent, with a caveat | Same calculation; the third parameter is named percentage in Pine and percentile in Lipi, which matters for named arguments. |
| [thinkScript](https://toslc.thinkorswim.com/center/reference/thinkScript/Functions/Tech-Analysis) | | Not in thinkScript | No percentile function in the functions list or study library. |

## Percent rank

Ranks where `source` now stands against the last `length` bars of itself.

In Lipi: `ta.percentrank`.

| Language | Construct | Relation | Note |
| - | - | - | - |
| [MQL4](https://docs.mql4.com/indicators) | | Not in MQL4 | No percent-rank function among the indicator functions. |
| [MQL5](https://www.mql5.com/en/docs/matrix/matrix_statistics) | | Not in MQL5 | No percent-rank method in the matrix and vector statistics list; count the values below the current one yourself. |
| [NinjaScript](https://ninjatrader.com/support/helpGuides/nt8/market_data.htm) | | Not in NinjaScript | No percent-rank method in the system indicator or Analytical lists; compute it by hand. |
| [Pine Script](https://www.tradingview.com/pine-script-reference/v6/#fun_ta.percentrank) | `ta.percentrank` | Equivalent, with a caveat | Same ranking on clean data; Pine yields na when an na is in the window, Lipi keeps computing after the na bar. |
| [thinkScript](https://toslc.thinkorswim.com/center/reference/thinkScript/Functions/Tech-Analysis) | | Not in thinkScript | No percent-rank function in the functions list or study library. |

## Correlation coefficient

Correlation between two series, `source1` and `source2`, measured over `length` bars.

In Lipi: `ta.correlation`.

| Language | Construct | Relation | Note |
| - | - | - | - |
| [MQL4](https://docs.mql4.com/indicators) | | Not in MQL4 | No correlation function among the indicator functions or math group. |
| [MQL5](https://www.mql5.com/en/docs/matrix/matrix_products/matrix_corrcoef) | `vector::CorrCoef` | Equivalent, with a caveat | A method on two vectors you fill first; it returns the Pearson coefficient. The bar window is whatever you copy into the vectors. |
| [NinjaScript](https://ninjatrader.com/support/helpGuides/nt8/correlation.htm) | `Correlation` | Equivalent, with a caveat | Correlates the chart series with another instrument given by name, not any two series. |
| [Pine Script](https://www.tradingview.com/pine-script-reference/v6/#fun_ta.correlation) | `ta.correlation` | Equivalent, with a caveat | Pine's reference says na source values are ignored; Lipi's ta.correlation returns na on a bar whose source is na. |
| [thinkScript](https://toslc.thinkorswim.com/center/reference/thinkScript/Functions/Statistical/Correlation) | `Correlation` | Equivalent, with a caveat | Length defaults to 10. thinkScript can feed another symbol's close as data2; Lipi reads only the chart symbol. Other timeframes: data2 may come from a secondary symbol, which Lipi cannot read. |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.