MA Slope
The line's COLOUR is its slope, measured as an angle against the instrument's own typical bar movement (ATR), so one threshold means the same thing on M1 as on H1 and on gold as on silver.
Set sigma bands to draw the 0.5 sigma ladder around it, every rung coloured by its own slope: rungs diverging is expansion, converging is a squeeze. The colour says STEEP RELATIVE TO VOLATILITY and never 'worth trading' — on a quiet market a bar in the steepest colour can still move less than the spread. This average needs several times its period before its first value, so the line is a transparent gap until then rather than a guess.
01The study, live
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. MA has no value on the first 19 — the bars it needs before it can answer — and its first value stands on bar 20. Of the 281 bars that have a value, the close is above the line on 146 and below it on 135. Counting the conditions the study declares on these bars: the slope turns strongly up 4 times; the slope turns up 7 times; the slope turns flat 5 times; the slope turns down 5 times; the slope turns strongly down 3 times. Press a condition under the figure to see each place marked. As states rather than moments: the slope is strongly up on 25 bars; the slope is up on 86 bars; the slope is flat on 56 bars; the slope is down on 71 bars; the slope is strongly down on 38 bars.
02Its parts, named
03What you see
A moving average coloured by how steeply it slopes — strongly up, up, flat, down, strongly down — with optional bands of standard deviations around it.
04Where it comes from
MA Slope is one of Bentrix's own studies. Its slope is measured in a way that does not depend on the chart's zoom: the rise over a few bars, divided by the market's own average true range, so steep means steep relative to how much the market normally moves.
05The formula
slopeₜ = (MAₜ − MA_(t−k))/(k · ATRₜ)
expressed as an angle and compared with two thresholds (flat and strong), which follow the period unless set.
06A worked example
Take an SMA that read 100.00 five bars ago and reads 100.60 now, on a market whose ATR is 0.80, with Slope bars 5.
The change per bar is (100.60 − 100.00) / 5 = 0.12. Measured in ATRs per bar that is 0.12 / 0.80 = 0.15, and the angle is atan(0.15) = 8.5°.
With a flat threshold of 5° and a strong threshold of 20°, this bar is coloured as a plain rise: more than flat, less than strong. Had the same 0.60 change happened on a market with an ATR of 3.00, the slope would be 0.04 ATR per bar, an angle of 2.3° — flat. The same price change is a slope on a quiet market and nothing on a wild one, which is the reason the angle is measured in ATRs.
On real closes — 20, 21, 23, 22, 24, 25, 24, 26 — the SMA of 3 that the study draws reads 23.67 two bars before the last and 25.00 on the last. With Slope bars 2 that is a change of (25.00 − 23.67) / 2 = 0.67 a bar, which the study then divides by the ATR.
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.
//@version=6 indicator("MA Slope", overlay = true) length = input.int(20, "Length") // The line is a simple moving average; how steeply it climbs or falls is what colours it on the chart. ma = ta.sma(close, length) plot(ma, "MA")
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
The colour is read as the trend's state on the average's own horizon: whether the average is rising or falling faster than the market's ordinary movement.
The colour of the line. Read as the state of the average's slope — strong up, up, flat, down, strong down — without having to judge an angle by eye. It fails near the thresholds: a slope hovering at the flat limit changes colour back and forth with no real change in the market.
Flat stretches. Read as stretches where the average has no direction and crossings of it carry little information. It fails at the end of such a stretch, where the colour changes only after the average has already turned.
09In different markets and timeframes
The slope colouring is meant for scanning a chart for where an average has direction at all; measuring the slope in ATRs makes the same thresholds usable on a quiet and on a wild market. Near the flat threshold the colour flickers.
10With other studies
Read beside the ADX, which answers the same question — is there a trend — from directional movement instead of from an average's slope.
11What it does not tell you
The colour describes the slope of the last bars of an average; it changes after the move that changed it.
12Inputs and defaults
- 1ATR period — 0The window of the ATR that the price change is divided by, so that the angle means the same on any market and timeframe.
- 2Bands — 0Bands drawn around the line; see the Bands tab of the study's settings.
- 3Flat deg — 0Angles smaller than this, in either direction, are coloured as flat.
- 4Average — smaThe kind of average the line is.
- 5Period — 20The period of that average.
- 6Slope bars — 5How many bars back the slope is measured from. One bar gives a twitchy colour; five or more a steadier one.
- 7Strong deg — 0Angles larger than this are coloured as strong.
- 8Wilder — TrueWhether the ATR uses Wilder's smoothing (the usual convention) or a simple average.
- 9Applied price — CloseAny of the seven prices, and several at once, each its own line with its own look.
- 10Timeframe — ChartThe chart's own by default; any higher one, read on the last closed candle. A finer one is never offered.
- 11Wait for the candle to close — OnThe value of a higher timeframe is taken only from a candle that has finished.
The settings in use
- In useSlope measured over 5 bars; thresholds of a few degrees for flat and around 20 for strong are starting points to be set against the instrument's own history.
13Limits and common misreadings
An angle on a chart is not a physical angle. It depends on the units chosen; here they are ATRs per bar, and other platforms choose differently.
The thresholds are the trader's. There is no natural value for flat or strong.
14Conditions an alert or a strategy can watch
an event happens on one bar 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
Watch the colours through a trend's start, middle and end; note how many bars into the move the colour changed.
Open the laboratory17In Bentrix
- From the menu: a chart's Indicators button › Moving averages › MA, or type MA 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": "ma_slope"}).
The study, as a chart files it
This is a new MA’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": "bentrix",
"kind": "ma_slope",
"settings": {
"atr_period": 0,
"bands": 0.0,
"flat_deg": 0.0,
"ma": "sma",
"period": 20,
"shape": "ma_slope",
"slope_bars": 5,
"strong_deg": 0.0,
"wilder": true
}
}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": "bentrix",
"kind": "ma_slope",
"settings": {
"atr_period": 0,
"bands": 0.0,
"flat_deg": 0.0,
"ma": "sma",
"period": 20,
"shape": "ma_slope",
"slope_bars": 5,
"strong_deg": 0.0,
"wilder": true
}
}
}
}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": "bentrix", "kind": "ma_slope", "settings": {"atr_period": 0, "bands": 0.0, "flat_deg": 0.0, "ma": "sma", "period": 20, "shape": "ma_slope", "slope_bars": 5, "strong_deg": 0.0, "wilder": True}}, limit=5)
print("times:", values["times"])
for line in values["lines"]:
print("line:", line["line"])
print(" newest values:", line["values"])JavaScript
const values = await client.study.values({ bench, symbol: market, timeframe: "H1", study: { "applied": "close", "convention": "bentrix", "kind": "ma_slope", "settings": { "atr_period": 0, "bands": 0.0, "flat_deg": 0.0, "ma": "sma", "period": 20, "shape": "ma_slope", "slope_bars": 5, "strong_deg": 0.0, "wilder": true } }, 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#
var values = await client.Study.Values(bench, market, "H1", new Dictionary<string, object?> { ["applied"] = "close", ["convention"] = "bentrix", ["kind"] = "ma_slope", ["settings"] = new Dictionary<string, object?> { ["atr_period"] = 0, ["bands"] = 0.0, ["flat_deg"] = 0.0, ["ma"] = "sma", ["period"] = 20, ["shape"] = "ma_slope", ["slope_bars"] = 5, ["strong_deg"] = 0.0, ["wilder"] = true } }, 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"]!}");
}Go
values := must(client.Study.Values(ctx, mcp.StudyValuesArgs{Bench: bench, Symbol: market, Timeframe: "H1", Study: map[string]any{"applied": "close", "convention": "bentrix", "kind": "ma_slope", "settings": map[string]any{"atr_period": 0, "bands": 0.0, "flat_deg": 0.0, "ma": "sma", "period": 20, "shape": "ma_slope", "slope_bars": 5, "strong_deg": 0.0, "wilder": true}}, 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", "bentrix", "kind", "ma_slope", "settings", obj("atr_period", 0, "bands", 0.0, "flat_deg", 0.0, "ma", "sma", "period", 20, "shape", "ma_slope", "slope_bars", 5, "strong_deg", 0.0, "wilder", true))).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++
auto values = client.study.values_(StudyApi::ValuesArgs(bench, market, "H1", Json::Object{{"applied", "close"}, {"convention", "bentrix"}, {"kind", "ma_slope"}, {"settings", Json::Object{{"atr_period", 0}, {"bands", 0.0}, {"flat_deg", 0.0}, {"ma", "sma"}, {"period", 20}, {"shape", "ma_slope"}, {"slope_bars", 5}, {"strong_deg", 0.0}, {"wilder", true}}}}).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" => "bentrix", "kind" => "ma_slope", "settings" => Dict{String,Any}("atr_period" => 0, "bands" => 0.0, "flat_deg" => 0.0, "ma" => "sma", "period" => 20, "shape" => "ma_slope", "slope_bars" => 5, "strong_deg" => 0.0, "wilder" => true)); limit = 5)
println("times:", " ", values["times"])
for line in values["lines"]
println("line:", " ", line["line"])
println(" newest values:", " ", line["values"])
endR
values <- client$study$values(bench, market, "H1", list(applied = "close", convention = "bentrix", kind = "ma_slope", settings = list(atr_period = 0, bands = 0.0, flat_deg = 0.0, ma = "sma", period = 20, shape = "ma_slope", slope_bars = 5, strong_deg = 0.0, wilder = TRUE)), 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")
}Rust
let values = client.study().values(mcp::StudyValuesArgs::new(bench.clone(), market.clone(), "H1", serde_json::json!({"applied": "close", "convention": "bentrix", "kind": "ma_slope", "settings": {"atr_period": 0, "bands": 0.0, "flat_deg": 0.0, "ma": "sma", "period": 20, "shape": "ma_slope", "slope_bars": 5, "strong_deg": 0.0, "wilder": true}})).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 itslinename and itsvalues;values[i]belongs to the candle attimes[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.
nullis a candle with no value yet — the warm-up, about 1 × the period at the start of the history.
line | What it is |
|---|---|
Rung { sigma: 0.0 } | Rung { sigma: 0.0 } |
In a strategy
Filed under a key of your choice in a strategy document’s studies — here ma_slope: {"ma_slope": {"applied": "close", "convention": "bentrix", "kind": "ma_slope", "settings": {"atr_period": 0, "bands": 0.0, "flat_deg": 0.0, "ma": "sma", "period": 20, "shape": "ma_slope", "slope_bars": 5, "strong_deg": 0.0, "wilder": true}}} — its rules can name:
| Write | What it is |
|---|---|
ma_slope.rung | this line, as a value in a compare |
{"cond": "ma_slope:slope.turns_strong_up"} | a condition it declares itself |
{"cond": "ma_slope:slope.turns_up"} | a condition it declares itself |
{"cond": "ma_slope:slope.turns_flat"} | a condition it declares itself |
{"cond": "ma_slope:slope.turns_down"} | a condition it declares itself |
{"cond": "ma_slope:slope.turns_strong_down"} | a condition it declares itself |
{"cond": "ma_slope:slope.is_strong_up"} | a condition it declares itself |
{"cond": "ma_slope:slope.is_up"} | a condition it declares itself |
{"cond": "ma_slope:slope.is_flat"} | a condition it declares itself |
{"cond": "ma_slope:slope.is_down"} | a condition it declares itself |
{"cond": "ma_slope:slope.is_strong_down"} | a condition it declares itself |
19Sources
- Bentrix's own study: its design is described on this page and in the application.
Bentrix 0.1.382Every number, name and default on these pages is read from the application itself.What is comingWhat changed