Why drawing matters
Lines that get plotted every bar are noise. A line drawn on entry, extended to exit, with the PnL labelled — that is information. Pine's drawing objects are how you turn a strategy tester into a chart you can read.
Labels: text annotations
if strategy.position_size == 0 and longCondition
label.new(bar_index, high, "Long", style=label.style_label_down, color=color.green)
Labels are anchored at a specific bar and price. Use them for trade entries, exits, and signal markers.
Lines: trend and stop lines
var line stopLine = na
if strategy.position_size != 0 and strategy.position_size[1] == 0
stopLine := line.new(bar_index, close, bar_index + 50, close - atrVal, color=color.red, width=2)
Lines can be horizontal, sloped, or extended. They auto-extend if you give them a future bar.
Boxes: zones
box.new(left, top, right, bottom) draws a rectangular zone. Use boxes for stop zones, target zones, session ranges, and consolidation zones.
Cleaning up old drawings
Drawing objects persist on the chart. Use label.delete, line.delete, box.delete to remove old ones, or use max_lines_count, max_labels_count, max_boxes_count in the indicator/strategy declaration to cap the total number Pine keeps.
A trade-management dashboard
if barstate.islast
var table dash = table.new(position.top_right, 2, 4)
table.cell(dash, 0, 0, "Direction", text_color=color.white)
table.cell(dash, 1, 0, strategy.position_size > 0 ? "Long" : strategy.position_size < 0 ? "Short" : "Flat")
table.cell(dash, 0, 1, "Entry", text_color=color.gray)
table.cell(dash, 1, 1, str.tostring(strategy.position_avg_price, "#.##"))
table.cell(dash, 0, 2, "Unrealized", text_color=color.gray)
table.cell(dash, 1, 2, str.tostring(strategy.openprofit, "#.##"))
table.cell(dash, 0, 3, "Risk", text_color=color.gray)
table.cell(dash, 1, 3, str.tostring(equityRisk, "#.##") + "%")
What to take from this
A chart with annotations is a tool. A chart without annotations is a price line. Take the time to make the strategy legible at a glance — it changes how you react during live trading.