triangle
Draws a Triangle by connecting three anchors. It’s handy for outlining zones, marking chart patterns, or highlighting areas of interest. You can softly fill the interior and choose a clean outline.
Syntax (one line)
triangle(pointA, pointB, pointC, styles?)
Parameters
pointA (PricedData) · First corner (time & price).
pointB (PricedData) · Second corner (time & price).
pointC (PricedData) · Third corner (time & price).
styles (TriangleLineToolOverrides) · Visual options for outline and fill:
backgroundColor(RGBAColor | BaseColors) · Fill color inside the triangle.color(RGBAColor | BaseColors) · Outline color.fillBackground(boolean) · Turn the interior fill on/off.linewidth(number) · Outline thickness.transparency(number) · 0–100 fill transparency (higher = lighter).
Return Value
(string) · The drawing ID of the created Triangle.
Example
What this does: Every 42 candles, it draws a soft orange triangle around a recent swing structure. We keep all visuals in one const style.
//@version=1
init = () => {
indicator({ onMainPanel: true, format: 'inherit' });
};
onTick = () => {
if (index % 42 === 0) { // draw occasionally to keep charts clean
// 1) Pick three anchors
const A = newPoint(time(80), high(80));
const B = newPoint(time(55), low(55));
const C = newPoint(time(30), closeC(30));
// 2) Style (TriangleLineToolOverrides)
const style = {
color: color.orange, // outline
linewidth: 2,
fillBackground: true, // fill the interior
backgroundColor: color.rgba(255, 165, 0, 0.2),
transparency: 80
};
// 3) Draw the triangle
triangle(A, B, C, style);
}
};Tips
Use triangles to frame consolidation or pattern zones you want to watch.
Keep fills subtle so candles remain visible; raise
transparencyif it feels heavy.
Warning
Extremely small triangles (few pixels) are hard to read; choose anchors that form a clear shape.
Good Practice
Reuse a small set of color presets for shapes (e.g., orange for highlights, blue for ranges) to keep charts consistent.
Keep your
const stylecentralized so you can tweak looks quickly across scripts.
Last updated