Bentrix Docs
HomePricingDashboard

Envelopes

Trend & channelsoverlay2 linesin every package

A moving average shifted up and down by a fixed percentage rather than by a measured deviation.

It measures distance from the mean on a scale you fix yourself, so unlike Bollinger the width says nothing about volatility. Read as a band of over-extension whose size is your assumption, not a measurement.

01The study, live

Live figureScroll to zoom, drag the bars to pan.
bar —O — H — L — C —band —band —first value at —
Show where:

Computed by Bentrix’s own code over the same synthetic bars on every page — an illustration of how the study behaves, not a market.

What this figure shows

The figure is computed over 300 sample bars. Envelopes has no value on the first 14 — the bars it needs before it can answer — and its first value stands on bar 15. Counting the conditions the study declares on these bars: price crosses above the upper band 8 times; price crosses below the lower band 11 times; price comes back inside the bands 20 times. Press a condition under the figure to see each place marked.

02Its parts, named

Warm-upno value on the first 14 bars: thestudy needs them before it cananswerThe upper banda set distance above the middleThe lower bandthe same distance below the middleThe bars it readseach bar's close, unless you chooseanother price
Computed by Bentrix’s own code over the sample bars. It is drawn on once, as you reach the figure.

03What you see

Two lines a fixed percentage above and below a moving average.

Envelopes are drawn over the candles: an upper and a lower line with the candles between them, the average itself not drawn. Both lines have the average's shape exactly, so the corridor keeps the same width in per cent however quiet or volatile the market is.

04Where it comes from

Moving-average envelopes — a band a fixed percentage above and below an average — are among the oldest channel techniques, in use on hand-drawn charts decades before volatility-based bands replaced them.

05The formula

Upper=MA(1+d),Lower=MA(1−d)
MAthe chosen moving average of the price
dthe deviation, as a fraction — 0.1 % by default

with the deviation d in percent (0.1 % by default in MetaTrader 5).

06A worked example

Take the last four closes of the sample, 24, 25, 24, 26, a period of 4 and a deviation of 2 %.

The average is 24.75.

  • upper = 24.75 × 1.02 = 25.25
  • lower = 24.75 × 0.98 = 24.25

The bands are always the same percentage apart, whatever the market is doing. With the default of 0.1 % they would be 24.77 and 24.73 — a default sized for a currency pair on a short timeframe; on most other charts it has to be changed before the bands mean anything.

07Built in Assay

The same study written in Assay, Bentrix’s script language, and drawn by Bentrix itself as the script’s graph: each block is one step of the formula. On the ladder the steps stand in the script’s order, one a row; on the board each wire carries a value from the block that gives it to the block that reads it, left to right. The script computes exactly what the study computes — Bentrix checks the two against each other, candle by candle.

THE SCRIPT’S GRAPH
//@version=6
indicator("Envelopes", overlay = true)
length = input.int(14, "Length")
deviation = input.float(0.1, "Deviation (%)")
average = ta.sma(close, length)
// The average moved up and down by a fixed percentage, from the bar after its first full window.
upper = bar_index >= length ? (1 + deviation / 100) * average : na
lower = bar_index >= length ? (1 - deviation / 100) * average : na
plot(upper, "Upper")
plot(lower, "Lower")

Paste it into the Assay IDE to put it on a chart, or to change it. Looking at the graph is free in every package; editing it as blocks is Plus.

08Readings — what traders look for

Read like a channel of fixed width: price at the upper line is read as stretched above its average by the set amount; in a range, a return inside the envelope is read as price back toward its centre.

How a band touch fails. The percentage is the trader's guess at a normal excursion. When volatility rises, price lives outside the bands; when it falls, price never reaches them. In a strong trend price presses against one band bar after bar; a touch of the band is then the normal state of the trend, not its limit.

09In different markets and timeframes

Envelopes are a fixed percentage around an average: right for one volatility and wrong for the next. They serve markets whose volatility is steady and need re-tuning otherwise.

The right percentage differs by market and by timeframe: on a daily chart of a major currency pair one to two per cent holds most closes, on an M15 chart a tenth of that, and on a volatile stock several times more. In a range price moves between the two lines; in a trend it runs along one of them or beyond, and the opposite line is not approached at all. After a change in volatility — a quiet market turning busy — a setting that fitted the last month no longer does, and the lines neither widen nor narrow to say so.

10With other studies

Read beside Bollinger Bands or Keltner Channels on the same average, which set their width from the market instead of from a constant.

11What it does not tell you

!

The width is fixed, so it means something different in a quiet market and a wild one — the reason Bollinger and Keltner channels make it adapt.

12Inputs and defaults

Envelopes (0.1, 14)settings card
1Deviations0.1
2Period14
3Shift0
4AverageThe study's own
5Applied priceClose
6TimeframeChart
7Wait for the candle to closeOn
  1. 1
    Deviations — 0.1The distance of each band from the average, in per cent of the average. It is the whole character of the study: too small and price is always outside, too large and it never arrives.
  2. 2
    Period — 14The period of the moving average in the middle.
  3. 3
    Shift — 0Draws every line that many candles to the right (a negative number: to the left). The values are not changed, only where they stand.
  4. 4
    Average — The study's ownThe kind of moving average inside the study. Left at the study's own, it is the one the study's calculation uses by itself.
  5. 5
    Applied price — CloseAny of the seven prices, and several at once, each its own line with its own look.
  6. 6
    Timeframe — ChartThe chart's own by default; any higher one, read on the last closed candle. A finer one is never offered.
  7. 7
    Wait for the candle to close — OnThe value of a higher timeframe is taken only from a candle that has finished.

What each input changes

  • ShiftDraws all the lines that many candles to the right, or to the left with a negative number. The values do not change, only the candle each one stands on.
  • AverageThe kind of average the middle line is: simple, exponential, smoothed or linear-weighted. The two envelopes are always that line moved by the same per cent, so they change with it.
  • In useThe percentage is everything: tenths of a per cent on a currency pair's intraday chart, several per cent on daily stock charts.

13Limits and common misreadings

Fixed width. The bands do not adapt to volatility; a percentage right for one year is wrong for the next.

The default is not universal. A percentage is chosen per instrument and timeframe.

14Conditions an alert or a strategy can watch

price crosses above the upper band eventprice crosses below the lower band eventprice comes back inside the bands event

Event: the bar it happens on an event happens on one barState: every bar while it holds a state holds on every bar while it lasts

These are the conditions the study itself declares — the same rules the alert editor and the strategy engine read, and the ones the figure's chips show.

15Practise it in the laboratory

Put Envelopes 20 on a chart and adjust the deviation until roughly nine closes in ten lie inside over the visible history; then scroll to a much quieter or wilder year and see how the same number fares.

Open the laboratory

17In Bentrix

  • From the menu: a chart's Indicators button › Trend & channels › Envelopes, or type Envelopes in its search.
  • Its settings: the settings card opens when it is added; its legend's name opens it again.

18From an agent or a program

Two tools reach it. study_values computes it over a workbench’s candles up to the clock — no chart needed — and study_attach puts it on a chart, where it is drawn and saved with the chart ({"chart": "<chart uri>", "kind": "envelopes"}).

The study, as a chart files it

This is a new Envelopes’s entry — its kind, its calculation, the price it reads and its settings. Change a setting here to read it with other inputs.

{
  "applied": "close",
  "convention": "mt5",
  "kind": "envelopes",
  "settings": {
    "dev": 0.1,
    "period": 14,
    "shape": "period_dev"
  }
}

An agent

An agent calls the MCP tool with it:

{
  "name": "study_values",
  "arguments": {
    "bench": "bentrix://lab/\u2026/bench/\u2026",
    "symbol": "EURUSD",
    "timeframe": "H1",
    "limit": 5,
    "study": {
      "applied": "close",
      "convention": "mt5",
      "kind": "envelopes",
      "settings": {
        "dev": 0.1,
        "period": 14,
        "shape": "period_dev"
      }
    }
  }
}

A program

A program does the same in its language — bench and market as in the built-in indicators guide:

Python

values = client.study.values(bench, market, "H1", {"applied": "close", "convention": "mt5", "kind": "envelopes", "settings": {"dev": 0.1, "period": 14, "shape": "period_dev"}}, limit=5)
print("times:", values["times"])
for line in values["lines"]:
    print("line:", line["line"])
    print("  newest values:", line["values"])

JSJavaScript

const values = await client.study.values({ bench, symbol: market, timeframe: "H1", study: { "applied": "close", "convention": "mt5", "kind": "envelopes", "settings": { "dev": 0.1, "period": 14, "shape": "period_dev" } }, limit: 5 });
console.log("times:", values.times);
for (const line of values.lines) {
  console.log("line:", line.line);
  console.log("  newest values:", line.values);
}

C#C#

var values = await client.Study.Values(bench, market, "H1", new Dictionary<string, object?> { ["applied"] = "close", ["convention"] = "mt5", ["kind"] = "envelopes", ["settings"] = new Dictionary<string, object?> { ["dev"] = 0.1, ["period"] = 14, ["shape"] = "period_dev" } }, limit: 5);
Console.WriteLine($"times: {values!["times"]!}");
foreach (var line in values!["lines"]!.AsArray())
{
    Console.WriteLine($"line: {line!["line"]!}");
    Console.WriteLine($"  newest values: {line!["values"]!}");
}

GOGo

values := must(client.Study.Values(ctx, mcp.StudyValuesArgs{Bench: bench, Symbol: market, Timeframe: "H1", Study: map[string]any{"applied": "close", "convention": "mt5", "kind": "envelopes", "settings": map[string]any{"dev": 0.1, "period": 14, "shape": "period_dev"}}, Limit: mcp.Ptr[int64](5)}))
fmt.Println("times:", at(values, "times"))
for _, line := range at(values, "lines").([]any) {
	fmt.Println("line:", at(line, "line"))
	fmt.Println("  newest values:", at(line, "values"))
}

Java

Object values = client.study.values(new Bentrix.StudyApi.ValuesArgs(bench, market, "H1", obj("applied", "close", "convention", "mt5", "kind", "envelopes", "settings", obj("dev", 0.1, "period", 14, "shape", "period_dev"))).limit(5L));
System.out.println("times:" + " " + at(values, "times"));
for (Object line : (List<Object>) at(values, "lines")) {
    System.out.println("line:" + " " + at(line, "line"));
    System.out.println("  newest values:" + " " + at(line, "values"));
}

C++C++

auto values = client.study.values_(StudyApi::ValuesArgs(bench, market, "H1", Json::Object{{"applied", "close"}, {"convention", "mt5"}, {"kind", "envelopes"}, {"settings", Json::Object{{"dev", 0.1}, {"period", 14}, {"shape", "period_dev"}}}}).limit(5));
std::cout << "times:" << " " << values["times"].dump() << std::endl;
for (const Json &line : values["lines"].arr()) {
    std::cout << "line:" << " " << line["line"].dump() << std::endl;
    std::cout << "  newest values:" << " " << line["values"].dump() << std::endl;
}

Julia

values = client.study.values(bench, market, "H1", Dict{String,Any}("applied" => "close", "convention" => "mt5", "kind" => "envelopes", "settings" => Dict{String,Any}("dev" => 0.1, "period" => 14, "shape" => "period_dev")); limit = 5)
println("times:", " ", values["times"])
for line in values["lines"]
    println("line:", " ", line["line"])
    println("  newest values:", " ", line["values"])
end

RR

values <- client$study$values(bench, market, "H1", list(applied = "close", convention = "mt5", kind = "envelopes", settings = list(dev = 0.1, period = 14, shape = "period_dev")), limit = 5)
cat("times:", format(values$times), "\n")
for (line in values$lines) {
  cat("line:", format(line$line), "\n")
  cat("  newest values:", format(line$values), "\n")
}

RRust

let values = client.study().values(mcp::StudyValuesArgs::new(bench.clone(), market.clone(), "H1", serde_json::json!({"applied": "close", "convention": "mt5", "kind": "envelopes", "settings": {"dev": 0.1, "period": 14, "shape": "period_dev"}})).limit(5))?;
println!("times: {}", values["times"]);
for line in values["lines"].as_array().into_iter().flatten() {
    println!("line: {}", line["line"]);
    println!("  newest values: {}", line["values"]);
}

Reading the answer

  • times — the candles’ open times, in milliseconds since 1970 (UTC), oldest first.
  • lines — one entry per line, in this order, each with its line name and its values; values[i] belongs to the candle at times[i].
  • The last value is the candle at the clock’s, which may still be forming: it changes until that candle closes, as on the chart. Nothing after the clock is ever computed.
  • null is a candle with no value yet — the warm-up, about 1 × the period at the start of the history.
lineWhat it is
BandEdgeband
BandEdgeband

In a strategy

Filed under a key of your choice in a strategy document’s studies — here envelopes: {"envelopes": {"applied": "close", "convention": "mt5", "kind": "envelopes", "settings": {"dev": 0.1, "period": 14, "shape": "period_dev"}}} — its rules can name:

WriteWhat it is
{"cond": "envelopes:band.cross_above_upper"}a condition it declares itself
{"cond": "envelopes:band.cross_below_lower"}a condition it declares itself
{"cond": "envelopes:band.back_inside"}a condition it declares itself

Its lines named band_edge are more than one line of that name, so a strategy reaches them through the conditions above rather than by name.

19Sources

  1. Murphy, John J. Technical Analysis of the Financial Markets. New York Institute of Finance, 1999.

Bentrix 0.1.382Every number, name and default on these pages is read from the application itself.What is comingWhat changed