> ## 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.

# Series helpers across languages

> How Lipi maps to MQL4, MQL5, NinjaScript, Pine Script and thinkScript for series helpers: bars since a condition, change over bars, cross of two series, cross above, cross below, falling for a number of bars and more, with the differences that matter when converting.

The built-in functions that test or summarise a series: crosses, changes, sums and the value when a condition held. 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 |
| - | - | - | - | - | - | - |
| [Bars since a condition](#ta-barssince) | `ta.barssince` | Absent | Absent | Caveat | Differs | Absent |
| [Change over bars](#ta-change) | `ta.change` | Absent | Absent | Caveat | Caveat | Absent |
| [Cross of two series](#ta-cross) | `ta.cross` | Absent | Absent | Absent | Exact | Exact |
| [Cross above](#ta-crossover) | `ta.crossover` | Absent | Absent | Caveat | Exact | Caveat |
| [Cross below](#ta-crossunder) | `ta.crossunder` | Absent | Absent | Caveat | Exact | Caveat |
| [Falling for a number of bars](#ta-falling) | `ta.falling` | Absent | Absent | Caveat | Differs | Differs |
| [Rising for a number of bars](#ta-rising) | `ta.rising` | Absent | Absent | Caveat | Differs | Differs |
| [Sum over bars](#ta-sum) | `ta.sum` | Absent | Caveat | Exact | Caveat | Caveat |
| [Value when a condition was true](#ta-valuewhen) | `ta.valuewhen` | Absent | Absent | Absent | Caveat | Absent |

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.

## Bars since a condition

Counts the bars that have gone by since `condition` was last true.

In Lipi: `ta.barssince`.

| Language | Construct | Relation | Note |
| - | - | - | - |
| [MQL4](https://docs.mql4.com/indicators) | | Not in MQL4 | No built-in; walk back through the series in a loop until the condition holds. |
| [MQL5](https://www.mql5.com/en/docs/function_indices) | | Not in MQL5 | No bars-since function in the reference; keep a counter variable updated on each bar. |
| [NinjaScript](https://ninjatrader.com/support/helpGuides/nt8/most_recent_occurence_mro.htm) | `MRO` | Equivalent, with a caveat | Condition is a lambda, with an occurrence number (1 = latest) and a required look-back limit. Returns -1 if none; unsupported in multi-series scripts. |
| [Pine Script](https://www.tradingview.com/pine-script-reference/v6/) | `ta.barssince` | Looks alike, behaves differently | While the condition has never been true Pine returns na; Lipi returns -1. So barssince \< 5 is false in Pine, true in Lipi. Warm-up and missing values: Never-true gives na in Pine and -1 in Lipi, so comparisons and nz() guards behave differently. |
| [thinkScript](https://toslc.thinkorswim.com/center/reference/thinkScript/Reserved-Words/rec) | | Not in thinkScript | No bars-since function. Build it with a recursive def variable that references its own earlier value, seeded with CompoundValue. |

## Change over bars

The difference between the current value of `source` and its value `length` bars back.

In Lipi: `ta.change`.

| Language | Construct | Relation | Note |
| - | - | - | - |
| [MQL4](https://docs.mql4.com/indicators) | | Not in MQL4 | No built-in; subtract timeseries elements yourself, such as Close\[0] - Close\[n]. |
| [MQL5](https://www.mql5.com/en/docs/function_indices) | | Not in MQL5 | No change function in the reference; subtract the value at the older bar offset yourself. iMomentum is a handle-based price-change indicator. |
| [NinjaScript](https://ninjatrader.com/support/helpGuides/nt8/momentum.htm) | `Momentum` | Equivalent, with a caveat | Page gives no formula for Momentum; plain subtraction of Input\[0] and Input\[n] is the safe equivalent. Warm-up and missing values: Reading a bar before the first one throws an index-out-of-range exception; guard with CurrentBar. |
| [Pine Script](https://www.tradingview.com/pine-script-reference/v6/#fun_ta.change) | `ta.change` | Equivalent, with a caveat | Pine's result is na on the na bar and length bars later; Lipi's ta.change is na only on the na bar. |
| [thinkScript](https://toslc.thinkorswim.com/center/reference/thinkScript/Operators/Indexing) | | Not in thinkScript | No change function. Subtract the indexed value, price minus price\[n]; positive indexes reach into the past. |

## Cross of two series

True on a bar where `source1` and `source2` cross, in either direction.

In Lipi: `ta.cross`.

| Language | Construct | Relation | Note |
| - | - | - | - |
| [MQL4](https://docs.mql4.com/indicators) | | Not in MQL4 | No built-in; compare the two values at shift 0 and shift 1 yourself. |
| [MQL5](https://www.mql5.com/en/docs/function_indices) | | Not in MQL5 | No cross function; compare the current and previous values of both series yourself. |
| [NinjaScript](https://ninjatrader.com/support/helpGuides/nt8/market_data.htm) | | Not in NinjaScript | No single both-direction cross method; combine CrossAbove and CrossBelow with OR. |
| [Pine Script](https://www.tradingview.com/pine-script-reference/v6/#fun_ta.cross) | `ta.cross` | Exact | |
| [thinkScript](https://toslc.thinkorswim.com/center/reference/thinkScript/Functions/Math---Trig/Crosses) | `Crosses` | Exact | |

## Cross above

Flags the bar on which `source1` crosses above `source2`.

In Lipi: `ta.crossover`.

| Language | Construct | Relation | Note |
| - | - | - | - |
| [MQL4](https://docs.mql4.com/indicators) | | Not in MQL4 | No built-in; test below-or-equal at shift 1 and above at shift 0 yourself. |
| [MQL5](https://www.mql5.com/en/docs/function_indices) | | Not in MQL5 | No crossover function; test previous below-or-equal and current above, using two bar values. |
| [NinjaScript](https://ninjatrader.com/support/helpGuides/nt8/crossabove.htm) | `CrossAbove` | Equivalent, with a caveat | Extra required lookBackPeriod (1 = current bar only). NinjaTrader excludes a cross that starts from equal values; Lipi's ta.crossover counts it. |
| [Pine Script](https://www.tradingview.com/pine-script-reference/v6/#fun_ta.crossover) | `ta.crossover` | Exact | |
| [thinkScript](https://toslc.thinkorswim.com/center/reference/thinkScript/Functions/Math---Trig/Crosses) | `Crosses` | Equivalent, with a caveat | Pass CrossingDirection.ABOVE: the default is ANY, so a bare Crosses call is ta.cross, not crossover. |

## Cross below

The mirror of `talib.crossover`: true on the bar where `source1` crosses below `source2`.

In Lipi: `ta.crossunder`.

| Language | Construct | Relation | Note |
| - | - | - | - |
| [MQL4](https://docs.mql4.com/indicators) | | Not in MQL4 | No built-in; test above-or-equal at shift 1 and below at shift 0 yourself. |
| [MQL5](https://www.mql5.com/en/docs/function_indices) | | Not in MQL5 | No crossunder function; test previous above-or-equal and current below, using two bar values. |
| [NinjaScript](https://ninjatrader.com/support/helpGuides/nt8/crossbelow.htm) | `CrossBelow` | Equivalent, with a caveat | Extra required lookBackPeriod (1 = current bar only). NinjaTrader excludes a cross that starts from equal values; Lipi's ta.crossunder counts it. |
| [Pine Script](https://www.tradingview.com/pine-script-reference/v6/#fun_ta.crossunder) | `ta.crossunder` | Exact | |
| [thinkScript](https://toslc.thinkorswim.com/center/reference/thinkScript/Functions/Math---Trig/Crosses) | `Crosses` | Equivalent, with a caveat | Pass CrossingDirection.BELOW: the default is ANY, so a bare Crosses call is ta.cross, not crossunder. |

## Falling for a number of bars

Asks the same question as `talib.rising` in the other direction: has `source` been falling across `length` bars? The answer is a bool, not a number.

In Lipi: `ta.falling`.

| Language | Construct | Relation | Note |
| - | - | - | - |
| [MQL4](https://docs.mql4.com/indicators) | | Not in MQL4 | No built-in; compare successive series values in a loop. |
| [MQL5](https://www.mql5.com/en/docs/function_indices) | | Not in MQL5 | No falling-test function; compare the bar values in a loop or a chain of comparisons. |
| [NinjaScript](https://ninjatrader.com/support/helpGuides/nt8/falling.htm) | `IsFalling` | Equivalent, with a caveat | No length argument: it only tests that the current value is below the previous bar's value. |
| [Pine Script](https://www.tradingview.com/pine-script-reference/v6/#fun_ta.falling) | `ta.falling` | Looks alike, behaves differently | Pine compares the current value with earlier values in the window; Lipi's ta.falling needs a fall on every bar. Compare each earlier bar explicitly. |
| [thinkScript](https://toslc.thinkorswim.com/center/reference/thinkScript/Functions/Tech-Analysis/IsDescending) | `IsDescending` | Looks alike, behaves differently | Tests the average slope of trendlines from the mid-body value of past bars to the current value, not bar-by-bar declines like ta.falling. |

## Rising for a number of bars

Tests whether `source` has been rising across `length` bars.

In Lipi: `ta.rising`.

| Language | Construct | Relation | Note |
| - | - | - | - |
| [MQL4](https://docs.mql4.com/indicators) | | Not in MQL4 | No built-in; compare successive series values in a loop. |
| [MQL5](https://www.mql5.com/en/docs/function_indices) | | Not in MQL5 | No rising-test function; compare the bar values in a loop or a chain of comparisons. |
| [NinjaScript](https://ninjatrader.com/support/helpGuides/nt8/rising.htm) | `IsRising` | Equivalent, with a caveat | No length argument: it only tests that the current value is above the previous bar's value. |
| [Pine Script](https://www.tradingview.com/pine-script-reference/v6/#fun_ta.rising) | `ta.rising` | Looks alike, behaves differently | Pine compares the current value with earlier values in the window; Lipi's ta.rising needs a rise on every bar. Compare each earlier bar explicitly. |
| [thinkScript](https://toslc.thinkorswim.com/center/reference/thinkScript/Functions/Tech-Analysis/IsAscending) | `IsAscending` | Looks alike, behaves differently | Tests the average slope of trendlines from the mid-body value of past bars to the current value, not bar-by-bar rises like ta.rising. |

## Sum over bars

Adds up the last `length` values of `source`.

In Lipi: `ta.sum`.

| Language | Construct | Relation | Note |
| - | - | - | - |
| [MQL4](https://docs.mql4.com/indicators) | | Not in MQL4 | No windowed-sum function in the math or array groups; add the values in a loop. |
| [MQL5](https://www.mql5.com/en/docs/matrix/matrix_statistics/matrix_sum) | `vector::Sum` | Equivalent, with a caveat | Totals a whole vector; a moving window means copying the last n values into a vector first. |
| [NinjaScript](https://ninjatrader.com/support/helpGuides/nt8/summation_sum.htm) | `SUM` | Exact | |
| [Pine Script](https://www.tradingview.com/pine-script-reference/v6/#fun_math.sum) | `math.sum` | Equivalent, with a caveat | Pine v6 has no ta.sum; the moving-window sum is math.sum(source, length). Lipi accepts either name. |
| [thinkScript](https://toslc.thinkorswim.com/center/reference/thinkScript/Functions/Math---Trig/Sum) | `Sum` | Equivalent, with a caveat | Sum's length defaults to 12, Lipi requires it, so a converter must insert 12 when omitted. |

## Value when a condition was true

Reads `source` from the bar on which `condition` was true, going back as far as `occurrence` says.

In Lipi: `ta.valuewhen`.

| Language | Construct | Relation | Note |
| - | - | - | - |
| [MQL4](https://docs.mql4.com/indicators) | | Not in MQL4 | No built-in; loop back through the series and read the value where the condition held. |
| [MQL5](https://www.mql5.com/en/docs/function_indices) | | Not in MQL5 | No value-when function; store the value in a variable each time the condition is true. |
| [NinjaScript](https://ninjatrader.com/support/helpGuides/nt8/market_data.htm) | | Not in NinjaScript | No single method; read MRO's bars-ago result back into the series, for example Close\[barsAgo], after a -1 check. |
| [Pine Script](https://www.tradingview.com/pine-script-reference/v6/#fun_ta.valuewhen) | `ta.valuewhen` | Equivalent, with a caveat | Lipi's ta.valuewhen takes number sources only; Pine also accepts bool and color sources. |
| [thinkScript](https://toslc.thinkorswim.com/center/reference/thinkScript/Reserved-Words/rec) | | Not in thinkScript | No value-when function. Build it with a recursive def variable that keeps its prior value until the condition is true. |


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