Drawings
Rectangles, lines, texts, Fibonacci and all the other chart drawings, created from code.

Creating a drawing
Drawings aren’t declared: they are created in the code, with draw.type(points, …). The type is the drawing’s name in snake_case: rectangle, trend_line, horizontal_line, text, fib_retracement… All the types, with how many points they need, are in the draw reference.
draw.rectangle((start, high), (end, low), fill={"color": color("#2962FF", 15)})
draw.horizontal_line((0, 70), line={"color": color("#787B86"), "pattern": "dashed"})
draw.text((i, high), text={"value": f"High {format.price(high)}"})They return nothing and don’t go in the dictionary: all the drawings created during the calculation appear. It’s best to create them when they are final, usually at the end.
Points
- Each point is
(index, price), with the index of a chart candle. As in Python,-1is the latest. - After the latest candle the index goes on, up to 500: the point falls where the chart expects that candle. This way
draw.trend_line((i, p), (i + 1, p))works on the latest one too. - With
xloc="time"the points’ x values are times in UTC milliseconds, likebars.time: useful when the x comes from a time of day or another timeframe.
# Up to 16:00: the latest candle opens at 15:00, so one hour is missing.
end = bars.time[-1] + 60 * 60 * 1000
draw.trend_line((bars.time[-1], price), (end, price), xloc="time")Style
The other arguments are the drawing’s settings, written as in Colors and style, text included: text={"value": "…"}. Colors are hexadecimal. To let the user choose the style, use the style inputs and pass them to the drawing.
An example: each day’s low
At the end of each day the script looks for the candle with the low and puts a price label on it, which writes the value by itself.

from totaltrade.v1 import indicator, request, draw
@indicator(short="Lows", overlay=True)
def calculate(bars=request.bars()):
new_day = bars.new_period("D")
start = 0
for i in range(1, len(bars.close) + 1):
if i < len(bars.close) and not new_day[i]:
continue
# The low of the day just ended, with its price.
bottom = start
for j in range(start, i):
if bars.low[j] < bars.low[bottom]:
bottom = j
draw.price_label((bottom, bars.low[bottom]))
start = iHow many drawings
An indicator keeps at most max_drawings drawings, 500 if you don’t write it, up to 10,000: beyond that, the last ones created remain. Every drawing has a cost, both to create and to draw, so it’s best to stop when you have enough.
BUBBLES = 200
@indicator(overlay=True, max_drawings=BUBBLES)
def calculate(bars=request.bars()):
count = 0
for i in reversed(range(len(bars.close))): # from the most recent candle
if count == BUBBLES:
break
...They can’t be selected or saved: they are recreated at every calculation. Drawings that calculate by themselves, like volume profiles and the anchored VWAP, only receive the position and load their own data.