this draws a giant plus sign, a vertical line and a horizontal line, on the chart.
default center is $1 below the close on bar # 80.
it has a height of $2 and a width of 9 bars.
related to this question
https://usethinkscript.com/threads/vertical-horizontal-lines.21035/
default center is $1 below the close on bar # 80.
it has a height of $2 and a width of 9 bars.
related to this question
https://usethinkscript.com/threads/vertical-horizontal-lines.21035/
Code:
# addchart_hline_vline
def na = double.nan;
def bn = barnumber();
input vertical_line_ht = 2.0;
#hint line_ht: Total height of the vertical line, in dollars
input line_yoffset = -1.0;
#hint yoffset: This is the price difference, from the close, to the top of the line. a negative number moves the line below the candle. positive number moves line above candle
input line_barnum = 80;
#hint barnum: Draw a vertical line at a specific barnumber
addlabel(1, "vertical line ht " + vertical_line_ht, color.yellow);
addlabel(1, "line y offset " + line_yoffset , color.yellow);
addlabel(1, "line barnum " + line_barnum , color.yellow);
addchartbubble(bn == line_barnum, high*1.002,
"Bar# " + bn + "\n" +
"close " + close
, color.yellow, yes);
#-------------------
# vert line
def vlinetop = close + line_yoffset;
def vlinemid = vlinetop - (vertical_line_ht/2);
def linebot = vlinetop - vertical_line_ht;
def ht = if bn == line_barnum then vlinetop else na;
def lt = ht - vertical_line_ht;
def ct = vlinemid;
def ot = vlinemid;
# uses the grow color
input type = ChartType.CANDLE;
AddChart(high = ht,low = lt,open = ot,close = ct, growColor = Color.cyan, fallColor = color.magenta, type = type);
#-------------------
addlabel(1, " ", color.black);
input horz_line_bar_length = 9;
addlabel(1, "horizontal line length, bars " + horz_line_bar_length , color.yellow);
def hhalf = floor(horz_line_bar_length/2);
def hline_first_bn = line_barnum - hhalf;
def hline_last_bn = hline_first_bn + horz_line_bar_length - 1;
def hline = (bn >= hline_first_bn and bn <= hline_last_bn);
def hline2 = if bn == hline_first_bn then vlinemid[-hhalf]
else if hline then hline2[1]
else na;
plot z1 = hline2;
z1.setdefaultcolor(color.cyan);
#