Lipi Reference
Lipi

Keywords

func

The other spelling for opening a function declaration. It declares exactly what `def` declares. A body is either a braced block or a single expression after an arrow, and the arrow form also accepts a tuple, which is how a function returns more than one value.

Syntax

                func <function_name>(<data_type> <param_name> [= <default_value>], ...) {
	<function_body>
}
		
func <function_name>(<data_type> <param_name> [= <default_value>], ...) => <expression>
              

Example


          //@lipi=2
indicator("func Example", overlay=true)
// A braced body
func spread(float h, float l) {
    return h - l
}
// An arrow body returning two values
func bounds(int len) => [talib.highest(high, len), talib.lowest(low, len)]
[upper, lower] = bounds(20)
plot(upper, title="Upper", color=color.green)
plot(lower, title="Lower", color=color.red)
plot(lower + spread(upper, lower) / 2, title="Middle", color=color.gray)