0

I am new to pinescript and wrote this simple script to show me daily, weekly and monthly candle open lines by piecing together information I could find. This works well but I would like to add input options to change the line(s) width and style (dotted, dashed). Seems like an easy task, but somehow I can't figure it out. Could anybody help?

A bit more work but, my next step would be to be able to toggle an option where, after a period ends, the line would extend until it is crossed by price again. If there is an easy way to do this, I would be much grateful for any tips.

Thanks in advance!

//@version=6
indicator("D/W/M Open Lines", overlay=true, max_lines_count=500)
// === Input Options ===
showDaily = input.bool(true, title="Show Daily Open")
showWeekly = input.bool(true, title="Show Weekly Open")
showMonthly = input.bool(false, title="Show Monthly Open")
dailyColor = input.color(color.aqua, "Daily Line Color")
weeklyColor = input.color(color.yellow, "Weekly Line Color")
monthlyColor = input.color(color.fuchsia, "Monthly Line Color")
// === Line Variables ===
var line dailyLine = na
var line weeklyLine = na
var line monthlyLine = na
// === Daily Line Logic ===
dailyOpen = request.security(syminfo.tickerid, "D", open)
dailyTime = request.security(syminfo.tickerid, "D", time)
newDaily = dailyTime != dailyTime[1]
if showDaily
 if newDaily
 if not na(dailyLine)
 line.set_x2(dailyLine, x=dailyTime)
 dailyLine := line.new(x1=dailyTime, y1=dailyOpen, x2=time, y2=dailyOpen, color=dailyColor, extend=extend.none, xloc=xloc.bar_time)
 else if not na(dailyLine)
 line.set_x2(dailyLine, x=time)
// === Weekly Line Logic ===
weeklyOpen = request.security(syminfo.tickerid, "W", open)
weeklyTime = request.security(syminfo.tickerid, "W", time)
newWeekly = weeklyTime != weeklyTime[1]
if showWeekly
 if newWeekly
 if not na(weeklyLine)
 line.set_x2(weeklyLine, x=weeklyTime)
 weeklyLine := line.new(x1=weeklyTime, y1=weeklyOpen, x2=time, y2=weeklyOpen, color=weeklyColor, extend=extend.none, xloc=xloc.bar_time)
 else if not na(weeklyLine)
 line.set_x2(weeklyLine, x=time)
// === Monthly Line Logic ===
monthlyOpen = request.security(syminfo.tickerid, "M", open)
monthlyTime = request.security(syminfo.tickerid, "M", time)
newMonthly = monthlyTime != monthlyTime[1]
if showMonthly
 if newMonthly
 if not na(monthlyLine)
 line.set_x2(monthlyLine, x=monthlyTime)
 monthlyLine := line.new(x1=monthlyTime, y1=monthlyOpen, x2=time, y2=monthlyOpen, color=monthlyColor, extend=extend.none, xloc=xloc.bar_time)
 else if not na(monthlyLine)
 line.set_x2(monthlyLine, x=time)
Jonathan
9237 silver badges25 bronze badges
asked Jun 16, 2025 at 13:02

1 Answer 1

0

More than one way to do it, this is my preferred method using enums.

//@version=6
indicator("My script", overlay = true)
enum lineStyle
 solid = 'Solid' 
 dashed = 'Dashed' 
 dotted = 'Dotted'
method styler(lineStyle this)=>
 switch this
 lineStyle.solid => line.style_solid
 lineStyle.dashed => line.style_dashed
 lineStyle.dotted => line.style_dotted
newLineStyle = input.enum(lineStyle.solid, title = ' ', inline = '1').styler()
if barstate.islast
 line.new(bar_index, high, bar_index + 5, high, style = newLineStyle)

You could also do it using a string input and a switch statement. Either way will get you the result you want

newLineStyle = input.string('Solid', 'Line Style', ['Solid', 'Dashed', 'Dotted'])
style = switch newLineStyle
 'Solid' => line.style_solid
 'Dashed' => line.style_dashed
 'Dotted' => line.style_dotted
if barstate.islast
 line.new(bar_index, high, bar_index + 5, high, style = style)
answered Jun 16, 2025 at 14:10
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.