Declaration and import pine //@version=6
indicator("My Canvas", overlay = false, max_polylines_count = 100)
import Alien_Algorithms/PineCanvas/1 as pcWith the alias pc, functions are called as pc.name() and methods on the object they belong to. Methods that configure or write return their object, so calls chain. Use the latest version number shown on the TradingView publication.
Type What it is pc.ValueFieldA fixed grid of numbers, coloured through the Canvas gradient. Fields: rows, columns. pc.PaletteFieldA fixed grid of exact palette indices. Fields: rows, columns. pc.ValueScrollA rolling window of number columns. Fields: rows, capacity, written. pc.PaletteScrollA rolling window of palette-index columns. Fields: rows, capacity, written. pc.CanvasHolds colours and style, owns its polylines, and draws sources and shapes. pc.StyleA complete rendering configuration, built with pc.newStyle(). pc.ScaleModeWhat automatic scaling measures: wholeGrid, eachColumn, or eachRow.
Call Description pc.valueField(int rows, int columns, float initial = na)A grid of numbers. At least 1 row, and 1 to 100,000 columns. na cells are transparent. pc.paletteField(int rows, int columns, int initial = -1)A grid of exact palette indices. -1 is transparent and 0 is the first palette colour. pc.valueScroll(int rows, int capacity)A rolling source of number columns. Rows and capacity from 2 to 99,999. pc.paletteScroll(int rows, int capacity)A rolling source of palette-index columns. scroll.push(array<float> column)Appends one column of exactly rows values to a ValueScroll, bottom row first. Overwrites the oldest once full. scroll.push(array<int> column)The same for a PaletteScroll.
These methods exist on both ValueField and PaletteField. The value is a float for one and an int for the other.
Call Description field.get(int row, int column)Reads one cell. field.set(int row, int column, value)Writes one cell and returns the field. field.fill(value)Writes one value into every cell and returns the field. field.row(int row)A writable array that shares one row's storage. Do not resize it. field.bandCount()The number of storage bands, at least 1. field.band(int index)The writable array of one band, in row-major order. Do not resize it. field.bandStart(int index)The field row a band begins at. field.bandRows(int index)How many complete rows a band stores.
Stamps write into a field, clip to its bounds, and return the field. Coordinates are rows and columns.
Call Description field.rect(int row0, int column0, int row1, int column1, value, bool filled = true)A filled rectangle, or its outline when filled is false. field.segment(int row0, int column0, int row1, int column1, value)A straight line of cells. field.circle(int centerRow, int centerColumn, int radius, value, bool filled = false)A one-cell ring, or a disc when filled is true.
Call Description pc.newCanvas(array<color> colors = na)Full opacity and a fixed value range of 0 to 1. na selects black and white. pc.heatmap(array<color> colors = na)Automatic scaling, 64 colour levels, and 15 to 90 opacity. na selects a thermal gradient. pc.gradient(color lowColor, color highColor)A two-stop colour array. pc.gradient(color color0, color color25, color color50, color color75, color color100)A five-stop colour array. pc.newStyle(int colorLevels = 64, float lowOpacity = 15.0, float highOpacity = 90.0, bool autoScale = false, float valueMin = 0.0, float valueMax = 1.0, float gamma = 1.0, bool logarithmicY = false, bool invertRows = false, bool forceOverlay = false, ScaleMode scaleMode = ScaleMode.wholeGrid, int drawingLimit = 100)Builds a complete Style.
Every method below returns the Canvas.
Call Description canvas.palette(array<color> colors)Replaces the palette or the gradient stops. 2 to 100 colours. canvas.colorLevels(int count)Samples a value source's gradient into 2 to 100 levels. No effect on palette sources. canvas.opacity(float lowOpacity, float highOpacity = na)Opacity from the lowest level to the highest, 0 to 100. One argument applies to every level. canvas.autoScale(ScaleMode mode = ScaleMode.wholeGrid)Takes the value range from the data: the whole grid, each column, or each row. canvas.valueRange(float minimum, float maximum)A fixed value range, with automatic scaling off. The maximum must exceed the minimum. canvas.gamma(float value)The response curve. Greater than 0. Below 1 lifts weak values, above 1 suppresses them. canvas.logarithmicY(bool enabled = true)Logarithmic row spacing for regular placement. Needs positive vertical bounds. canvas.invertRows(bool enabled = true)Puts row 0 at the top. canvas.forceOverlay(bool enabled = true)Places the drawings on the main price chart. canvas.drawingLimit(int count)Caps the polylines this Canvas may own, from 1 to 100. canvas.configure(Style style)Copies a complete Style into the Canvas. canvas.clear()Deletes every polyline the Canvas owns.
Every draw call returns the Canvas and replaces its previous drawings. field is a ValueField or a PaletteField, and scroll is a ValueScroll or a PaletteScroll.
Call Description canvas.drawLookback(field, int lookback, float bottom, float top, int rightOffset = 0)Places a field ending at the current bar. lookback is the width in bars: 0 uses one bar per column, otherwise it must be at least the column count. canvas.drawLookback(scroll, float bottom, float top, int rightOffset = 0)Draws a rolling source at its current column count, newest column on the right. Needs at least two pushed columns. canvas.draw(field, int leftIndex, int rightIndex, float bottom, float top)Places a field between two bar indices. The span must be at least the column count. canvas.drawTime(field, int leftTime, int rightTime, float bottom, float top)Places a field between two UNIX timestamps in milliseconds. canvas.drawGrid(field, array<int> columnEdges, array<float> rowEdges)Explicit edges: strictly increasing bar indices, columns + 1 of them, and strictly increasing vertical values, rows + 1 of them. canvas.drawTimeGrid(field, array<int> timeEdges, array<float> rowEdges)The same, with timestamps in milliseconds as the horizontal edges.
Shape points are chart.point values made with chart.point.from_time(). The queueing methods return the Canvas.
Call Description canvas.rect(chart.point topLeft, chart.point bottomRight, color fillColor)Queues an axis-aligned rectangle from two opposite corners. canvas.triangle(chart.point cornerA, chart.point cornerB, chart.point cornerC, color fillColor)Queues a triangle, in any orientation. canvas.circle(chart.point centre, int radiusTime, float radiusPrice, int segments, color fillColor)Queues an ellipse. radiusTime is in milliseconds, radiusPrice in price units, segments from 3 to 9,999. canvas.poly(array<chart.point> points, color fillColor)Queues any closed polygon of 3 to 9,999 points, convex or concave. canvas.drawShapes()Draws the queue, replaces the Canvas's previous drawings, empties the queue, and returns the number of polylines created. canvas.clearShapes()Discards the queue without drawing it. Returns the Canvas. canvas.shapeCount()The number of shapes queued and not yet drawn. pc.barsToTime(int offsetBars)Estimates a timestamp from a bar offset on the current timeframe. It does not account for session gaps.
Call Description canvas.drawingCount()The number of polylines the Canvas currently owns. canvas.componentCount()The number of connected same-colour regions the last field render found, or 0 before any render. canvas.dimensions()A [rows, columns] tuple from the last field render, or [0, 0] before any render and after clear(). canvas.scaledRange()A [minimum, maximum] tuple: the value range the last field render used. Both are na for an empty field.
Limit Value Polylines per script 100, shared by every Canvas and any other polylines Points per polyline 10,000 Colours in a palette or gradient 2 to 100 Colour levels of a value source 2 to 100 Field size to be drawn 2 to 99,999 rows and columns Cells before the large renderer takes over 100,000 Bar-index placement 10,000 bars back, 500 bars forward Shape batch 100,000 source vertices and 100 fill colours Points in one shape 3 to 9,999
The same reference is kept as plain Markdown , ready to paste into an editor or an AI assistant.