Drawings & Colors
Pine Script compatible drawing primitives (chart.point.*, polyline.new, polygon.new, fib.new, box.new, line.new, label.new) and color/gradient helpers exposed by the v1.0.6 runtime.
color.new(colorStr, transparency)
Creates a transparent or semi-transparent color string. The transparency parameter scales from 0 (completely opaque) to 100 (completely transparent). Mapped to browser-native rgba() under the hood.
const fillCol = color.new(color.green, 85); // 85% transparent green
color.gradient(color1, color2, vertical = true) (v1.0.6)
Generates a gradient fill definition interpolating between color1 and color2 along vertical (default) or horizontal geometry axes for custom fills and polygons.
box.new(left, top, right, bottom, bgcolor, border_c, border_w)
Creates a viewport rectangle spanning from bar index left to right, and price levels top to bottom. Supports dynamic solid/alpha backgrounds, borders, and Pine tooltip= strings.
const zone = box.new(
50, 1.2500,
100, 1.2450,
color.new(color.red, 90),
color.red,
1
);
Related helpers:
box.delete(boxObj): Removes the specified box object from the canvas.box.set_bgcolor(boxObj, color)&box.set_border_color(boxObj, color): Modifies fill and border colors.box.set_left(boxObj, left)/box.set_right(boxObj, right): Updates the horizontal bar boundaries.
line.new(x1, y1, x2, y2, color, style, width)
Draws a segment between (x1, y1) and (x2, y2) using bar indices/prices or chart.point anchors. Styles include 'solid' | 'dashed' | 'dotted' and ray modes (extend.right, extend.left, extend.both).
const trendLine = line.new(startIndex, lowVal, endIndex, highVal, color.blue, 'dashed', 2);
Related helpers:
line.get_price(lineObj, barIdx): Computes projected price along a trendline at barbarIdx.line.delete(lineObj): Removes the specified line object from the active list.
label.new(x, y, text, color, style, textcolor, size)
Creates a styled text label bubble anchored at bar index x and price level y (or a chart.point). Style options include 'up' | 'down' | 'left' | 'triangleup' | 'triangledown' | 'arrowup' | 'arrowdown' plus interactive tooltip= support.
label.new(i, low, "BUY", color.green, 'up', color.white, 'normal');
Related helpers:
label.delete(labelObj): Deletes the specified label object from the active list.
chart.point.*, polyline.new & polygon.new (v1.0.6)
Build multi-vertex vector paths, smoothed curves, and closed geometric polygons anchored by chart.point objects:
chart.point.new(time, index, price),chart.point.from_index(index, price),chart.point.from_time(time, price),chart.point.copy(pt).polyline.new(points, curved, closed, xloc, line_color, fill_color, line_style, line_width): Draws open paths or closed filled shapes across anychart.point[]array.polygon.new(points, color, fill_color, width)/ctx.polygon.new(...): Renders filled polygons directly onto the price pane.
pts = array.from(
chart.point.from_index(bar_index - 10, low[10]),
chart.point.from_index(bar_index - 5, high[5]),
chart.point.from_index(bar_index, close)
)
polyline.new(pts, curved=true, closed=false, line_color=color.aqua, line_width=2)
linefill.new(line1, line2, color)
Fills the area between two active line objects with a colored, semi-transparent background fill. Extremely useful for drawing custom channels, Keltner Bands, or moving average ribbons.
const l1 = line.new(start, high1, end, high2, color.blue);
const l2 = line.new(start, low1, end, low2, color.blue);
linefill.new(l1, l2, color.new(color.blue, 90));
fib.new(...) & Dynamic Fibonacci Mutators (v1.0.6)
Draws Fibonacci retracements from either 4 coordinates fib.new(startBar, startPrice, endBar, endPrice, color) or two chart.point anchors, with mutable level sets and styling helpers:
.set_levels(levelsArray): Customize ratios (e.g.,[0, 0.382, 0.5, 0.618, 0.786, 1, 1.618])..set_color(color),.set_extend(extendMode),.set_first_point(pt), and.set_second_point(pt).
const f = fib.new(chart.point.from_index(startIdx, lowPrice), chart.point.from_index(endIdx, highPrice), color.purple);
f.set_levels([0, 0.382, 0.618, 0.786, 1.0]);
Interactive Tooltips & Hit-Testing (v1.0.6)
Attach interactive hover tooltips to box.new and label.new objects using tooltip= in Direct Pine Mode or the JS options object. For custom canvas widgets, combine ctx.registerTooltip(...) with is_hovered(barIndex, priceLevel, width, height).
// Pine Mode: native tooltip parameter on box.new / label.new
box.new(bar_index - 5, high, bar_index, low, bgcolor=color.new(color.green, 85), tooltip="Order Block Zone")
// JavaScript Mode
box.new(bar1, price1, bar2, price2, {
bgcolor: 'rgba(255,0,0,0.2)',
tooltip: 'Bullish Engulfing Pattern Detected!\nVolume: High'
});