plot, the drawing calls (line.new, label.new, box.new, …) may be called inside an if, a loop or a function. They
return a handle you can keep, change and delete.
find the level
talib.highest(source, length) is the highest value of source over the last length bars. We plot it first to see what we are
going to draw.draw the line on the last bar
line.new(x1, y1, x2, y2) draws a line between two points. The x values are bar numbers (bar_index is the number of the bar the
script is on), the y values are prices. barstate.islast is true only on the last bar, so the line is drawn once the script reaches
the end of the history. extend=extend.right carries it past the last bar.math.max keeps the start
from going below bar 0 on a short chart.add the label
label.new(x, y, text) puts text at a point. The text is joined from strings, and numbers are converted with str.tostring.keep the drawings and move them
A drawing stays on the chart until the script deletes it or the limit for its kind trims it (50 of each kind unless the declaration
raises it). A script that calls Name the string variable something other than
line.new every time it reaches the last bar adds a line each time. Instead, create the line and
the label once, hold them in static variables, and move them afterwards.static line levelLine = naandstatic label levelLabel = nadeclare empty handles that last across bars.na(levelLine)is true until a line has been assigned to it, so the first branch runs once.line.set_xy1,line.set_xy2,label.set_xyandlabel.set_textchange the existing drawings.
text: text is the name of a built-in namespace, and a variable called text
compiles with the warning Variable `text` hides the built-in namespace `text`.What we built
An indicator with one setting that keeps a single line and a single label on the chart and moves them to the current highest high of the last N bars.Next
- Lines, labels, boxes and polylines: every drawing function and its arguments.
- How to keep one label that moves with the last bar
- How to keep drawings under the limit