Bentrix Docs
HomePricingDashboard

Beta BETA

Statisticoscillatorone linein every package

The slope of a regression between the price's and the second series' bar-to-bar percentage changes over the period.

It measures how strongly the two move together, scaled by how much each moves; 1 is a move of the same size.

01The study, live

Live figureScroll to zoom, drag the bars to pan.
01
bar —O — H — L — C —main line —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. BETA has no value on the first 5 — the bars it needs before it can answer — and its first value stands on bar 6. Its line runs between -1.97 and 1.45 on these bars, and the last value is -0.0058. Counting the conditions the study declares on these bars: crosses above 0 36 times; crosses below 0 37 times; crosses above 1 once; crosses below 1 once. Press a condition under the figure to see each place marked. As states rather than moments: is above 0 on 119 bars; is below 0 on 176 bars; is above 1 on 1 bars; is below 1 on 294 bars.

02Its parts, named

The bars it readseach bar's close, unless you chooseanother priceWarm-upno value on the first 5 bars: thestudy needs them before it cananswerLevel 1a fixed reference the study is readagainstThe zero linethe centre line: where the studychanges signThe main linethe study's own value on each bar
Computed by Bentrix’s own code over the sample bars. It is drawn on once, as you reach the figure.

03What you see

A statistic of this market against a second series you choose — another market on the workbench, another study's line: how much this market tends to move per unit move of the other.

04Where it comes from

Beta comes from William Sharpe's capital asset pricing model (1964): the slope of one asset's returns regressed on another's, usually a stock on its index.

05The formula

With x the bar-to-bar changes of the second series and y those of the chart's price, over the last N bars:

β=cov(x,y)σx2
xthe bar-to-bar changes of the second series
ythe bar-to-bar changes of the chart's price
cov(x,y), σx2their covariance, and the variance of x, over the last N bars

the slope of the least-squares line of y on x: how much the price changed, on average, for each unit the second series changed.

06A worked example

Take five bars on which the second series changed by +1 %, +2 %, -1 %, +2 %, +1 % and the chart's price by +2 %, +3 %, -1 %, +3 %, +2 %.

Beta is the least-squares slope of the second list on the first. With n = 5: Σx = 5, Σy = 9, Σxy = 17, Σx² = 11.

Beta = (5 × 17 − 5 × 9) / (5 × 11 − 5²) = 40 / 30 = 1.33

For each 1 % the second series moved, the price moved about 1.33 % in the same direction over this window.

On real bars: take eight with closes 20, 21, 23, 22, 24, 25, 24, 26 and opens 19, 20, 21, 23, 22, 24, 25, 24, and measure the closes against the opens — the second series a new BETA starts with — over 5 bars. On the last bar it reads −0.78: over that window the closes' changes ran against the opens'.

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("Beta")
length = input.int(5, "Length")
// Each bar's return: how far the price moved since the bar before, as a share of it.
x = (close - close[1]) / close[1]
// The second series is the open.
y = (open - open[1]) / open[1]
sumX = math.sum(x, length)
sumY = math.sum(y, length)
sumXY = math.sum(x * y, length)
sumXX = math.sum(x * x, length)
// The slope of the least-squares line through the window's pairs of returns.
beta = (length * sumXY - sumX * sumY) / (length * sumXX - sumX * sumX)
plot(beta, "Beta")

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

Beta above 1 is read as this market having moved more than the second series, bar for bar; between 0 and 1 as having moved less, in the same direction; below 0 as having moved against it.

How beta fails. A beta above 1 says the price has moved more than the reference, bar for bar. Over a window as short as the default 5 the figure is dominated by one or two bars and swings wildly; and a beta measured in calm conditions routinely changes when conditions do.

09In different markets and timeframes

Beta needs two series whose bars line up in time and a window long enough to mean something; over five bars it is noise.

It is a daily and weekly statistic by custom: a year of daily bars (about 250) or two to five years of weekly ones. On intraday bars two markets that trade in different hours give stale pairs of prices and a beta pulled toward zero. It is not constant: the same pair of instruments shows a different beta in calm and in stressed periods, and a window that spans both describes neither. Between two currency pairs it mostly measures the currency they share.

10With other studies

Read beside the correlation of the same two series: beta is how much, correlation how reliably.

11What it does not tell you

!

Beta changes; a window's beta describes that window, and says nothing of why the two moved together. The second series is yours to choose: a new BETA opens measuring the chart's price against its own Open, which is only a placeholder until a market or a study's line is picked on the settings card.

12Inputs and defaults

BETA (5, Close)settings card
1Time Period5
2Applied priceClose
  1. 1
    Time Period — 5Time period
  2. 2
    Applied price — CloseAny of the seven prices, and several at once, each its own line with its own look.

What each input changes

  • Time PeriodThe number of bars in the window. Longer: steadier and later. Shorter: quicker and noisier.
  • Second seriesWhat the chart's price is measured against: a market of the workbench, a study's line, one of the chart's own prices or its volume. A new study opens on the chart's own Open; the reading means something once the series you intend is chosen.
  • In use5 by default in TA-Lib; 60 to 250 in practice.

13Limits and common misreadings

Short windows are noise. Five returns do not estimate a slope.

Not symmetric. The beta of A on B is not the inverse of B on A.

Returns must line up in time: two markets with different sessions give a spurious figure.

14Conditions an alert or a strategy can watch

crosses above 0 eventcrosses below 0 eventis above 0 stateis below 0 statecrosses above 1 eventcrosses below 1 eventis above 1 stateis below 1 state

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

Choose an index as the second series for a stock chart and compare BETA 5 with BETA 60; note how little the short one tells.

Open the laboratory

17On pages of their own

18In Bentrix

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

19From 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": "beta"}).

The study, as a chart files it

This is a new BETA’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": "talib",
  "kind": "beta",
  "second": {
    "from": "price",
    "price": "open"
  },
  "settings": {
    "shape": "ta",
    "values": {
      "optInTimePeriod": 5.0
    }
  }
}

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": "talib",
      "kind": "beta",
      "second": {
        "from": "price",
        "price": "open"
      },
      "settings": {
        "shape": "ta",
        "values": {
          "optInTimePeriod": 5.0
        }
      }
    }
  }
}

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": "talib", "kind": "beta", "second": {"from": "price", "price": "open"}, "settings": {"shape": "ta", "values": {"optInTimePeriod": 5.0}}}, 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": "talib", "kind": "beta", "second": { "from": "price", "price": "open" }, "settings": { "shape": "ta", "values": { "optInTimePeriod": 5.0 } } }, 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"] = "talib", ["kind"] = "beta", ["second"] = new Dictionary<string, object?> { ["from"] = "price", ["price"] = "open" }, ["settings"] = new Dictionary<string, object?> { ["shape"] = "ta", ["values"] = new Dictionary<string, object?> { ["optInTimePeriod"] = 5.0 } } }, 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": "talib", "kind": "beta", "second": map[string]any{"from": "price", "price": "open"}, "settings": map[string]any{"shape": "ta", "values": map[string]any{"optInTimePeriod": 5.0}}}, 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", "talib", "kind", "beta", "second", obj("from", "price", "price", "open"), "settings", obj("shape", "ta", "values", obj("optInTimePeriod", 5.0)))).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", "talib"}, {"kind", "beta"}, {"second", Json::Object{{"from", "price"}, {"price", "open"}}}, {"settings", Json::Object{{"shape", "ta"}, {"values", Json::Object{{"optInTimePeriod", 5.0}}}}}}).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" => "talib", "kind" => "beta", "second" => Dict{String,Any}("from" => "price", "price" => "open"), "settings" => Dict{String,Any}("shape" => "ta", "values" => Dict{String,Any}("optInTimePeriod" => 5.0))); 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 = "talib", kind = "beta", second = list(from = "price", price = "open"), settings = list(shape = "ta", values = list(optInTimePeriod = 5.0))), 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": "talib", "kind": "beta", "second": {"from": "price", "price": "open"}, "settings": {"shape": "ta", "values": {"optInTimePeriod": 5.0}}})).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.
  • Its fixed levels, drawn on the chart: [0.0, 1.0].
lineWhat it is
Mainthe indicator's own value

In a strategy

Filed under a key of your choice in a strategy document’s studies — here beta: {"beta": {"applied": "close", "convention": "talib", "kind": "beta", "second": {"from": "price", "price": "open"}, "settings": {"shape": "ta", "values": {"optInTimePeriod": 5.0}}}} — its rules can name:

WriteWhat it is
betaits main line, as a value in a compare
{"cond": "beta:level.cross_up:0"}a condition it declares itself
{"cond": "beta:level.cross_down:0"}a condition it declares itself
{"cond": "beta:level.above:0"}a condition it declares itself
{"cond": "beta:level.below:0"}a condition it declares itself
{"cond": "beta:level.cross_up:1"}a condition it declares itself
{"cond": "beta:level.cross_down:1"}a condition it declares itself
{"cond": "beta:level.above:1"}a condition it declares itself
{"cond": "beta:level.below:1"}a condition it declares itself

20Sources

  1. Colby, Robert W. The Encyclopedia of Technical Market Indicators, 2nd ed. McGraw-Hill, 2003.
  2. Sharpe, William F. "Capital Asset Prices: A Theory of Market Equilibrium under Conditions of Risk." The Journal of Finance, vol. 19, no. 3, 1964.

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