OsMA MACD histogram
The MACD line minus its signal line, drawn as a histogram.
It measures the gap that the MACD histogram already draws, published as its own indicator. Readings: the zero crossings, which by construction fall on the same bars as MACD's line-signal crosses, and the histogram's own slope, which turns before those crossings do.
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. OsMA has no value on the first 8 — the bars it needs before it can answer — and its first value stands on bar 9. Its bars run between -0.00048 and 0.0008 on these bars, and the last value is -0.00012. Counting the conditions the study declares on these bars: crosses above 0 15 times; crosses below 0 16 times. Press a condition under the figure to see each place marked. As states rather than moments: is above 0 on 129 bars; is below 0 on 163 bars.
02Its parts, named
03What you see
Bars around zero in their own pane: MACD minus its signal line. The bars are tall when MACD is far above or below its signal and short when the two are close.
04Where it comes from
Gerald Appel created MACD in the late 1970s. Thomas Aspray added the histogram in 1986 to show MACD's distance from its signal line at a glance; MetaTrader names it OsMA — Moving Average of Oscillator.
05The formula
MACD = EMA(C, 12) − EMA(C, 26), OsMA = MACD − SMA(MACD, 9)
The signal subtracted here is a simple average of the MACD line, as MetaTrader 5's OsMA computes it, and the two EMAs start at the first price. The MACD study's own histogram subtracts an exponential signal, so the two differ a little.
06A worked example
Take the closes 20, 21, 23, 22, 24, 25, 24, 26 with a fast EMA of 2, a slow EMA of 4 and a signal of 2, each started at the first value to keep the example short.
On the last bar the fast EMA reads 25.38 and the slow one 24.64.
MACD = 25.38 − 24.64 = 0.74
The MACD line over the eight bars is 0.00, 0.27, 0.78, 0.41, 0.76, 0.89, 0.42, 0.74. The signal is the simple average of the last two values of that line: (0.42 + 0.74) / 2 = 0.58. OsMA is the difference of the two: 0.74 − 0.58 = 0.16.
On the bar before, the signal was (0.89 + 0.42) / 2 = 0.66 and OsMA 0.42 − 0.66 = −0.24: the bar has crossed from below zero to above it, which is the MACD line crossing above its signal.
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("Moving Average of Oscillator") fastLength = input.int(12, "Fast") slowLength = input.int(26, "Slow") signalLength = input.int(9, "Signal") // MetaTrader's exponential average: it starts at the first close and takes a share of every new close. fastAlpha = 2.0 / (fastLength + 1) slowAlpha = 2.0 / (slowLength + 1) var float fastEma = na var float slowEma = na fastEma := na(fastEma[1]) ? close : fastAlpha * close + (1 - fastAlpha) * fastEma[1] slowEma := na(slowEma[1]) ? close : slowAlpha * close + (1 - slowAlpha) * slowEma[1] macd = fastEma - slowEma // The signal is a simple average of the MACD line, and the bars are the gap between the two. signal = ta.sma(macd, signalLength) osma = macd - signal plot(osma, "OsMA", style = plot.style_histogram) hline(0)
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
Crossing zero. The histogram crossing zero is exactly MACD crossing its signal line.
Bars shrinking. Read as MACD's distance from its signal narrowing — the earliest of MACD's events, since it shows before the lines cross.
Divergence. A lower histogram peak under a higher price peak is read as the move continuing with less acceleration.
How a shrinking histogram fails. Shrinking bars say the MACD line is closing on its signal — the pace of the move is easing. Moves ease and resume all the time; the bars shrink and grow again without ever crossing zero.
How the zero crossing fails. It is the MACD crossing its signal, with every weakness of that crossing in a sideways market.
09In different markets and timeframes
OsMA is the MACD histogram alone: it measures whether the MACD line is pulling away from its signal. It turns before the MACD crosses its signal and long before it crosses zero; in a range its bars alternate.
10With other studies
Read under the MACD it is made from, where its zero crossings are the signal crossings.
11What it does not tell you
It is a difference of a difference of averages: very smooth inputs, describing only how they changed recently. A shrinking histogram is common in a move that then continues.
12Inputs and defaults
- 1Fast period — 12The shorter EMA of the MACD underneath.
- 2Signal period — 9The simple average of the MACD line that is subtracted from it. Longer: larger, slower bars.
- 3Slow period — 26The longer EMA.
- 4Applied price — CloseAny of the seven prices, and several at once, each its own line with its own look.
- 5Timeframe — ChartThe chart's own by default; any higher one, read on the last closed candle. A finer one is never offered.
- 6Wait 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 use12, 26, 9, as for MACD.
13Limits and common misreadings
Price units. Like MACD it is in the market's own price units; the same height means different things on different markets.
MetaTrader's form. OsMA is computed as MetaTrader 5 computes it, its signal a simple average of MACD. The histogram of the MACD study, whose signal is an exponential average by default, differs from it a little.
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
Attach MACD and OsMA together and step through one MACD cross. Count how many bars before the cross the histogram began to shrink.
Open the laboratory17In Bentrix
- From the menu: a chart's Indicators button › Oscillators › OsMA, or type OsMA 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": "osma"}).
The study, as a chart files it
This is a new OsMA’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": "osma",
"settings": {
"fast": 12,
"shape": "fast_slow_signal",
"signal": 9,
"slow": 26
}
}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": "osma",
"settings": {
"fast": 12,
"shape": "fast_slow_signal",
"signal": 9,
"slow": 26
}
}
}
}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": "osma", "settings": {"fast": 12, "shape": "fast_slow_signal", "signal": 9, "slow": 26}}, 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": "mt5", "kind": "osma", "settings": { "fast": 12, "shape": "fast_slow_signal", "signal": 9, "slow": 26 } }, 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"] = "mt5", ["kind"] = "osma", ["settings"] = new Dictionary<string, object?> { ["fast"] = 12, ["shape"] = "fast_slow_signal", ["signal"] = 9, ["slow"] = 26 } }, 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": "mt5", "kind": "osma", "settings": map[string]any{"fast": 12, "shape": "fast_slow_signal", "signal": 9, "slow": 26}}, 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", "osma", "settings", obj("fast", 12, "shape", "fast_slow_signal", "signal", 9, "slow", 26))).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", "mt5"}, {"kind", "osma"}, {"settings", Json::Object{{"fast", 12}, {"shape", "fast_slow_signal"}, {"signal", 9}, {"slow", 26}}}}).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" => "osma", "settings" => Dict{String,Any}("fast" => 12, "shape" => "fast_slow_signal", "signal" => 9, "slow" => 26)); 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 = "mt5", kind = "osma", settings = list(fast = 12, shape = "fast_slow_signal", signal = 9, slow = 26)), 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": "mt5", "kind": "osma", "settings": {"fast": 12, "shape": "fast_slow_signal", "signal": 9, "slow": 26}})).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.- Its fixed levels, drawn on the chart:
[0.0].
line | What it is |
|---|---|
Main | the indicator's own value |
In a strategy
Filed under a key of your choice in a strategy document’s studies — here osma: {"osma": {"applied": "close", "convention": "mt5", "kind": "osma", "settings": {"fast": 12, "shape": "fast_slow_signal", "signal": 9, "slow": 26}}} — its rules can name:
| Write | What it is |
|---|---|
osma | its main line, as a value in a compare |
{"cond": "osma:level.cross_up:0"} | a condition it declares itself |
{"cond": "osma:level.cross_down:0"} | a condition it declares itself |
{"cond": "osma:level.above:0"} | a condition it declares itself |
{"cond": "osma:level.below:0"} | a condition it declares itself |
19Sources
- Appel, Gerald. Technical Analysis: Power Tools for Active Investors. FT Prentice Hall, 2005.
- Aspray, Thomas. "MACD Momentum." Technical Analysis of Stocks & Commodities, August 1986.
Bentrix 0.1.382Every number, name and default on these pages is read from the application itself.What is comingWhat changed