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

# Volatility and bands across languages

> How Lipi maps to MQL4, MQL5, NinjaScript, Pine Script and thinkScript for volatility and bands: average true range, bollinger bands, bollinger bands width, donchian channel, donchian channel width, mean absolute deviation and more, with the differences that matter when converting.

The built-in volatility measures, bands, channels and trailing stops. 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 |
| - | - | - | - | - | - | - |
| [Average true range](#ta-atr) | `ta.atr` | Caveat | Caveat | Exact | Exact | Caveat |
| [Bollinger Bands](#ta-bb) | `ta.bb` | Caveat | Caveat | Caveat | Caveat | Caveat |
| [Bollinger Bands width](#ta-bbw) | `ta.bbw` | Absent | Absent | Absent | Differs | Differs |
| [Donchian channel](#ta-dc) | `ta.dc` | Absent | Absent | Caveat | Absent | Caveat |
| [Donchian channel width](#ta-dcw) | `ta.dcw` | Absent | Absent | Absent | Absent | Absent |
| [Mean absolute deviation](#ta-dev) | `ta.dev` | Absent | Caveat | Absent | Caveat | Caveat |
| [Keltner channels](#ta-kc) | `ta.kc` | Absent | Absent | Caveat | Caveat | Caveat |
| [Keltner channels width](#ta-kcw) | `ta.kcw` | Absent | Absent | Absent | Caveat | Absent |
| [Parabolic SAR](#ta-psar) | `ta.psar` | Caveat | Caveat | Caveat | Caveat | Caveat |
| [Standard deviation](#ta-stdev) | `ta.stdev` | Caveat | Caveat | Caveat | Caveat | Caveat |
| [Supertrend](#ta-supertrend) | `ta.supertrend` | Absent | Absent | Absent | Caveat | Absent |
| [True range](#ta-tr) | `ta.tr` | Absent | Absent | Absent | Caveat | Caveat |
| [Variance](#ta-variance) | `ta.variance` | Absent | Caveat | 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.

## Average true range

Average true range over `length` bars.

In Lipi: `ta.atr`.

| Language | Construct | Relation | Note |
| - | - | - | - |
| [MQL4](https://docs.mql4.com/indicators/iatr#iATR) | `iATR` | Equivalent, with a caveat | Called with symbol, timeframe, period and shift; returns the value at that shift, not the current bar's. 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/iatr) | `iATR` | Equivalent, with a caveat | Returns a handle, one buffer. Symbol and timeframe are arguments; the smoothing method is not stated on the page. 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/average_true_range_atr.htm) | `ATR` | Exact | |
| [Pine Script](https://www.tradingview.com/pine-script-reference/v6/#fun_ta.atr) | `ta.atr` | Exact | |
| [thinkScript](https://toslc.thinkorswim.com/center/reference/Tech-Indicators/studies-library/A-B/ATR) | `ATR` | Equivalent, with a caveat | Defaults to a 14-bar Wilder average of true range; thinkScript also takes an average type (simple, exponential, weighted, Wilder, Hull) that Lipi ta.atr lacks. |

## Bollinger Bands

Bollinger bands for `source` over `length` bars, with `mult` setting how far the outer bands sit from the middle one.

In Lipi: `ta.bb`.

| Language | Construct | Relation | Note |
| - | - | - | - |
| [MQL4](https://docs.mql4.com/indicators/ibands) | `iBands` | Equivalent, with a caveat | One call returns one line by mode (0 main, 1 upper, 2 lower); Lipi returns a tuple. 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/indicators/ibands) | `iBands` | Equivalent, with a caveat | Buffers are 0 base, 1 upper, 2 lower, the same order as Lipi's tuple. Adds a shift argument; price is an applied-price constant. State and side effects: Returns a handle; each band is read with its own CopyBuffer call on buffer 0, 1 or 2. 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/bollinger_bands.htm) | `Bollinger` | Equivalent, with a caveat | Order is multiplier then period (input first if given). Bands come back as .Upper and .Lower series, not a tuple. |
| [Pine Script](https://www.tradingview.com/pine-script-reference/v6/) | `ta.bb` | Equivalent, with a caveat | Pine's reference says na source values are ignored; Lipi's ta.bb returns na on a bar whose source is na. |
| [thinkScript](https://toslc.thinkorswim.com/center/reference/Tech-Indicators/studies-library/A-B/BollingerBands) | `BollingerBands` | Equivalent, with a caveat | Separate lower and upper deviation counts, a displace shift and a selectable average type; plots are MidLine, LowerBand, UpperBand versus Lipi's \[middle, upper, lower]. |

## Bollinger Bands width

Bollinger band width: the same calculation as `talib.bb`, delivered as one number instead of three bands.

In Lipi: `ta.bbw`.

| Language | Construct | Relation | Note |
| - | - | - | - |
| [MQL4](https://docs.mql4.com/indicators) | | Not in MQL4 | No band-width function; compute it from the main, upper and lower iBands lines. |
| [MQL5](https://www.mql5.com/en/docs/indicators) | | Not in MQL5 | No band-width indicator; derive it from the iBands base, upper and lower buffers. |
| [NinjaScript](https://ninjatrader.com/support/helpGuides/nt8/indicators.htm) | | Not in NinjaScript | No band-width indicator; derive it from the Bollinger Upper and Lower series. |
| [Pine Script](https://www.tradingview.com/pine-script-reference/v6/#fun_ta.bbw) | `ta.bbw` | Looks alike, behaves differently | Lipi returns upper minus lower in price units; Pine divides that width by the middle band (a fraction, or x100 in its own example). |
| [thinkScript](https://toslc.thinkorswim.com/center/reference/Tech-Indicators/studies-library/A-B/BollingerBandwidth) | `BollingerBandwidth` | Looks alike, behaves differently | BollingerBandwidth gives band distance as a percent of the middle band, plus Bulge and Squeeze plots. Lipi's ta.bbw is top minus bottom, in price units. |

## Donchian channel

Donchian channel over `length` bars.

In Lipi: `ta.dc`.

| Language | Construct | Relation | Note |
| - | - | - | - |
| [MQL4](https://docs.mql4.com/indicators) | | Not in MQL4 | No Donchian channel; combine iHighest and iLowest with iHigh and iLow. |
| [MQL5](https://www.mql5.com/en/docs/indicators) | | Not in MQL5 | No Donchian channel indicator; build it from iHighest and iLowest over the window. |
| [NinjaScript](https://ninjatrader.com/support/helpGuides/nt8/donchian_channel.htm) | `DonchianChannel` | Equivalent, with a caveat | Read as .Upper and .Lower series plus the default series, not a tuple; the plain call needs only a period. |
| [Pine Script](https://www.tradingview.com/pine-script-reference/v6/) | | Not in Pine Script | The ta namespace lists no Donchian function. A script must compose it from ta.highest and ta.lowest (our inference, not stated in the reference). |
| [thinkScript](https://toslc.thinkorswim.com/center/reference/Tech-Indicators/studies-library/O-Q/PriceChannel) | `PriceChannel` | Equivalent, with a caveat | Plots only LowerBand and UpperBand, no midline; Highest and Lowest give the same bands (the docs shift them by \[1] to skip the current bar). |

## Donchian channel width

Donchian channel width over `length` bars, as a single figure.

In Lipi: `ta.dcw`.

| Language | Construct | Relation | Note |
| - | - | - | - |
| [MQL4](https://docs.mql4.com/indicators) | | Not in MQL4 | No Donchian width function; derive it from iHighest/iHigh and iLowest/iLow. |
| [MQL5](https://www.mql5.com/en/docs/indicators) | | Not in MQL5 | No Donchian width indicator; derive it from the highest and lowest values yourself. |
| [NinjaScript](https://ninjatrader.com/support/helpGuides/nt8/indicators.htm) | | Not in NinjaScript | No width indicator; subtract DonchianChannel Lower from Upper. |
| [Pine Script](https://www.tradingview.com/pine-script-reference/v6/) | | Not in Pine Script | No Donchian width function in the ta namespace. Compose it from ta.highest and ta.lowest (our inference, not stated in the reference). |
| [thinkScript](https://toslc.thinkorswim.com/center/reference/Tech-Indicators/studies-library/O-Q/PriceChannel) | | Not in thinkScript | No channel-width study; subtract the PriceChannel LowerBand from its UpperBand. |

## Mean absolute deviation

A deviation measure for `source` over `length` bars.

In Lipi: `ta.dev`.

| Language | Construct | Relation | Note |
| - | - | - | - |
| [MQL4](https://docs.mql4.com/indicators) | | Not in MQL4 | No mean-deviation function among the indicator functions. |
| [MQL5](https://www.mql5.com/en/docs/standardlibrary/mathematics/stat/array_stat/mathaveragedeviation) | `MathAverageDeviation` | Equivalent, with a caveat | Average absolute deviation of an array you fill with the window. Lipi's reference does not define its dev measure, so confirm they match. |
| [NinjaScript](https://ninjatrader.com/support/helpGuides/nt8/indicators.htm) | | Not in NinjaScript | No mean-absolute-deviation indicator in the system list; compute it by hand. |
| [Pine Script](https://www.tradingview.com/pine-script-reference/v6/#fun_ta.dev) | `ta.dev` | Equivalent, with a caveat | Pine's reference says na source values are ignored; Lipi's ta.dev returns na on a bar whose source is na. |
| [thinkScript](https://toslc.thinkorswim.com/center/reference/thinkScript/Functions/Statistical/LinDev) | `LinDev` | Equivalent, with a caveat | LinDev's length defaults to 12, Lipi's dev requires it, so a converter must insert 12 when omitted; the deviation formula matches. |

## Keltner channels

Keltner channels for `source` over `length` bars, with `mult` setting the distance to the outer bands.

In Lipi: `ta.kc`.

| Language | Construct | Relation | Note |
| - | - | - | - |
| [MQL4](https://docs.mql4.com/indicators) | | Not in MQL4 | No Keltner channel; iEnvelopes is a fixed-percent envelope around an average, not ATR-based. |
| [MQL5](https://www.mql5.com/en/docs/indicators) | | Not in MQL5 | No Keltner channel among the built-in indicators; combine a moving average with iATR. |
| [NinjaScript](https://ninjatrader.com/support/helpGuides/nt8/keltner_channel.htm) | `KeltnerChannel` | Equivalent, with a caveat | Multiplier comes before period, with no true-range switch. Bands are .Upper and .Lower series; the page does not state how the width is built. |
| [Pine Script](https://www.tradingview.com/pine-script-reference/v6/) | `ta.kc` | Equivalent, with a caveat | Bands match the page formula after the first bars; Lipi seeds the range EMA on bar 0 from high-low, the page's ta.tr is na there. |
| [thinkScript](https://toslc.thinkorswim.com/center/reference/Tech-Indicators/studies-library/G-L/KeltnerChannels) | `KeltnerChannels` | Equivalent, with a caveat | Width is always ATR times factor (default 2), with separate average types for the centre line and ATR; plots Avg, Upper\_Band, Lower\_Band. |

## Keltner channels width

Keltner channel width for `source` over `length` bars: one figure in place of the three the channel call returns.

In Lipi: `ta.kcw`.

| Language | Construct | Relation | Note |
| - | - | - | - |
| [MQL4](https://docs.mql4.com/indicators) | | Not in MQL4 | No Keltner width; no Keltner channel is built in. |
| [MQL5](https://www.mql5.com/en/docs/indicators) | | Not in MQL5 | No Keltner width indicator; derive it from your own channel bands. |
| [NinjaScript](https://ninjatrader.com/support/helpGuides/nt8/indicators.htm) | | Not in NinjaScript | No width indicator; derive it from KeltnerChannel Upper and Lower. |
| [Pine Script](https://www.tradingview.com/pine-script-reference/v6/#fun_ta.kcw) | `ta.kcw` | Equivalent, with a caveat | Width fraction matches the page formula after the first bars; Lipi seeds the range EMA on bar 0, the page's ta.tr is na there. |
| [thinkScript](https://toslc.thinkorswim.com/center/reference/Tech-Indicators/studies-library/G-L/KeltnerChannels) | | Not in thinkScript | No Keltner width study; derive it from the Upper\_Band, Lower\_Band and Avg plots. |

## Parabolic SAR

Parabolic SAR, controlled by three numbers rather than a bar count: where the calculation starts, how much it moves on each step, and how far it is allowed to go.

In Lipi: `ta.psar`.

| Language | Construct | Relation | Note |
| - | - | - | - |
| [MQL4](https://docs.mql4.com/indicators/isar) | `iSAR` | Equivalent, with a caveat | Two parameters (step, maximum) where Lipi has start, step and max\_step; no source argument. 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/isar) | `iSAR` | Equivalent, with a caveat | Takes step and maximum only; Lipi also has a start value. Usual values per the page are 0.02 and 0.2. One buffer. 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/parabolic_sar.htm) | `ParabolicSAR` | Equivalent, with a caveat | Order is acceleration, max, step, whereas Lipi is start, step, max\_step. The page's own syntax lines disagree on the last two. |
| [Pine Script](https://www.tradingview.com/pine-script-reference/v6/#fun_ta.sar) | `ta.sar` | Equivalent, with a caveat | Pine's function is ta.sar; there is no ta.psar. Positional arguments start, inc, max line up with Lipi's start, step, max\_step. |
| [thinkScript](https://toslc.thinkorswim.com/center/reference/Tech-Indicators/studies-library/O-Q/ParabolicSAR) | `ParabolicSAR` | Equivalent, with a caveat | Two inputs: initial acceleration factor and its limit. Lipi ta.psar has three (start, step, max\_step), so the step is not separately set. |

## Standard deviation

Standard deviation of `source` over `length` bars.

In Lipi: `ta.stdev`.

| Language | Construct | Relation | Note |
| - | - | - | - |
| [MQL4](https://docs.mql4.com/indicators/istddev) | `iStdDev` | Equivalent, with a caveat | Takes a moving-average method and shift; the docs do not say population or sample division. 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/indicators/istddev) | `iStdDev` | Equivalent, with a caveat | Also takes ma\_method and ma\_shift, so the mean it measures around is selectable; use MODE\_SMA. The divisor is not stated on the page. 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/standard_deviation_stddev.htm) | `StdDev` | Equivalent, with a caveat | Lipi divides by length (population). The page does not state NinjaTrader's divisor; dividing by length minus one gives larger values. |
| [Pine Script](https://www.tradingview.com/pine-script-reference/v6/#fun_ta.stdev) | `ta.stdev` | Equivalent, with a caveat | Pine adds a biased flag (default true, the population form Lipi always uses). biased=false has no Lipi counterpart; use ta.variance with biased and math.sqrt. |
| [thinkScript](https://toslc.thinkorswim.com/center/reference/thinkScript/Functions/Statistical/StDev) | `StDev` | Equivalent, with a caveat | StDev's length defaults to 12, Lipi requires it; both are population deviations (divide by length). |

## Supertrend

Supertrend from a `multiplier` and an `atrLength`, calculated on the chart's own bars.

In Lipi: `ta.supertrend`. Takes the multiplier first, then the ATR length. At this build the direction is -1 on every bar except at most one early bar (none with an ATR length of 1).

| Language | Construct | Relation | Note |
| - | - | - | - |
| [MQL4](https://docs.mql4.com/indicators) | | Not in MQL4 | No Supertrend among the indicator functions; build it from iATR and price. |
| [MQL5](https://www.mql5.com/en/docs/indicators) | | Not in MQL5 | No Supertrend among the built-in indicators; it would come from a custom indicator via iCustom or your own code on iATR. |
| [NinjaScript](https://ninjatrader.com/support/helpGuides/nt8/indicators.htm) | | Not in NinjaScript | No Supertrend in NinjaTrader's system indicator list; build it from ATR by hand. |
| [Pine Script](https://www.tradingview.com/pine-script-reference/v6/) | `ta.supertrend` | Equivalent, with a caveat | Same signs: -1 up-trend, 1 down-trend. Lipi takes multiplier, then ATR length; its direction is -1 on all but at most one early bar. |
| [thinkScript](https://toslc.thinkorswim.com/center/reference/Tech-Indicators/studies-library) | | Not in thinkScript | No Supertrend study or function in the functions list or the study library. |

## True range

True range for the bar the script is on, taken from the chart's own bars.

In Lipi: `ta.tr`.

| Language | Construct | Relation | Note |
| - | - | - | - |
| [MQL4](https://docs.mql4.com/indicators) | | Not in MQL4 | No true-range function; derive it from High, Low and the previous Close, or use iATR. |
| [MQL5](https://www.mql5.com/en/docs/indicators) | | Not in MQL5 | No true-range indicator; only the averaged iATR exists. Compute true range from high, low and previous close. |
| [NinjaScript](https://ninjatrader.com/support/helpGuides/nt8/indicators.htm) | | Not in NinjaScript | No standalone true-range indicator; true range appears only inside the ATR page's description. Compute it from High, Low and the prior Close. |
| [Pine Script](https://www.tradingview.com/pine-script-reference/v6/) | `ta.tr` | Equivalent, with a caveat | Pine has both a variable ta.tr (same as ta.tr(false)) and the function; Lipi has only the function, so write the bare variable as ta.tr(). |
| [thinkScript](https://toslc.thinkorswim.com/center/reference/thinkScript/Functions/Tech-Analysis/TrueRange) | `TrueRange` | Equivalent, with a caveat | Takes high, close and low series as explicit arguments and uses the previous close; Lipi ta.tr reads chart bars and has a handle\_na option. |

## Variance

Variance of `source` over `length` bars.

In Lipi: `ta.variance`.

| Language | Construct | Relation | Note |
| - | - | - | - |
| [MQL4](https://docs.mql4.com/indicators) | | Not in MQL4 | No variance function; square iStdDev or compute it in a loop. |
| [MQL5](https://www.mql5.com/en/docs/matrix/matrix_statistics/matrix_var) | `vector::Var, MathVariance` | Equivalent, with a caveat | Divisor is N minus ddof: ddof 0 is the biased form, ddof 1 the unbiased. Fill the vector with the window first. |
| [NinjaScript](https://ninjatrader.com/support/helpGuides/nt8/indicators.htm) | | Not in NinjaScript | No variance indicator; only StdDev and StdError exist, so square StdDev or compute by hand. |
| [Pine Script](https://www.tradingview.com/pine-script-reference/v6/#fun_ta.variance) | `ta.variance` | Equivalent, with a caveat | Pine skips na values in the window; Lipi's ta.variance returns na on a bar whose source is na. |
| [thinkScript](https://toslc.thinkorswim.com/center/reference/thinkScript/Functions/Math---Trig/Sqr) | | Not in thinkScript | No variance function; square StDev with Sqr. StDev divides by length, so the result is the biased (population) variance. |


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