Hello everyone, looking for an indicator that plots 4 horizontal lines that works on all intraday timeframes. First plot line starts at 10am, second plot line starts at 11am, third plot line starts at 1pm, and fourth plot line starts at 2pm. All 4 lines draw to the end of trading hour. Indicator should have an option to turn on/off plots on all previous days. I search the forums but can't find one. Would any experts in this be so kind to create one? Thanks in advance.
I have this code but it doesn't work. Can anyone take a look to see what's not working?
I have this code but it doesn't work. Can anyone take a look to see what's not working?
Code:
# Define the input parameters
input showPreviousDays = yes; # option to show/hide previous days' lines
input line1Start = "10:00"; # time for first line to start (format: "HH:MM")
input line2Start = "11:00"; # time for second line to start (format: "HH:MM")
input line3Start = "13:00"; # time for third line to start (format: "HH:MM")
input line4Start = "14:00"; # time for fourth line to start (format: "HH:MM")
input lineColor = color.blue; # color of the lines
input lineWeight = 2; # weight of the lines
# Calculate the line times based on the regular trading hours
def regularSessionStart = secondsFromTime(0930); # 9:30 AM EST
def line1Time = regularSessionStart + secondsFromTime(line1Start + ":00");
def line2Time = regularSessionStart + secondsFromTime(line2Start + ":00");
def line3Time = regularSessionStart + secondsFromTime(line3Start + ":00");
def line4Time = regularSessionStart + secondsFromTime(line4Start + ":00");
def regularSessionEnd = secondsFromTime(1600); # 4:00 PM EST
# Plot the lines
plot line1 = if showPreviousDays or getDay() == getLastDay() then line1Time else double.nan;
line1.SetStyle(curve.FIRM);
line1.SetDefaultColor(lineColor);
line1.SetLineWeight(lineWeight);
plot line2 = if showPreviousDays or getDay() == getLastDay() then line2Time else double.nan;
line2.SetStyle(curve.FIRM);
line2.SetDefaultColor(lineColor);
line2.SetLineWeight(lineWeight);
plot line3 = if showPreviousDays or getDay() == getLastDay() then line3Time else double.nan;
line3.SetStyle(curve.FIRM);
line3.SetDefaultColor(lineColor);
line3.SetLineWeight(lineWeight);
plot line4 = if showPreviousDays or getDay() == getLastDay() then line4Time else double.nan;
line4.SetStyle(curve.FIRM);
line4.SetDefaultColor(lineColor);
line4.SetLineWeight(lineWeight);
# Extend the lines to the end of the trading day
line1.SetExtend(true);
line2.SetExtend(true);
line3.SetExtend(true);
line4.SetExtend(true);
# Define a function to get the last trading day's date
def getLastDay() {
# Get the current date and time in milliseconds
def currentDate = GetYYYYMMDD();
def currentTime = GetTime();
def currentDateTime = currentDate * 1000 + currentTime;
# Look for the last trading day's date
def lastDay = currentDate - 1;
while (GetDay() != lastDay && lastDay >= GetCurrentYear() * 10000) {
lastDay--;
}Iam
return lastDay;
}
Last edited by a moderator: