Language
Functions and methods
Write your own functions with =>, return several values as a tuple, and call functions as methods. Libraries and import are not available.
Your own functions#
A function is a name, its parameters, =>, and a body. One line:
pct(a, b) => (a - b) / b * 100Or several lines, indented; the last line is the result:
//@version=6indicator("Band position")bandPos(src, len, mult) => [mid, up, lo] = ta.bb(src, len, mult) (src - lo) / (up - lo)plot(bandPos(close, 20, 2), "%B", color = color.purple)hline(1)hline(0)Each call keeps its own history, so calling a function that uses ta.* inside it twice with different arguments gives two independent results.
Returning several values#
Return a tuple and destructure it at the call:
//@version=6indicator("Range stats", overlay = true)rangeOf(len) => hi = ta.highest(high, len) lo = ta.lowest(low, len) [hi, lo, (hi + lo) / 2][h, l, m] = rangeOf(30)plot(h, "High", color = color.teal)plot(l, "Low", color = color.red)plot(m, "Mid", color = color.gray)Methods#
A function declared with method can be called with a dot on its first argument. Built-in functions for arrays and drawings can be called the same way: arr.push(x) is array.push(arr, x).
method spread(float a, float b) => a - bd = close.spread(open)Libraries#
Pine libraries (library() and import user/name/1) are not available on Tradequix: there is no library resolver. Copy the functions you need into your script. The checker flags imports for you.