Market Open

You might also like

Download as rtf, pdf, or txt
Download as rtf, pdf, or txt
You are on page 1of 3

//@version=5

indicator("Market Open", overlay=true)

// *** Input Settings for Lines and Labels ***

lineColor = input(#00ff08, "Horizontal Line Color")

lineType = input.string("dotted", "Horizontal Line Style", options=["solid", "dotted", "dashed"])

lineWidth = input.int(2, "Horizontal Line Width", minval=1, maxval=5)

showVerticalLine = input(true, "Show Vertical Line")

verticalLineColor = input(#00ff08, "Vertical Line Color")

verticalLineStyle = input.string("dotted", "Vertical Line Style", options=["solid", "dotted", "dashed"])

verticalLineWidth = input.int(2, "Vertical Line Width", minval=1, maxval=5)

showLabel = input(true, "Show Label")

labelTextColor = input(color.white, "Label Text Color")

labelSizeOption = input.string("Normal", "Label Size", options=["Normal", "Small", "Large"])

labelSize = switch labelSizeOption

"Large" => size.large

"Small" => size.small

"Normal" => size.normal

labelVOffset = input.float(0, "Vertical Offset", step=0.1)

labelHOffset = input.int(40, "Horizontal Offset", step=1)

// *** Time and Calculations ***

target_hour = (6 + 3) % 24
target_minute = 30

var float lowestLow = na

var float highestHigh = na

lowestLow := ta.lowest(low, 100)

highestHigh := ta.highest(high, 100)

var float openPrice = na

var line myLine = na

var label myLabel = na

var line myVerticalLine = na

var string labelText = "" // Proper initialization of labelText

// *** Main Script Execution ***

if (hour == target_hour and minute == target_minute)

openPrice := open

labelText := "Market Open - " + str.tostring(openPrice) // Set labelText based on openPrice

if na(myLine)

myLine := line.new(bar_index, openPrice, bar_index + 100, openPrice, color=lineColor,


width=lineWidth, extend=extend.right, style=lineType == "solid" ? line.style_solid : lineType ==
"dotted" ? line.style_dotted : line.style_dashed)

if showVerticalLine

myVerticalLine := line.new(bar_index, lowestLow, bar_index, highestHigh, color=verticalLineColor,


width=verticalLineWidth, extend=extend.both, style=verticalLineStyle == "solid" ? line.style_solid :
verticalLineStyle == "dotted" ? line.style_dotted : line.style_dashed)

else

line.set_xy1(myLine, bar_index, openPrice)

line.set_xy2(myLine, bar_index + 100, openPrice)


line.set_color(myLine, lineColor)

if showVerticalLine and not na(myVerticalLine)

line.set_x1(myVerticalLine, bar_index)

line.set_x2(myVerticalLine, bar_index)

line.set_y1(myVerticalLine, lowestLow)

line.set_y2(myVerticalLine, highestHigh)

line.set_color(myVerticalLine, verticalLineColor)

if showLabel

if na(myLabel)

myLabel := label.new(bar_index + labelHOffset, openPrice + labelVOffset, labelText,


color=labelTextColor, size=labelSize, style=label.style_none, xloc=xloc.bar_index)

else

label.set_xy(myLabel, bar_index + labelHOffset, openPrice + labelVOffset)

label.set_text(myLabel, labelText)

label.set_textcolor(myLabel, labelTextColor)

label.set_size(myLabel, labelSize)

You might also like