Write your first indicator in Cuprel
By MillionChart Team · · 2 min read

Cuprel is the language for writing your own indicators and strategies on MillionChart. This walk-through builds a small indicator: two exponential moving averages and a marker on the bar where the faster one crosses above the slower one.
The script
Open the script editor on the chart, start a new indicator and replace its text with these lines. The two indented lines belong to the indicator header, so keep their spaces.
//@cuprel 1
indicator "Two averages"
edition = 1
display = price
input fast: int = 9, "Fast length"
input slow: int = 21, "Slow length"
let quick = tech.ema(close, fast)
let calm = tech.ema(close, slow)
plot(quick, name = "Fast")
plot(calm, name = "Slow")
mark.shape(tech.crosses_above(quick, calm), "cross")
What each part does
The first line names the language and its version. The indicator header gives the script a title and says that it draws on the price pane. The two input lines create settings that appear in the Inspector, so you can change the lengths without editing the code.
The let lines calculate a value on every bar. The word close means the closing price of the bar being calculated. The plot lines draw those values, and the name you give each plot is the name shown in the legend. The last line places a mark on bars where the crossing condition is true.
Try changes one at a time
- Change the default lengths and watch how often the marker appears.
- Plot the difference between the two averages in a pane of its own.
- Add a second mark for the downward crossing.
Check your work honestly
A marker on a past chart can look convincing. Use bar replay to see when the mark would actually have appeared, and remember that the newest candle is still forming: a crossing can appear and vanish before the candle closes. Waiting for the close removes much of that surprise.
The scripting section of the wiki covers inputs, drawings, tables, alerts and strategies in more depth, with examples you can copy. When the editor reports an error, it names the line and explains what it expected, so fix one message at a time. Your scripts are private to you unless you choose to publish them.