millionchart
فارسی

The language

Functions of your own, with guards and default arguments, in programs that are compiled and run.

Small programs about the shape of the language itself.

User functions#

A block function with a guard, a one-line function and an argument given by name.

Cuprel
// Your own functions: a block function with a guard, a one-line function, and an argument given by name.
indicator "User functions"
    edition = 1
    display = pane

fn body_share(open_price: float, close_price: float, high_price: float, low_price: float): float
    let range = high_price - low_price
    if range == 0
        return na
    return math.abs(close_price - open_price) / range

fn scaled(x: float, factor: float = 100.0): float = x * factor

plot(scaled(body_share(open, close, high, low)), name = "Body as a percent of the range")
plot(scaled(0.5), name = "Half", color = color.gray)