Indicator · Pine Script v6 · On the chart

Type Declaration Coverage

by kaigouthro

This script serves as a syntax demonstration and test suite for Pine Script v6 type declarations, created primarily for testing editor syntax highlighters and themes.

View on GitHub

Repaints

GitHub stars21on the repository
Pine versionv6current
Lines of code377
Settings0inputs
LicenceMIT
Last update1 year ago10 Jun 2025

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

377 lines of Pine Script v6 from themes/sytax-types.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

sytax-types.pine


//@version=6
indicator("Type Declaration Coverage", overlay = true)

// =============================================================================
// Library Definition (Imaginary - For Demonstration Purposes)
// =============================================================================

// Assume a library named `myimportlib` with an exported type `ImportedUDT`
// and an exported enum `ExportedEnum` is defined elsewhere.

// @type ImportedUDT, all library code require exported types and enums to have `export` defined
// @field field1 int,defval = 10
// @field field2 string,defval = "hello"
export type ImportedUDT
    int field1 = 10
    string field2 = "hello"


// @enum ExportedEnum, all library code with exoprts require exported types and enums to have `export` defined
// @field VALUE1
// @field VALUE2
export enum ExportedEnum
    VALUE1 = "val 1"
    VALUE2 = "val 2"

    

// ============================== end imagonary lib  area

//import myimportlib/mylibrary/1 as myimportlib // this makes the above real


// =============================================================================
// User-Defined Type (UDT) Definition
// =============================================================================

// @type MyUDT demonstrates all situations where we can use the int/float/string types for defaults, array/matrix/map are not allowed to have any
// @field myIntField int      ,defval = 0
// @field myFloatField float  ,defval = 0.0
// @field myStringField string,defval = "hello"
// @field myBoolField bool    ,defval = false
// @field myColorField color  ,defval = color.red
type MyUDT
    int myIntField = 0
    float myFloatField = 0.0
    string myStringField = "hello"
    bool myBoolField = false
    color myColorField = color.red
    array<int> myArrayField  // no default value for arrays
    matrix<float> myMatrixField // no default value for matrices
    map<string, int> myMapField   // no default value for maps


    
// =============================================================================
// Library type declarations (Imaginary - For Demonstration Purposes)
// =============================================================================
// Imported type
// var ImportedUDT myImportedUDTVar
// varip ImportedUDT myImportedUDTVarip

// map<string, ImportedUDT> myMapOfImportedUDTs = map.new<string, ImportedUDT>()
//matrix<ImportedUDT> myMatrixOfImportedUDTs = matrix.new<ImportedUDT>(2,2)

// =============================================================================
// Primitive Type Declarations
// =============================================================================

// Standard Variable Declaration
int myInt = 10
float myFloat = 3.14
bool myBool = true
string myString = "Pine Script"
color myColor = color.red

// Series Variable Declaration
series int mySeriesInt = 100
series float mySeriesFloat = close
series bool mySeriesBool = close > open
series string mySeriesString = syminfo.ticker
series color mySeriesColor = close > open ? color.green : color.red

// Simple Variable Declaration
simple int mySimpleInt = 20
simple float mySimpleFloat = 6.28
simple bool mySimpleBool = syminfo.type == "stock"
simple string mySimpleString = syminfo.currency
simple color mySimpleColor = color.yellow


// Constant Variable Declaration
const int myConstInt = 30
const float myConstFloat = 9.42
const bool myConstBool = true
const string myConstString = "Constant Value"
const color myConstColor = color.blue

// var Variable Declaration (initializes once per bar)
var int myVarInt = 40
var float myVarFloat = 12.56
var bool myVarBool = false
var string myVarString = "Var Value"
var color myVarColor = color.orange

// varip Variable Declaration (persists across calculations)
varip int myVaripInt = 50, myVaripInt := nz(myVaripInt,50)
varip float myVaripFloat = 15.7, myVaripFloat := nz(myVaripFloat,15.7)
varip bool myVaripBool = true, myVaripBool := myVaripBool
varip string myVaripString = "Varip Value", myVaripString := myVaripString

// =============================================================================
// Built-in Object Declarations
// =============================================================================

// Line Declaration
line myLine = line.new(bar_index[10], low[10], bar_index, high)
var line myVarLine = line.new(bar_index[5], high[5], bar_index, low)

// Label Declaration
label myLabel = label.new(bar_index, high, "Label Text")
var label myVarLabel = label.new(bar_index, low, "Var Label")

// Box Declaration
box myBox = box.new(bar_index[10], high[10], bar_index, low)
var box myVarBox = box.new(bar_index[5], high[5], bar_index, low)

// Table Declaration
table myTable = table.new(position.top_right, 2, 2)
var table myVarTable = table.new(position.bottom_left, 3, 3)

// Linefill Declaration
linefill myLinefill = linefill.new(myLine, myVarLine, color.green)
var linefill myVarLinefill = linefill.new(myLine, myVarLine, color.red)

// chart.point Declaration
chart.point myPoint = chart.point.now(close)
var chart.point myVarPoint = chart.point.from_index(index=bar_index-10,price=low)
varip chart.point myVaripPoint = chart.point.from_time(time=time,price=open)

// polyline Declaration
polyline myPolyline = polyline.new(points=array.from(myPoint,chart.point.now(close)),line_color=color.fuchsia)
var polyline myPolylineVar = na

// =============================================================================
// Array Declarations
// =============================================================================

// Array of int
array<int> myIntArray = array.new<int>()
var array<int> myVarIntArray = array.new<int>(5)
varip array<int> myVaripIntArray = array.from(1, 2, 3)

// Array of float
array<float> myFloatArray = array.new<float>()
var array<float> myVarFloatArray = array.new<float>(5, 0.0)
varip array<float> myVaripFloatArray = array.from(1.1, 2.2, 3.3)

// Array of string
array<string> myStringArray = array.new<string>()
var array<string> myVarStringArray = array.new<string>(3, "empty")
varip array<string> myVaripStringArray = array.from("a", "b", "c")

// Array of bool
array<bool> myBoolArray = array.new<bool>()
var array<bool> myVarBoolArray = array.new<bool>(4, false)
varip array<bool> myVaripBoolArray = array.from(true, false, true)

// Array of color
array<color> myColorArray = array.new<color>()
var array<color> myVarColorArray = array.new<color>(2, color.white)
varip array<color> myVaripColorArray = array.from(color.red, color.green)

// Array of line
array<line> myLineArray = array.new<line>()
var array<line> myVarLineArray = array.new<line>(2, myLine)

// Array of label
array<label> myLabelArray = array.new<label>()
var array<label> myVarLabelArray = array.new<label>(2, myLabel)

// Array of box
array<box> myBoxArray = array.new<box>()
var array<box> myVarBoxArray = array.new<box>(2, myBox)

// Array of table
array<table> myTableArray = array.new<table>()
var array<table> myVarTableArray = array.new<table>(2, myTable)

// Array of linefill
array<linefill> myLinefillArray = array.new<linefill>()
var array<linefill> myVarLinefillArray = array.new<linefill>(2, myLinefill)

// Array of chart.point
array<chart.point> myPointArray = array.new<chart.point>()
var array<chart.point> myVarPointArray = array.new<chart.point>(2, chart.point.now(close))
varip array<chart.point> myVaripPointArray = array.from(chart.point.now(close), chart.point.from_index(bar_index-10,low))

// Array of polyline
array<polyline> myPolylineArray = array.new<polyline>()
var array<polyline> myVarPolylineArray = array.new<polyline>(2)

// Array of UDT
array<MyUDT> myUDTArray = array.new<MyUDT>()
var array<MyUDT> myVarUDTArray = array.new<MyUDT>(3)
varip array<MyUDT> myVaripUDTArray = array.new<MyUDT>(3)


// =============================================================================
// Matrix Declarations
// =============================================================================

// Matrix of int
matrix<int> myIntMatrix = matrix.new<int>(2, 2)
var matrix<int> myVarIntMatrix = matrix.new<int>(3, 3, 0)
varip matrix<int> myVaripIntMatrix = matrix.new<int>(2, 2, 1)

// Matrix of float
matrix<float> myFloatMatrix = matrix.new<float>(2, 2)
var matrix<float> myVarFloatMatrix = matrix.new<float>(3, 3, 0.0)
varip matrix<float> myVaripFloatMatrix = matrix.new<float>(2, 2, 1.0)

// Matrix of string
matrix<string> myStringMatrix = matrix.new<string>(1, 1)
var matrix<string> myVarStringMatrix = matrix.new<string>(2, 2, "empty")
varip matrix<string> myVaripStringMatrix = matrix.new<string>(1, 1, "value")

// Matrix of bool
matrix<bool> myBoolMatrix = matrix.new<bool>(2, 1)
var matrix<bool> myVarBoolMatrix = matrix.new<bool>(2, 2, false)
varip matrix<bool> myVaripBoolMatrix = matrix.new<bool>(1, 1, true)

// Matrix of color
matrix<color> myColorMatrix = matrix.new<color>(2, 2)
var matrix<color> myVarColorMatrix = matrix.new<color>(3, 3, color.white)
varip matrix<color> myVaripColorMatrix = matrix.new<color>(2, 2, color.black)

// Matrix of line
matrix<line> myLineMatrix = matrix.new<line>(2, 2)
var matrix<line> myVarLineMatrix = matrix.new<line>(3, 3, myLine)

// Matrix of label
matrix<label> myLabelMatrix = matrix.new<label>(2, 2)
var matrix<label> myVarLabelMatrix = matrix.new<label>(3, 3, myLabel)

// Matrix of box
matrix<box> myBoxMatrix = matrix.new<box>(2, 2)
var matrix<box> myVarBoxMatrix = matrix.new<box>(3, 3, myBox)

// Matrix of table
matrix<table> myTableMatrix = matrix.new<table>(2, 2)
var matrix<table> myVarTableMatrix = matrix.new<table>(3, 3, myTable)

// Matrix of linefill
matrix<linefill> myLinefillMatrix = matrix.new<linefill>(2, 2)
var matrix<linefill> myVarLinefillMatrix = matrix.new<linefill>(3, 3, myLinefill)

// Matrix of chart.point
matrix<chart.point> myPointMatrix = matrix.new<chart.point>(1, 1)
var matrix<chart.point> myVarPointMatrix = matrix.new<chart.point>(1, 1, chart.point.now(close))
varip matrix<chart.point> myVaripPointMatrix = matrix.new<chart.point>(1, 1, chart.point.from_index ( bar_index-10 , low ))

// Matrix of polyline
matrix<polyline> myPolylineMatrix = matrix.new<polyline>(1, 1)
var matrix<polyline> myVarPolylineMatrix = matrix.new<polyline>(1, 1)

// Matrix of UDT
matrix<MyUDT> myUDTMatrix = matrix.new<MyUDT>(2, 2)
var matrix<MyUDT> myVarUDTMatrix = matrix.new<MyUDT>(3, 3)
varip matrix<MyUDT> myVaripUDTMatrix = matrix.new<MyUDT>(2, 2)


// =============================================================================
// Map Declarations
// =============================================================================

// Map with string keys and int values
map<string, int> myStringIntMap = map.new<string, int>()
var map<string, int> myVarStringIntMap = map.new<string, int>()
varip map<string, int> myVaripStringIntMap = map.new<string, int>()

// Map with int keys and float values
map<int, float> myIntFloatMap = map.new<int, float>()
var map<int, float> myVarIntFloatMap = map.new<int, float>()
varip map<int, float> myVaripIntFloatMap = map.new<int, float>()

// Map with int keys and string values
map<int, string> myIntStringMap = map.new<int, string>()
var map<int, string> myVarIntStringMap = map.new<int, string>()
varip map<int, string> myVaripIntStringMap = map.new<int, string>()

// Map with int keys and bool values
map<int, bool> myIntBoolMap = map.new<int, bool>()
var map<int, bool> myVarIntBoolMap = map.new<int, bool>()
varip map<int, bool> myVaripIntBoolMap = map.new<int, bool>()

// Map with int keys and color values
map<int, color> myIntColorMap = map.new<int, color>()
var map<int, color> myVarIntColorMap = map.new<int, color>()
varip map<int, color> myVaripIntColorMap = map.new<int, color>()

// Map with string keys and UDT values
map<string, MyUDT> myStringUDTMap = map.new<string, MyUDT>()
var map<string, MyUDT> myVarStringUDTMap = map.new<string, MyUDT>()
varip map<string, MyUDT> myVaripStringUDTMap = map.new<string, MyUDT>()

// Map with int keys and UDT values
map<int, MyUDT> myIntUDTMap = map.new<int, MyUDT>()
var map<int, MyUDT> myVarIntUDTMap = map.new<int, MyUDT>()
varip map<int, MyUDT> myVaripIntUDTMap = map.new<int,MyUDT>()

// =============================================================================
// UDT Declarations
// =============================================================================

// Standard UDT Declaration
MyUDT myUDT = MyUDT.new()
var MyUDT myVarUDT = MyUDT.new()
varip MyUDT myVaripUDT = MyUDT.new()

// -----------------------------------------------------------------------------
// -- Enums
// -----------------------------------------------------------------------------

// Enum myEnum
enum myEnum
    VALUE1
    VALUE2
    
var myEnum myenumvar = myEnum.VALUE1



// #############################################################################
// #  Function Definition
// #############################################################################

// With type definition
myFunc(int a, float b) =>
    a + b

// function that retuns udt and uses one as argument
myfunc2(MyUDT a) =>
    a

// Function returning array of type
myFunc3() =>
    array.new<int>()

// Function returning a matrix
myFunc4() =>
    matrix.new<float>(2, 2)

// Function returning a map
myFunc5() =>
    map.new<string, int>()

// #############################################################################
// #  Switch Statement
// #############################################################################

// Switch for conditional logic
string priceAction = switch
    close > open     => "Bullish"
    close < open     => "Bearish"
    => "Neutral"

// Switch with enum
myNextEnum = switch myenumvar
    myEnum.VALUE1 => myEnum.VALUE2
    myEnum.VALUE2 => myEnum.VALUE1
    => na


// The last statemnt in the file
plot(close)

Overview

Type Declaration Coverage defines user-defined types, exported enums, and demonstrates various variable forms across qualifiers such as primitive, series, simple, and constant declarations. The script does not calculate technical indicators, generate trading signals, or render plots on the price chart, and it includes no customizable input settings.

Details

Published by

kaigouthro on GitHub

Type

Indicator, Pine Script v6

Draws

On the price chart

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

  • Signals can change on the live bar or after it closes (repainting)
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

948 stars

The Adaptive Laguerre Filter calculates a smoothed, dynamically adjusted trendline plotted directly on the main price chart. It dynamically adjusts its damping factor (alpha) based on recent price range variations and median percentile calculations over a spec

Indicator v4 TrendMoving averages
Updated 10 days ago · GPL-3.0 GitHub repository of Adaptive Laguerre Filter
575 stars

The indicator plots ICT displacement candles on the price chart and can switch to retracement scanning. Displacement requires a move larger than a set share of the 14-bar average high-low range, lasting at least a chosen number of bars, with optional close, pr

Indicator v6 SMC / ICT / price actionCandlestick patterns
Updated 1 year ago · MPL-2.0 GitHub repository of ICT Displacement Candles Indicator
330 stars

This script plots three moving averages on the price chart: a fast EMA or SMA with 10 periods, a slow EMA or SMA with 20 periods, and a trend EMA or SMA with 100 periods. It signals trend changes by drawing a white cross when the fast moving average crosses ab

Indicator v4 TrendMoving averages
Updated 2 months ago · None stated GitHub repository of 3 EMA/SMA + Cross [Alorse]
318 stars

This indicator calculates an ATR trailing stop line derived from the highest high minus an average true range multiple over a specified lookback period. It plots the trailing stop line directly on the price chart and colors price bars based on whether the clos

Indicator v5 TrendVolatility & bands
Updated 2 months ago · MIT GitHub repository of ATR Trailing Stoploss

1833 Tracker

by Allen1212
303 stars

1833 Tracker is an overlay indicator that visualizes historical buy and sell transactions executed by ARK Invest ETFs for the stock on the main price chart. It displays trade dates using green buy and red sell labels positioned relative to price bars, indicati

Indicator v4
Updated 2 years ago · None stated GitHub repository of 1833 Tracker

More indicators

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers