Vertical line and Opening Price

AdalWolf

New member
Hello Guys,
I am looking for a script for TOS that can put a vertical line at midnight NY time (custom Time zone even better) and a horizontal line for the opening price of midnight and 8:30 open. Are there any scripts similar to this? I do have script Trading View but I am not from the coding background so I can make it for TOS. Please help! Here are codes for Trading VIew:
https://www.tradingview.com/script/Pt0Kk3PV-ICT-NEW-YORK-MIDNIGHT-OPEN-AND-8-30-AM-OPEN/

Thank you in Advance🙏🏻
@FutureTony
 
Last edited by a moderator:
Solution
Great indicator, instead of the open can it be made to plot the line at the close at first 930 bar, and can the line agg on the 15min agg and yet show on a 5 min agg. chart

Here is 15m close @0930 on a 5m chart with a vertical line @0930. The line on the 5m moves until the 15m opening bar closes

Screenshot 2024-01-26 151505.png
Code:
#Midnight_Vertical_Open_830_Vertical_Open
input openingTime1 = 0930;
input openingTime2 = 0930;
input agg          = AggregationPeriod.FIFTEEN_MIN;
input showvertical = yes;
input showbubble   = yes;


def sec1 = SecondsFromTime(openingTime1);
def sec2 = SecondsFromTime(openingTime2);
def isTime1 = (sec1 >= 0 and sec1[1] < 0) or (sec1 < sec1[1] and sec1 >= 0);
def isTime2 = (sec2 >= 0 and sec2[1] < 0) or (sec2 <...
@FutureTony, Thank you for the indicator. Do you have any indicator for TOS that can put a vertical line at midnight NY time (custom Time zone even better) and a horizontal line for the opening price of midnight and 8:30 open?
I do have script Trading View but I am not from the coding background so I can make it for TOS. Please help! Here are codes for Trading VIew:
https://www.tradingview.com/script/Pt0Kk3PV-ICT-NEW-YORK-MIDNIGHT-OPEN-AND-8-30-AM-OPEN/
I think that should be fairly easy. I'm working on a Globex, Midnight and NY Open vertical plus the horizontals for the price at two defined times (midnight and 8:30 are the default). Just fixing a couple small things and will post later. Just FYI, this will only work on time-based charts.

2HRbRq7.png
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

I think that should be fairly easy. I'm working on a Globex, Midnight and NY Open vertical plus the horizontals for the price at two defined times (midnight and 8:30 are the default). Just fixing a couple small things and will post later. Just FYI, this will only work on time-based charts.

2HRbRq7.png

This will use nearest time if opening times had no trading.

Capture.jpg
Ruby:
#Midnight_Vertical_Open_830_Vertical_Open
input openingTime1 = 0000;
input openingTime2 = 0830;

def sec1 = SecondsFromTime(openingTime1);
def sec2 = SecondsFromTime(openingTime2);
def isTime1 = (sec1 >= 0 and sec1[1] < 0) or (sec1 < sec1[1] and sec1 >= 0);
def isTime2 = (sec2 >= 0 and sec2[1] < 0) or (sec2 < sec2[1] and sec2 >= 0);

def  op1   = if isTime1 then open else op1[1];
plot open1 = op1;
open1.setpaintingStrategy(paintingStrategy.HORIZONTAL);
AddVerticalLine(isTime1, " ", open1.takevalueColor(), Curve.FIRM);
addchartBubble(isnan(close[-1]) and !isnan(close), open1,"Midnight",open1.takevalueColor());

def  op2   = if isTime2 then open else op2[1];
plot open2 = op2;
open2.setpaintingStrategy(paintingStrategy.HORIZONTAL);
AddVerticalLine(isTime2, " ",  open2.takevalueColor(), Curve.FIRM);
addchartBubble(isnan(close[-1]) and !isnan(close), open2,"830",open2.takevalueColor());
;
 
I think that should be fairly easy. I'm working on a Globex, Midnight and NY Open vertical plus the horizontals for the price at two defined times (midnight and 8:30 are the default). Just fixing a couple small things and will post later. Just FYI, this will only work on time-based charts.

2HRbRq7.png
Perfect Thank you so much
 
Yeah thanks, it does the work. I think it would be better if it have the option to turn off the old line and only show for the current day as it makes lots of lines on the chart and some people find it distracting.

Modified with todayonly option and a bubblemover option

Ruby:
#Midnight_Vertical_Open_830_Vertical_Open
input todayonly    = yes;
input openingTime1 = 0000;
input openingTime2 = 0830;
input bubblemover  = 3;
def bm  = bubblemover;
def bm1 = bm + 1;

def sec1 = SecondsFromTime(openingTime1);
def sec2 = SecondsFromTime(openingTime2);
def isTime1 = (sec1 >= 0 and sec1[1] < 0) or (sec1 < sec1[1] and sec1 >= 0);
def isTime2 = (sec2 >= 0 and sec2[1] < 0) or (sec2 < sec2[1] and sec2 >= 0);

def  op1   = if isTime1 then open else op1[1];
plot open1 = if todayonly and GetDay() != GetLastDay() then Double.NaN else op1;
open1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
AddVerticalLine(if todayonly and GetDay() != GetLastDay() - 1 then Double.NaN else isTime1, " ", open1.TakeValueColor(), Curve.FIRM);
AddChartBubble(IsNaN(close[bm]) and !IsNaN(close[bm1]), open1[bm1], "Midnight", open1.TakeValueColor());

def  op2   = if isTime2 then open else op2[1];
plot open2 = if todayonly and GetDay() != GetLastDay() or GetDay() == GetLastDay() and sec2 < 0 then Double.NaN else op2;
open2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
AddVerticalLine(if todayonly and GetDay() != GetLastDay() then Double.NaN else isTime2, " ",  open2.TakeValueColor(), Curve.FIRM);
AddChartBubble(IsNaN(close[bm]) and !IsNaN(close[bm1]), open2[bm1], "830", open2.TakeValueColor(), no);
;
 
I think that should be fairly easy. I'm working on a Globex, Midnight and NY Open vertical plus the horizontals for the price at two defined times (midnight and 8:30 are the default). Just fixing a couple small things and will post later. Just FYI, this will only work on time-based charts.

2HRbRq7.png
Hows are your scripts coming along?
 
Modified with todayonly option and a bubblemover option
Nice script is there any way to delete the vertical lines and just keep the horizontal ones?

Oh sorry, I didn't post because I thought @SleepyZ 's response above was better than I already had. Is there anything in that script that isn't working for you?
Hi buddy is there any way to delete the vertical lines and only keep the horizontal ones?
 
Nice script is there any way to delete the vertical lines and just keep the horizontal ones?


Hi buddy is there any way to delete the vertical lines and only keep the horizontal ones?

This allows you to choose or not to display the verticallines.

Ruby:
#Midnight_Vertical_Open_830_Vertical_Open
input showverticls = no;
input todayonly    = no;
input openingTime1 = 0000;
input openingTime2 = 0830;
input bubblemover  = 3;
def bm  = bubblemover;
def bm1 = bm + 1;

def sec1 = SecondsFromTime(openingTime1);
def sec2 = SecondsFromTime(openingTime2);
def isTime1 = (sec1 >= 0 and sec1[1] < 0) or (sec1 < sec1[1] and sec1 >= 0);
def isTime2 = (sec2 >= 0 and sec2[1] < 0) or (sec2 < sec2[1] and sec2 >= 0);

def  op1   = if isTime1 then open else op1[1];
plot open1 = if todayonly and GetDay() != GetLastDay() then Double.NaN else op1;
open1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
AddVerticalLine(if !showverticls then double.nan else if todayonly and GetDay() != GetLastDay() - 1 then Double.NaN else isTime1, " ", open1.TakeValueColor(), Curve.FIRM);
AddChartBubble(IsNaN(close[bm]) and !IsNaN(close[bm1]), open1[bm1], "Midnight", open1.TakeValueColor());

def  op2   = if isTime2 then open else op2[1];
plot open2 = if todayonly and GetDay() != GetLastDay() or GetDay() == GetLastDay() and sec2 < 0 then Double.NaN else op2;
open2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
AddVerticalLine(if !showverticls then double.nan else if todayonly and GetDay() != GetLastDay() then Double.NaN else isTime2, " ",  open2.TakeValueColor(), Curve.FIRM);
AddChartBubble(IsNaN(close[bm]) and !IsNaN(close[bm1]), open2[bm1], "830", open2.TakeValueColor(), no);
 
Hey! I just came along this script and was wondering if there's any way to just have a 830 vertical line that can be customized?

Sure,

Screenshot-2022-12-01-103514.png
Ruby:
#830_Vertical_Open
input showverticls = yes;
input todayonly    = yes;
input openingTime2 = 0830;
input showbubble   = yes;
input bubblemover  = 3;
def bm  = bubblemover;
def bm1 = bm + 1;

def sec2 = SecondsFromTime(openingTime2);
def isTime2 = (sec2 >= 0 and sec2[1] < 0) or (sec2 < sec2[1] and sec2 >= 0);

def  op2   = if isTime2 then open else op2[1];
plot open2 = if todayonly and GetDay() != GetLastDay() or GetDay() == GetLastDay() and sec2 < 0 then Double.NaN else op2;
open2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
AddVerticalLine(if !showverticls then double.nan else if todayonly and GetDay() != GetLastDay() then Double.NaN else isTime2, " ",  open2.TakeValueColor(), Curve.FIRM);
AddChartBubble(showbubble and IsNaN(close[bm]) and !IsNaN(close[bm1]), open2[bm1], "830", open2.TakeValueColor(), no);
 
Is there a way to extend the lines past a single day? I tried looking in other scripts but can't quite figure out how to extend. And then if there's a way to add the date to the lines too that would be awesome.
 
Is there a way to extend the lines past a single day? I tried looking in other scripts but can't quite figure out how to extend. And then if there's a way to add the date to the lines too that would be awesome.

To extend the lines, each has to have a separate plot statement. To do that, this study uses the script function to create those plots.

The study has the last 5 plots. You can create more using the same logic in the study that created the 5 plots.

Screenshot-2023-02-16-151636.jpg
Code:
#830_Vertical_Open
script x {

    input lookback     = 0;
    input openingTime2 = 0830;

    def ymd      = GetYYYYMMDD();
    def candles  = !IsNaN(close);
    def capture  = candles and ymd != ymd[1];
    def dayCount = CompoundValue(1, if capture then dayCount[1] + 1 else dayCount[1], 0);
    def thisDay  = (HighestAll(dayCount) - dayCount) + 1;
    def sec2     = SecondsFromTime(openingTime2);
    def isTime2  = (sec2 >= 0 and sec2[1] < 0) or (sec2 < sec2[1] and sec2 >= 0);

    def  op2   = if IsNaN(close) then op2[1] else if thisDay == lookback and isTime2 then open else op2[1];
    plot open2 = if thisDay > lookback and isTime2 then Double.NaN else op2[1];
    def mon   = if thisDay == lookback then GetMonth() else mon[1];
    def day   = if thisDay == lookback then GetDayOfMonth(GetYYYYMMDD()) else day[1];
    plot m = mon;
    plot d = day;

}


input showverticals = yes;
input openingTime2  = 0830;
input showbubble    = yes;
input showlabel     = yes;


def sec2 = SecondsFromTime(openingTime2);
def isTime2 = (sec2 >= 0 and sec2[1] < 0) or (sec2 < sec2[1] and sec2 >= 0);

plot o1 = x(lookback = 1);
o1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
plot o2 = x(lookback = 2);
o2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
plot o3 = x(lookback = 3);
o3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
plot o4 = x(lookback = 4);
o4.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
plot o5 = x(lookback = 5);
o5.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

DefineGlobalColor("X", Color.CYAN);
o1.SetDefaultColor(GlobalColor("X"));
o2.SetDefaultColor(GlobalColor("X"));
o3.SetDefaultColor(GlobalColor("X"));
o4.SetDefaultColor(GlobalColor("X"));
o5.SetDefaultColor(GlobalColor("X"));

AddLabel(showlabel, "Open Time = " + openingTime2, Color.CYAN);

input bubblemover  = 3;
def bm  = bubblemover;
def bm1 = bm + 1;


AddVerticalLine(if !showverticals then Double.NaN else isTime2, AsPrice(GetYYYYMMDD()),  o1.TakeValueColor(), Curve.FIRM);

AddChartBubble(showbubble and IsNaN(close[bm]) and !IsNaN(close[bm1]), o1[bm1], +x(1).m + "/" + x(1).d, o1.TakeValueColor(), yes);
AddChartBubble(showbubble and IsNaN(close[bm]) and !IsNaN(close[bm1]), o2[bm1], +x(2).m + "/" + x(2).d, o2.TakeValueColor(), yes);
AddChartBubble(showbubble and IsNaN(close[bm]) and !IsNaN(close[bm1]), o3[bm1], +x(3).m + "/" + x(3).d, o3.TakeValueColor(), yes);
AddChartBubble(showbubble and IsNaN(close[bm]) and !IsNaN(close[bm1]), o4[bm1], +x(4).m + "/" + x(4).d, o4.TakeValueColor(), yes);
AddChartBubble(showbubble and IsNaN(close[bm]) and !IsNaN(close[bm1]), o5[bm1], +x(5).m + "/" + x(5).d, o4.TakeValueColor(), yes);
 
To extend the lines, each has to have a separate plot statement. To do that, this study uses the script function to create those plots.

The study has the last 5 plots. You can create more using the same logic in the study that created the 5 plots.

Any idea why mine will only show the last 4 plots? I'm plotting it on /ES. Copied the code from your post.

QZo1YEZ.png
 
Great indicator, instead of the open can it be made to plot the line at the close at first 930 bar, and can the line agg on the 15min agg and yet show on a 5 min agg. chart
 
Last edited:

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
289 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top