Hi my indicator is supposed to only draw three lines starting at bar_index[15] and ending at bar-index[14] but somehow it draws fewer lines on every bar going back. I think it has something to do with the bar_index but I can't figure it out.
//@version=5
indicator("My Fan", overlay=true, max_bars_back = 400)
drawLines(origX, origY, adjX, adjY) =>
// Calculate key values
dx = adjX - origX
dy = adjY - origY
priceUnit = dy / dx
draw1x1 = input(true, "Draw 1 Line")
draw1x2 = input(true, "Draw 2 Line")
draw2x1 = input(true, "Draw 3 Line")
adjPriceUnit = 1 / 8 // 1/8 line
adjYnew = adjY - (adjPriceUnit * dx)
origYnew = origY
origXnew = origX
adjXnew = adjX
dxnew = adjXnew - origXnew
dynew = adjYnew - origYnew
priceUnitnew = dynew / dxnew
// 1 line
if draw1x1
line.new(origX, origY, adjX, adjYnew, extend=extend.right, color=color.blue, width=2)
// 2 line
if draw1x2
y2 = origYnew + priceUnitnew * 2
line.new(origX, origY, adjX, y2, extend=extend.right, color=color.blue, width=1)
// 3line
if draw2x1
x2 = origXnew + dxnew * 2
line.new(origX, origY, x2, adjY, extend=extend.right, color=color.blue, width=1)
// User inputs
origX = bar_index[15]
origY = input.float(448, "Origin Y")
adjX = bar_index[14]
adjY = input.float(446, "Adjustment Y")
drawLines(origX, origY, adjX, adjY)
I tried changing the bar_index and it just drew more lines...
Your function
drawLines()draws three lines and it is called on every bar. Therefore, you will get many lines. If you only want to keep the last three lines, then you need to delete the old ones.