Skip to content

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

TagPlacementDescription
@functionAbove a function declarationAdds a custom description for the function
@paramAbove a function declarationAdds a description for a parameter. Specify the parameter name, then its description
@returnsAbove a function declarationAdds a description for the return value
@typeAbove a type or newtype declarationAdds a custom description for the type
@enumAbove an enum declarationAdds a custom description for the enum
@fieldAbove a type or enum declarationAdds a description for a field or variant. Specify the field name, then its description
@variableAbove a variable declarationAdds 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:

pine
// @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:

pine
//@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:

pine
//@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) / basePrice

Documenting Types

Use @type and @field to document type declarations:

pine
//@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 price

The @type tag also works for newtype declarations:

pine
//@type Handle for a label drawing object.
export type label => int

Documenting Enums

Use @enum and @field to document enum declarations and their variants:

pine
//@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:

pine
//@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.0

Editor 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:

pine
//@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)

Released under the MIT License.