Getting Started

Quickstart & Scene Lifecycle

Configure TradingView drawing budgets, create one persistent scene, build geometry once, mutate it later, and render exactly one frame at a time.

Updated Publisher Alien_AlgorithmsPine Script v6

Setup requirements

Required declaration and importpine
//@version=6
indicator("My 3D Scene", overlay = false,
  max_polylines_count = 100,
  max_lines_count = 500,
  max_labels_count = 500)

import Alien_Algorithms/Pine3D/1 as p3d

Raise all three drawing budgets because Pine3D can use polylines, lines, linefills, and labels in one scene. These values are TradingView’s hard maximums.

Your first scene

Lit animated spherepine
//@version=6
indicator("My First 3D Scene", overlay = false,
  max_polylines_count = 100,
  max_lines_count = 500,
  max_labels_count = 500)

import Alien_Algorithms/Pine3D/1 as p3d

var p3d.Scene scene = p3d.newScene()
var p3d.Mesh sun = na

if barstate.isfirst
    scene.setLightDir(1.0, -1.0, 0.5).setAmbient(0.3)
    sun := p3d.sphere(50.0, 16, 12, color.orange).setTag("sun")
    scene.add(sun)
    p3d.wireGrid(scene, 300.0, 300.0, 6, 6, color.new(color.gray, 80))
    scene.camera.orbit(35.0, 25.0, 220.0)

if barstate.islast
    sun.rotateBy(0.0, 1.5, 0.0)
    p3d.render(scene, lighting = true)

The scene and mesh use var, so they persist. Geometry is allocated on the first bar. The last bar mutates rotation and renders the frame.

The scene lifecycle

  • Create one scene: initialize p3d.newScene() in a persistent variable.
  • Build once: create meshes, labels, grids, and other overlays inside barstate.isfirst.
  • Mutate later: update transforms, surface data, bar values, trail samples, or overlay fields on later bars.
  • Render once: call p3d.render(scene) once per frame, normally inside barstate.islast.
The core pattern
Build once, mutate later, render once. Rebuilding geometry every bar wastes CPU and drawing resources.

Scene clear vs. frame clear

scene.clear()

scene.clear() removes meshes, labels, lines, and polylines from the persistent scene graph. Most scripts do not need it.

render()

render() clears the previous TradingView drawings and redraws the current scene graph. It does not remove scene objects.

Manual drawings are also cleared
Render clears the full chart drawing pool. Create manual labels or lines after the Pine3D render call if they need to remain visible. Tables are unaffected.

Global-scope series calculations

Compute history-dependent values such as close[1], ta.rsi(), ta.atr(), and request.security() at global scope. Pass the completed data into last-bar update methods afterward.

Pine3D is a graphical rendering library for Pine Script. TradingView drawing, execution, and publication limits still apply. © Alien_Algorithms.