Reputation: 11
How do I create a draggable vertical line in pinescript?
I managed to create simple indicator based on Gann Box. I'm facing some issues since I'm a beginner at Pine Script coding:
version=5
indicator(title="Gann Box", overlay=true)
// Inputs
L1 = input.float(62500, "Horizontal Line 1 Price", inline = "1")
L2 = input.float(63750, "Horizontal Line 2 Price", inline = "2")
L3 = input.float(65450, "Horizontal Line 3 Price", inline = "3")
CP1 = input.string(title='', options=[" Up", " Down"], defval=" Up", inline = "1")
CP2 = input.string(title='', options=[" Up", " Down"], defval=" Up", inline = "2")
CP3 = input.string(title='', options=[" Up", " Down"], defval=" Up", inline = "3")
lineDate1 = input.time(timestamp("26 Apr 2024 13:30"), title="Line Location1")
lineDate2 = input.time(timestamp("26 Apr 2024 14:30"), title="Line Location2")
lineDate3 = input.time(timestamp("26 Apr 2024 15:30"), title="Line Location3")
//
var VLine1 = line.new(x1=na, y1=na, x2=na, y2=na,
color=color.green, width=2,style = line.style_solid, xloc=xloc.bar_time)
var VLine2 = line.new(x1=na, y1=na, x2=na, y2=na,
color=color.green, width=2,style = line.style_solid, xloc=xloc.bar_time)
var VLine3 = line.new(x1=na, y1=na, x2=na, y2=na,
color=color.green, width=2,style = line.style_solid, xloc=xloc.bar_time)
//
line.set_xy1(VLine1, x=lineDate1, y=L1)
line.set_xy2(VLine1, x=lineDate3, y=L1)
line.set_xy1(VLine2, x=lineDate1, y=L2)
line.set_xy2(VLine2, x=lineDate3, y=L2)
line.set_xy1(VLine3, x=lineDate1, y=L3)
line.set_xy2(VLine3, x=lineDate3, y=L3)
Label1 = label.new(x=lineDate3, y=L1,text= " " + str.tostring(L1) + "-" + CP1, color=color.green, textcolor=color.white, size=size.normal, style=label.style_label_left, xloc=xloc.bar_time)
Label2 = label.new(x=lineDate3, y=L2,text= " " + str.tostring(L2) + "-" + CP2, color=color.green, textcolor=color.white, size=size.normal, style=label.style_label_left, xloc=xloc.bar_time)
Label3 = label.new(x=lineDate3, y=L3,text= " " + str.tostring(L3) + "-" + CP3, color=color.green, textcolor=color.white, size=size.normal, style=label.style_label_left, xloc=xloc.bar_time)
// Make both trend lines once
var vLine1 = line.new(x1=na, y1=na, x2=na, y2=na,
color=color.green, width=2,style = line.style_solid, xloc=xloc.bar_time)
var vLine2 = line.new(x1=na, y1=na, x2=na, y2=na,
color=color.green, width=2,style = line.style_solid, xloc=xloc.bar_time)
var vLine3 = line.new(x1=na, y1=na, x2=na, y2=na,
color=color.green, width=2,style = line.style_solid, xloc=xloc.bar_time)
// Update the lines' location on every bar
line.set_xy1(vLine1, x=lineDate1, y=L1)
line.set_xy2(vLine1, x=lineDate1, y=L3)
line.set_xy1(vLine2, x=lineDate2, y=L1)
line.set_xy2(vLine2, x=lineDate2, y=L3)
line.set_xy1(vLine3, x=lineDate3, y=L1)
line.set_xy2(vLine3, x=lineDate3, y=L3)
Upvotes: 1
Views: 141
Reputation: 1
instead of input.float, Use input.price() for draggable horizantal lines and input.time for vertical lines.
Upvotes: 0