Schaff Trend Cycle STC
The MACD line passed twice through a stochastic over the cycle window, each pass smoothed, so the result runs between 0 and 100 and turns sooner than the MACD it is built from.
It measures where the MACD sits in its own recent range.
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. STC has no value on the first 67 — the bars it needs before it can answer — and its first value stands on bar 68. Its line runs between 0 and 100 on these bars, and the last value is 69.21. The pane's scale is fixed at 0 to 100, the range the study can take. Counting the conditions the study declares on these bars: crosses above 25 9 times; crosses below 25 8 times; crosses above 75 6 times; crosses below 75 6 times. Press a condition under the figure to see each place marked. As states rather than moments: is above 25 on 99 bars; is below 25 on 134 bars; is above 75 on 67 bars; is below 75 on 166 bars.
02Its parts, named
03What you see
A line in its own pane between 0 and 100 that spends long stretches at its extremes and moves quickly from one to the other.
04Where it comes from
Doug Schaff, a currency trader, developed the Schaff Trend Cycle in the 1990s. His idea was to take MACD — a trend measure — and pass it through a Stochastic twice, so that it would turn faster and sit flat at its extremes while a trend held.
05The formula
From MACD's line (fast 23, slow 50 by default), take its Stochastic over a cycle of bars (10), smooth it, then take the Stochastic of that and smooth again (factor 0.5):
%K₁ = 100 · (MACD − min ₖ(MACD))/(max ₖ(MACD) − min ₖ(MACD)), D₁ = D_(1,t−1) + 0.5 (%K₁ − D_(1,t−1))
%K₂ = 100 · (D₁ − min ₖ(D₁))/(max ₖ(D₁) − min ₖ(D₁)), STC = STC_(t−1) + 0.5 (%K₂ − STC_(t−1))
06A worked example
The chain has four links; follow one bar through them with a cycle of 10.
- The MACD line (fast 23, slow 50) reads 0.42. Over the last 10 bars it ranged from −0.10 to 0.60: its stochastic is (0.42 − (−0.10)) / (0.60 − (−0.10)) × 100 = 74.3.
- That value is smoothed with a factor of 0.5: if the smoothed figure stood at 60.0, it becomes 60.0 + 0.5 × (74.3 − 60.0) = 67.1.
- The smoothed figure's own last 10 values ranged from 20.0 to 80.0: its stochastic is (67.1 − 20.0) / (80.0 − 20.0) × 100 = 78.5.
- Smoothed once more with 0.5 from a previous 70.0: 74.3 — the value drawn.
Two stochastic passes force the result into 0–100 and make it move fast between the ends, which is the look of the line: long stays near 0 and 100 joined by steep runs.
On real closes — 20, 22, 21, 23, 22, 21, 23, 24, 22, 23 — with a MACD of 2 and 3 and a cycle of 3, the line reads 100.0 on the eighth bar, 50.0 on the ninth, after the fall from 24 to 22, and 25.0 on the last: from the top of its scale to a quarter of it in two bars.
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("Schaff Trend Cycle") fastLength = input.int(23, "Fast") slowLength = input.int(50, "Slow") cycleLength = input.int(10, "Cycle") // TA-Lib's STC: a MACD line (fast minus slow exponential average) put through a stochastic over `cycleLength` // bars, smoothed by half, and put through a stochastic and smoothed again; a flat window keeps the last reading. stc = talib.STC(close, fastLength, slowLength, cycleLength) plot(stc, "STC") hline(75) hline(25)
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
Leaving the extremes. A rise from below 25 or a fall from above 75 is read as MACD's position within its own recent range changing direction.
Flat at 100 or 0. Read as MACD holding the top or bottom of its recent range — a trend in force by MACD's measure.
How the 25 and 75 levels fail. A rise through 25 is read as an up-cycle beginning. The double stochastic makes the line binary: it spends most of its time pinned near 0 or 100, where it carries no information about how far price has gone.
How its speed fails. It turns sooner than MACD because it measures the MACD against its own recent range; when that range is tiny — a flat market — trivial changes of the MACD swing the line across its whole scale.
09In different markets and timeframes
The Schaff Trend Cycle is MACD passed twice through a stochastic: it moves quickly between its ends and sits at them, so it marks changes of cycle rather than measuring strength.
With 23, 50 and 10 the MACD underneath needs some 50 bars and looks back about ten weeks of daily bars. In a long trend the line sits at 100 or at 0 for the length of it and says nothing more; in a range it travels the whole scale with each swing, and on short timeframes it does so many times a day. Schaff worked on currency pairs, where he set the cycle input to half the cycle he expected.
10With other studies
Read beside the MACD it is built from, which keeps the sense of size the STC removes.
11What it does not tell you
Its sharp moves come from a double Stochastic of MACD; they describe that construction, not the size of the move in price. A quick swing from 0 to 100 can follow a small change in MACD.
12Inputs and defaults
- 1Fast Period — 23Period of the fast EMA
- 2Slow Period — 50Period of the slow EMA
- 3Cycle Period — 10Window of both stochastic stages
- 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.
What each input changes
- Fast PeriodThe MACD's short EMA (23).
- Slow PeriodThe MACD's long EMA (50).
- Cycle PeriodThe window of both stochastic passes (10). Schaff suggested half the cycle length expected.
- In use23, 50 and 10 are Schaff's.
13Limits and common misreadings
Flat-lining. At the extremes it carries no information until it leaves them.
Sensitivity. Small changes of the cycle length change it a great deal; settings suited to one market rarely suit another.
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 STC and MACD together. Step through a range-bound day and count how often STC travelled its whole range while MACD barely moved.
Open the laboratory17In Bentrix
- From the menu: a chart's Indicators button › Oscillators › STC, or type STC 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": "stc"}).
The study, as a chart files it
This is a new STC’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": "stc",
"settings": {
"shape": "ta",
"values": {
"optInCyclePeriod": 10.0,
"optInFastPeriod": 23.0,
"optInSlowPeriod": 50.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": "stc",
"settings": {
"shape": "ta",
"values": {
"optInCyclePeriod": 10.0,
"optInFastPeriod": 23.0,
"optInSlowPeriod": 50.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": "stc", "settings": {"shape": "ta", "values": {"optInCyclePeriod": 10.0, "optInFastPeriod": 23.0, "optInSlowPeriod": 50.0}}}, 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": "talib", "kind": "stc", "settings": { "shape": "ta", "values": { "optInCyclePeriod": 10.0, "optInFastPeriod": 23.0, "optInSlowPeriod": 50.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#
var values = await client.Study.Values(bench, market, "H1", new Dictionary<string, object?> { ["applied"] = "close", ["convention"] = "talib", ["kind"] = "stc", ["settings"] = new Dictionary<string, object?> { ["shape"] = "ta", ["values"] = new Dictionary<string, object?> { ["optInCyclePeriod"] = 10.0, ["optInFastPeriod"] = 23.0, ["optInSlowPeriod"] = 50.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"]!}");
}Go
values := must(client.Study.Values(ctx, mcp.StudyValuesArgs{Bench: bench, Symbol: market, Timeframe: "H1", Study: map[string]any{"applied": "close", "convention": "talib", "kind": "stc", "settings": map[string]any{"shape": "ta", "values": map[string]any{"optInCyclePeriod": 10.0, "optInFastPeriod": 23.0, "optInSlowPeriod": 50.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", "stc", "settings", obj("shape", "ta", "values", obj("optInCyclePeriod", 10.0, "optInFastPeriod", 23.0, "optInSlowPeriod", 50.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++
auto values = client.study.values_(StudyApi::ValuesArgs(bench, market, "H1", Json::Object{{"applied", "close"}, {"convention", "talib"}, {"kind", "stc"}, {"settings", Json::Object{{"shape", "ta"}, {"values", Json::Object{{"optInCyclePeriod", 10.0}, {"optInFastPeriod", 23.0}, {"optInSlowPeriod", 50.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" => "stc", "settings" => Dict{String,Any}("shape" => "ta", "values" => Dict{String,Any}("optInCyclePeriod" => 10.0, "optInFastPeriod" => 23.0, "optInSlowPeriod" => 50.0))); 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 = "talib", kind = "stc", settings = list(shape = "ta", values = list(optInCyclePeriod = 10.0, optInFastPeriod = 23.0, optInSlowPeriod = 50.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")
}Rust
let values = client.study().values(mcp::StudyValuesArgs::new(bench.clone(), market.clone(), "H1", serde_json::json!({"applied": "close", "convention": "talib", "kind": "stc", "settings": {"shape": "ta", "values": {"optInCyclePeriod": 10.0, "optInFastPeriod": 23.0, "optInSlowPeriod": 50.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 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:
[25.0, 75.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 stc: {"stc": {"applied": "close", "convention": "talib", "kind": "stc", "settings": {"shape": "ta", "values": {"optInCyclePeriod": 10.0, "optInFastPeriod": 23.0, "optInSlowPeriod": 50.0}}}} — its rules can name:
| Write | What it is |
|---|---|
stc | its main line, as a value in a compare |
{"cond": "stc:level.cross_up:25"} | a condition it declares itself |
{"cond": "stc:level.cross_down:25"} | a condition it declares itself |
{"cond": "stc:level.above:25"} | a condition it declares itself |
{"cond": "stc:level.below:25"} | a condition it declares itself |
{"cond": "stc:level.cross_up:75"} | a condition it declares itself |
{"cond": "stc:level.cross_down:75"} | a condition it declares itself |
{"cond": "stc:level.above:75"} | a condition it declares itself |
{"cond": "stc:level.below:75"} | a condition it declares itself |
19Sources
- Colby, Robert W. The Encyclopedia of Technical Market Indicators, 2nd ed. McGraw-Hill, 2003 (the components).
Bentrix 0.1.382Every number, name and default on these pages is read from the application itself.What is comingWhat changed