Documentation Annotations
Pine Script supports special comment tags that attach documentation to declarations. These annotations are used by the LSP (for hover and completions) and by the documentation generator.
Both //@tag and // @tag (with a space after //) formats are supported.
Available Tags
| Tag | Placement | Description |
|---|---|---|
@function | Above a function declaration | Adds a custom description for the function |
@param | Above a function declaration | Adds a description for a parameter. Specify the parameter name, then its description |
@returns | Above a function declaration | Adds a description for the return value |
@type | Above a type or newtype declaration | Adds a custom description for the type |
@enum | Above an enum declaration | Adds a custom description for the enum |
@field | Above a type or enum declaration | Adds a description for a field or variant. Specify the field name, then its description |
@variable | Above a variable declaration | Adds a custom description for the variable |
All tags support multi-line continuation: lines starting with // (without a @ tag) immediately after a tag line are appended to that tag's text.
Documenting Functions
Use @function, @param, and @returns to document function declarations:
// @function Outputs a label with `labelText` on the bar's high.
// @param labelText (series string) The text to display on the label.
// @returns The drawn label ID.
export drawLabel(string labelText) =>
label.new(bar_index, high, text = labelText)@param and @returns can appear either before or after the @function tag:
//@param series Series of values to process.
//@param length Number of bars (length).
//@function Arnaud Legoux Moving Average.
//
// It uses Gaussian distribution as weights for moving average.
export series float alma(series float series, simple int length) =>
// ...Multi-line Descriptions
Continuation lines (starting with // but without @) extend the previous tag's description:
//@function Calculates the percentage difference
// from the base price to the target price.
//@param basePrice The start price
// used as the reference point.
//@param price The end price.
//@returns The signed deviation percentage.
export calcDeviation(float basePrice, float price) =>
100 * (price - basePrice) / basePriceDocumenting Types
Use @type and @field to document type declarations:
//@type A point on a chart.
//@field index The index of the bar where the point is located, i.e., its `x` coordinate.
//@field price The price where the point is located, i.e., its `y` coordinate.
type Point
int index
float priceThe @type tag also works for newtype declarations:
//@type Handle for a label drawing object.
export type label => intDocumenting Enums
Use @enum and @field to document enum declarations and their variants:
//@enum Represents a trading direction.
//@field long A long (buy) direction.
//@field short A short (sell) direction.
//@field both Both directions.
enum Direction
long
short
both = "Both Directions"Documenting Variables
Use @variable to document variable declarations:
//@variable The highest price over the last 20 bars.
float highest20 = ta.highest(high, 20)
//@variable Tracks cumulative volume since the session started.
var float cumVol = 0.0Editor Support
When documentation annotations are present, the OpenPine LSP uses them to provide:
- Hover information — shows the description, parameters, return value, and field docs when hovering over a symbol
- Completion details — shows the summary in autocomplete suggestions
- Document symbols — includes the summary in the outline view
Library Documentation
For exported libraries, documentation annotations are especially important. The documentation generator (openpine-docgen) extracts these annotations to produce API reference pages:
//@version=6
library("MyLib")
//@type Configuration for a custom indicator.
//@field length The lookback period.
//@field multiplier The standard deviation multiplier.
export type Config
int length = 14
float multiplier = 2.0
//@function Calculates a custom band around a moving average.
//@param src The source series.
//@param config The indicator configuration.
//@returns The upper band value.
export upperBand(series float src, Config config) =>
basis = ta.sma(src, config.length)
basis + config.multiplier * ta.stdev(src, config.length)