A whole indicator — two averages, the space between them filled, a mark where they cross — written, run and changed, line by line.
Open the IDE (the Assay button on the application's bar, or New Assay script in a chart's indicator menu) and type this:
//@version=6
indicator("Two averages", overlay = true)
fastLen = input.int(9, "Fast length", minval = 1)
slowLen = input.int(21, "Slow length", minval = 1)
fast = ta.ema(close, fastLen)
slow = ta.sma(close, slowLen)
p1 = plot(fast, "Fast", color = color.new(color.blue, 0), linewidth = 2)
p2 = plot(slow, "Slow", color = color.new(color.orange, 0))
fill(p1, p2, color = fast > slow ? color.new(color.blue, 85) : color.new(color.orange, 85))
plotshape(ta.crossover(fast, slow), "Crossed above", shape.triangleup, location.belowbar, color.blue)
plotshape(ta.crossunder(fast, slow), "Crossed below", shape.triangledown, location.abovebar, color.orange)
Press F5: the script runs over the chart in front, and its lines appear.
01Line by line
//@version=6 — the version of the dialect the text is written in. Every version from 1 to 6 runs; this line is what tells Bentrix which one to read.
indicator("Two averages", overlay = true) — the declaration. Every script has exactly one: indicator(…) for a study, strategy(…) for a strategy, library(…) for a library. overlay = true draws over the price; without it the study gets a pane of its own.
input.int(9, "Fast length", minval = 1) — a setting. It appears in the study's settings card under Inputs, with its default and its limit; the script reads whatever the person sets. See Inputs and output.
ta.ema(close, fastLen) — a built-in. close is the bar's close; ta.ema is the exponential average of it over fastLen bars, computed by Bentrix's own indicator code in the study's Calculation convention. The script is run once per bar, so fast is a series — a value per bar — even though the line reads like a single assignment. See The language.
plot(…) — a line of the study. It answers a handle (p1) that fill uses to fill the space between two lines.
fast > slow ? … : … — a condition chosen bar by bar: the fill's colour follows which average is above.
plotshape(ta.crossover(fast, slow), …) — a mark on each bar where the condition is true: here, the bar where the fast average crosses above the slow one.
02Change it, and watch
With the preview on (the eye icon), the chart in front shows the script as you type: change 21 to 50 and the slow line moves 400 ms after you stop. Save it (Ctrl+S) and it goes into your indicators folder; tick it in Settings › Indicators and it is under My indicators on every chart.
03When something is wrong
Problems are underlined as you type and listed in the Problems view, each with its line, its column and a sentence saying what is wrong — a name the dialect does not have, an argument of the wrong type, a built-in Bentrix refuses. Nothing runs halfway: a script either checks and runs, or says why it does not.
04What to read next
- The language for series, history and variables — the three ideas everything else rests on.
- The reference pages for ta, plotting and the bar's values and input.