Skip to content
TradequixDocsOpen the terminal
OverviewStart here, search, progress
  • Introduction
  • Quickstart
  • How a script runs
  • Types and qualifiers
  • Operators, conditionals and loops
  • Functions and methods
  • Objects and enums
  • Arrays, matrices and maps
  • Strings and colours
  • Time and sessions
  • Bar states
  • Plotting
  • Inputs
  • Technical analysis
  • Drawings and tables
  • Multiple timeframes
  • Strategies
  • Alerts in scripts
  • Repainting
  • The Pine editor
  • Indicator settings
  • Coming from TradingView
  • The data
  • Publish and sell
  • Catalogue and community
  • Your dashboard and earnings
  • Errors and debugging
  • Limits
  • Coverage
  • Built-in catalogue
  • Cookbook
  • Write Pine with AI
  • FAQ
  • Glossary
  • Cheat sheet
  • Function reference
  • Will it run here?
  • Error index

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.

View as MarkdownOpen in ClaudeOpen in ChatGPT

Your own functions#

A function is a name, its parameters, =>, and a body. One line:

pine
1pct(a, b) => (a - b) / b * 100

Or several lines, indented; the last line is the result:

RunnableBand position
1//@version=62indicator("Band position")3bandPos(src, len, mult) =>4 [mid, up, lo] = ta.bb(src, len, mult)5 (src - lo) / (up - lo)6plot(bandPos(close, 20, 2), "%B", color = color.purple)7hline(1)8hline(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:

RunnableRange stats
1//@version=62indicator("Range stats", overlay = true)3rangeOf(len) =>4 hi = ta.highest(high, len)5 lo = ta.lowest(low, len)6 [hi, lo, (hi + lo) / 2]7[h, l, m] = rangeOf(30)8plot(h, "High", color = color.teal)9plot(l, "Low", color = color.red)10plot(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).

pine
1method spread(float a, float b) => a - b2d = 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.

PreviousOperators, conditionals and loopsNext Objects and enums

On this page

  • Your own functions
  • Returning several values
  • Methods
  • Libraries

Use with AI

View as MarkdownOpen in ClaudeOpen in ChatGPT