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

# Moving averages across languages

> How Lipi maps to MQL4, MQL5, NinjaScript, Pine Script and thinkScript for moving averages: arnaud legoux moving average, exponential moving average, hull moving average, wilder's moving average, simple moving average, symmetrically weighted moving average and more, with the differences that matter w

The built-in moving averages and linear regression. 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 |
| - | - | - | - | - | - | - |
| [Arnaud Legoux moving average](#ta-alma) | `ta.alma` | Absent | Absent | Absent | Caveat | Absent |
| [Exponential moving average](#ta-ema) | `ta.ema` | Caveat | Caveat | Exact | Caveat | Caveat |
| [Hull moving average](#ta-hma) | `ta.hma` | Absent | Absent | Differs | Differs | Differs |
| [Wilder's moving average](#ta-rma) | `ta.rma` | Caveat | Caveat | Absent | Caveat | Caveat |
| [Simple moving average](#ta-sma) | `ta.sma` | Caveat | Caveat | Exact | Caveat | Caveat |
| [Symmetrically weighted moving average](#ta-swma) | `ta.swma` | Absent | Absent | Absent | Caveat | Absent |
| [Volume-weighted moving average](#ta-vwma) | `ta.vwma` | Absent | Absent | Exact | Caveat | Absent |
| [Weighted moving average](#ta-wma) | `ta.wma` | Caveat | Caveat | Differs | Differs | Differs |
| [Linear regression](#ta-linreg) | `ta.linreg` | 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.

## Arnaud Legoux moving average

An Arnaud Legoux moving average of `source` over `length` bars.

In Lipi: `ta.alma`.

| Language | Construct | Relation | Note |
| - | - | - | - |
| [MQL4](https://docs.mql4.com/indicators) | | Not in MQL4 | No Arnaud Legoux average among the indicator functions; code the weights by hand. |
| [MQL5](https://www.mql5.com/en/docs/indicators) | | Not in MQL5 | No ALMA among the built-in indicators; a custom indicator loaded through iCustom would have to supply it. |
| [NinjaScript](https://ninjatrader.com/support/helpGuides/nt8/indicators.htm) | | Not in NinjaScript | No ALMA in NinjaTrader's system indicator list; weights must be coded by hand. |
| [Pine Script](https://www.tradingview.com/pine-script-reference/v6/#fun_ta.alma) | `ta.alma` | Equivalent, with a caveat | Pine adds an optional floor flag (default false) that floors the offset calculation; Lipi's ta.alma has no floor argument. |
| [thinkScript](https://toslc.thinkorswim.com/center/reference/Tech-Indicators/studies-library) | | Not in thinkScript | No ALMA function or study in the functions list or the study library. |

## Exponential moving average

Exponential moving average of `source` over `length` bars, weighted so that recent bars count for more than older ones.

In Lipi: `ta.ema`.

| Language | Construct | Relation | Note |
| - | - | - | - |
| [MQL4](https://docs.mql4.com/indicators/ima) | `iMA with MODE_EMA` | Equivalent, with a caveat | One iMA covers four averages via ma\_method (MODE\_EMA = 1). ma\_shift offsets the line, which Lipi lacks. Source is an applied-price constant, not any series. 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/constants/indicatorconstants/enum_ma_method) | `iMA with MODE_EMA` | Equivalent, with a caveat | Same iMA as the simple average with ma\_method set to MODE\_EMA. An extra ma\_shift shifts the line; price is an applied-price constant. 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. Other timeframes: Symbol and timeframe are explicit arguments, so another symbol or timeframe is requested directly. |
| [NinjaScript](https://ninjatrader.com/support/helpGuides/nt8/moving_average_-_exponential_e.htm) | `EMA` | Exact | |
| [Pine Script](https://www.tradingview.com/pine-script-reference/v6/#fun_ta.ema) | `ta.ema` | Equivalent, with a caveat | Pine's reference says na source values are ignored; Lipi's ta.ema returns na on a bar whose source is na. |
| [thinkScript](https://toslc.thinkorswim.com/center/reference/thinkScript/Functions/Tech-Analysis/ExpAverage) | `ExpAverage` | Equivalent, with a caveat | Same alpha, 2/(length+1), and both seed from the first value. thinkScript's length defaults to 12, so pass it explicitly. |

## Hull moving average

Hull moving average of `source` over `length` bars.

In Lipi: `ta.hma`. Built on ta.wma, so it shares ta.wma's behaviour at this build. The half length rounds up.

| Language | Construct | Relation | Note |
| - | - | - | - |
| [MQL4](https://docs.mql4.com/indicators) | | Not in MQL4 | No Hull average among the indicator functions; build it from LWMA iMA calls. |
| [MQL5](https://www.mql5.com/en/docs/indicators) | | Not in MQL5 | No Hull moving average among the built-in indicators; compose weighted averages with iMA or use iCustom. |
| [NinjaScript](https://ninjatrader.com/support/helpGuides/nt8/moving_average_-_hull_hma.htm) | `HMA` | Looks alike, behaves differently | Lipi's ta.hma is built on its ta.wma, which does not follow standard weights at this build, so values differ. |
| [Pine Script](https://www.tradingview.com/pine-script-reference/v6/#fun_ta.hma) | `ta.hma` | Looks alike, behaves differently | Lipi's ta.hma uses its ta.wma, which does not follow standard weights at this build, so values differ. Its half length rounds up. |
| [thinkScript](https://toslc.thinkorswim.com/center/reference/Tech-Indicators/studies-library/G-L/HullMovingAvg) | `HullMovingAvg` | Looks alike, behaves differently | Lipi's ta.hma uses its ta.wma, which does not follow standard weights at this build, so values differ. The study also has a displace input. |

## Wilder's moving average

Rolling moving average of `source` over `length` bars.

In Lipi: `ta.rma`.

| Language | Construct | Relation | Note |
| - | - | - | - |
| [MQL4](https://docs.mql4.com/indicators/ima) | `iMA with MODE_SMMA` | Equivalent, with a caveat | MODE\_SMMA is the smoothed average; the page gives no formula. Lipi's ta.rma uses alpha 1/length, seeded with the SMA of the first length bars. 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/constants/indicatorconstants/enum_ma_method) | `iMA with MODE_SMMA` | Equivalent, with a caveat | MODE\_SMMA is the smoothed average; the page gives no formula. Lipi's ta.rma uses alpha 1/length, seeded with the SMA of the first length bars. 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. Other timeframes: Symbol and timeframe are explicit arguments, so another symbol or timeframe is requested directly. |
| [NinjaScript](https://ninjatrader.com/support/helpGuides/nt8/indicators.htm) | | Not in NinjaScript | No RMA indicator; Wilder smoothing is used inside RSI and ATR but not exposed on its own. |
| [Pine Script](https://www.tradingview.com/pine-script-reference/v6/#fun_ta.rma) | `ta.rma` | Equivalent, with a caveat | Pine's reference says na source values are ignored; Lipi's ta.rma returns na on a bar whose source is na. |
| [thinkScript](https://toslc.thinkorswim.com/center/reference/thinkScript/Functions/Tech-Analysis/WildersAverage) | `WildersAverage` | Equivalent, with a caveat | Length defaults to 12 and seeding uses prefetched bars; Lipi needs the length and seeds with the SMA of the first length bars. |

## Simple moving average

Simple moving average of `source` over `length` bars: every bar in the window counts for the same.

In Lipi: `ta.sma`.

| Language | Construct | Relation | Note |
| - | - | - | - |
| [MQL4](https://docs.mql4.com/indicators/ima) | `iMA with MODE_SMA` | Equivalent, with a caveat | One iMA covers four averages via ma\_method (MODE\_SMA = 0). ma\_shift offsets the line. Source is an applied-price constant, not any series. iMAOnArray takes arrays. 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/ima) | `iMA with MODE_SMA` | Equivalent, with a caveat | One iMA covers every average type via ma\_method; MODE\_SMA is simple averaging. An extra ma\_shift shifts the line on the chart. 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. Other timeframes: Symbol and timeframe are explicit arguments, so another symbol or timeframe is requested directly. |
| [NinjaScript](https://ninjatrader.com/support/helpGuides/nt8/moving_average_-_simple_sma.htm) | `SMA` | Exact | |
| [Pine Script](https://www.tradingview.com/pine-script-reference/v6/#fun_ta.sma) | `ta.sma` | Equivalent, with a caveat | Same average on clean data; at an na source bar Lipi returns na, TradingView returns the average of the last length non-na values. |
| [thinkScript](https://toslc.thinkorswim.com/center/reference/thinkScript/Functions/Tech-Analysis/Average) | `Average` | Equivalent, with a caveat | Average's length defaults to 12, Lipi requires it, so a converter must insert 12 when omitted. |

## Symmetrically weighted moving average

Symmetrically weighted moving average of `source` over the last four bars, with the weights 1/6, 2/6, 2/6 and 1/6.

In Lipi: `ta.swma`.

| Language | Construct | Relation | Note |
| - | - | - | - |
| [MQL4](https://docs.mql4.com/indicators) | | Not in MQL4 | No symmetric weighted average; use iMA with MODE\_LWMA or weight four bars by hand. |
| [MQL5](https://www.mql5.com/en/docs/indicators) | | Not in MQL5 | No symmetrically weighted average among the built-in indicators; weight four bar values yourself. |
| [NinjaScript](https://ninjatrader.com/support/helpGuides/nt8/indicators.htm) | | Not in NinjaScript | No symmetrically weighted average in the system list; code the 1-2-2-1 weights by hand. |
| [Pine Script](https://www.tradingview.com/pine-script-reference/v6/#fun_ta.swma) | `ta.swma` | Equivalent, with a caveat | Same weights on clean data; Pine yields na for four bars after an na source value, Lipi keeps computing. |
| [thinkScript](https://toslc.thinkorswim.com/center/reference/thinkScript/Functions/Tech-Analysis/WMA) | | Not in thinkScript | No symmetrically weighted average; WMA weights linearly over a length you choose. |

## Volume-weighted moving average

Volume-weighted moving average of `source` over `length` bars: bars that traded more count for more.

In Lipi: `ta.vwma`.

| Language | Construct | Relation | Note |
| - | - | - | - |
| [MQL4](https://docs.mql4.com/indicators) | | Not in MQL4 | No volume-weighted moving average among the indicator functions. |
| [MQL5](https://www.mql5.com/en/docs/constants/indicatorconstants/enum_ma_method) | | Not in MQL5 | No volume-weighted moving average among the built-in indicators; iMA has no volume weighting. |
| [NinjaScript](https://ninjatrader.com/support/helpGuides/nt8/moving_average_-_volume_weight.htm) | `VWMA` | Exact | |
| [Pine Script](https://www.tradingview.com/pine-script-reference/v6/#fun_ta.vwma) | `ta.vwma` | Equivalent, with a caveat | Pine's reference says na source values are ignored; Lipi's ta.vwma returns na on a bar whose source is na. |
| [thinkScript](https://toslc.thinkorswim.com/center/reference/Tech-Indicators/studies-library) | | Not in thinkScript | No volume-weighted moving average; build it as Sum(price\*volume, n) divided by Sum(volume, n). |

## Weighted moving average

Weighted moving average of `source` over `length` bars.

In Lipi: `ta.wma`. At this build the result does not follow standard WMA weights: a step from 0 to 1 settles at 1/length of the step.

| Language | Construct | Relation | Note |
| - | - | - | - |
| [MQL4](https://docs.mql4.com/indicators/ima) | `iMA with MODE_LWMA` | Equivalent, with a caveat | One iMA covers four averages via ma\_method (MODE\_LWMA = 3). ma\_shift offsets the line. Source is an applied-price constant, not any series. 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/constants/indicatorconstants/enum_ma_method) | `iMA with MODE_LWMA` | Equivalent, with a caveat | MODE\_LWMA is linear-weighted averaging, set through ma\_method on iMA. An extra ma\_shift shifts the line on the chart. 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. Other timeframes: Symbol and timeframe are explicit arguments, so another symbol or timeframe is requested directly. |
| [NinjaScript](https://ninjatrader.com/support/helpGuides/nt8/moving_average_-_weighted_wma.htm) | `WMA` | Looks alike, behaves differently | At this build Lipi's ta.wma does not follow standard weights: a step from 0 to 1 settles at 1/length. Compare values before porting. |
| [Pine Script](https://www.tradingview.com/pine-script-reference/v6/#fun_ta.wma) | `ta.wma` | Looks alike, behaves differently | At this build Lipi's ta.wma does not follow standard weights: a step from 0 to 1 settles at 1/length. Compare values before porting. |
| [thinkScript](https://toslc.thinkorswim.com/center/reference/thinkScript/Functions/Tech-Analysis/WMA) | `WMA` | Looks alike, behaves differently | WMA's length defaults to 9. At this build Lipi's ta.wma does not follow standard weights: a step from 0 to 1 settles at 1/length. |

## Linear regression

Fits a linear regression to `source` across `length` bars and returns a value from that fit.

In Lipi: `ta.linreg`. At this build a non-zero offset gives values that do not follow the fitted line.

| Language | Construct | Relation | Note |
| - | - | - | - |
| [MQL4](https://docs.mql4.com/indicators) | | Not in MQL4 | No linear-regression function among the indicator functions. |
| [MQL5](https://www.mql5.com/en/docs/matrix/matrix_statistics/matrix_linearregression) | `vector::LinearRegression` | Equivalent, with a caveat | Returns the whole fitted line for a vector; pick the element you need. No offset argument; fill the vector with the window first. |
| [NinjaScript](https://ninjatrader.com/support/helpGuides/nt8/linear_regression.htm) | `LinReg` | Equivalent, with a caveat | No offset argument; the call gives the least-squares line value. Page states no formula or which point of the fit is returned. |
| [Pine Script](https://www.tradingview.com/pine-script-reference/v6/#fun_ta.linreg) | `ta.linreg` | Equivalent, with a caveat | Matches the page's fit at offset 0; at other offsets Lipi's values do not follow the fit at this build, and Lipi resumes after na. |
| [thinkScript](https://toslc.thinkorswim.com/center/reference/thinkScript/Functions/Statistical/Inertia) | `Inertia` | Equivalent, with a caveat | Least-squares regression value at the current bar; no offset argument and no default length, unlike Lipi ta.linreg's offset. |


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