draw horizontal line for high and low values between the previous day close (4pm) and today open (9:30am) in TOS

Tupar999

New member
Hi,

i am looking for a TOS script that can draw the horizontal lines of the highest and lowest values for the time period between previous day close and today market open.

example: draw horizontal lines for the highest and lowest value, between sep 15, 2022 4pm and sep 16, 2022 9:30am assuming today is sep 16, 2022. (EST time)

Thanks for your help,
Tupar
 
Solution
You can limit how many plots to display @input show_plots_for_daysback . I have set it to 3 to give you the first 2 days you last indicated you wanted. Look at the explanation in the next paragraph for why you need a 3 for the 2 days.

The code uses a general snippet of code called thisday that I use that defines ranges with uniform numbers. Those numbers did not stay the same between chart timeframes. The range for your request spans 2 chart days and required some finesse to make it uniform days. It numbers them 1, 3, 5, 7, etc... Make sure your chart timeframe has a few extra days than the highest number of plots you want to display.

Screenshot-2022-10-12-103814.png
Ruby:
script onh {
input...

SleepyZ

Well-known member
VIP
Lifetime
You can limit how many plots to display @input show_plots_for_daysback . I have set it to 3 to give you the first 2 days you last indicated you wanted. Look at the explanation in the next paragraph for why you need a 3 for the 2 days.

The code uses a general snippet of code called thisday that I use that defines ranges with uniform numbers. Those numbers did not stay the same between chart timeframes. The range for your request spans 2 chart days and required some finesse to make it uniform days. It numbers them 1, 3, 5, 7, etc... Make sure your chart timeframe has a few extra days than the highest number of plots you want to display.

Screenshot-2022-10-12-103814.png
Ruby:
script onh {
input daysback = 1;
input openingTime = 1600;
input closingTime = 0930;

def sec1    = SecondsFromTime(openingTime);
def sec2    = SecondsFromTime(closingTime);
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 inRange = CompoundValue(1, if isTime1 then 1 else if isTime2 then 0 else inRange[1], 0);
def ymd      = inrange;
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) ;
#thisday.setpaintingStrategy(paintingStrategy.VALUES_BELOW);

def rhi        = if inRange and !inRange[1]
                 then high
                 else if inRange[1] and high > rhi[1]
                 then high else rhi[1];
def rHighBar   = if thisday == daysback and inRange and high == rhi then BarNumber() else Double.NaN;
def rHighest   = if BarNumber() == HighestAll(rHighBar)  then rhi else rHighest[1];

plot rangehigh = if (rHighest > 0) then rHighest else Double.NaN;
rangehigh.setpaintingStrategy(paintingStrategy.HORIZONTAL);
rangehigh.setlineWeight(2);

def rlow       = if inRange and !inRange[1]
                 then low
                 else if inRange[1] and low < rlow[1]
                 then low else rlow[1];
def rLowBar    = if thisday == daysback and inRange and low == rlow then BarNumber() else Double.NaN;
def rlowest    = if BarNumber() == HighestAll(rLowBar) then rlow else rlowest[1];

plot rangelow  = if (rlowest > 0) then rlowest else Double.NaN;
rangelow.setpaintingStrategy(paintingStrategy.HORIZONTAL);
rangelow.setlineWeight(2);
}

input show_plots_for_daysback = 3;
plot onh0 = if show_plots_for_daysback>=1 then onh(daysback = 1).rangehigh else double.nan;
plot onh1 = if show_plots_for_daysback>=3 then onh(daysback = 3).rangehigh else double.nan;
plot onh2 = if show_plots_for_daysback>=5 then onh(daysback = 5).rangehigh else double.nan;
plot onh3 = if show_plots_for_daysback>=7 then onh(daysback = 7).rangehigh else double.nan;

onh0.SetpaintingStrategy(paintingStrategy.DASHES);
onh1.SetpaintingStrategy(paintingStrategy.DASHES);
onh2.SetpaintingStrategy(paintingStrategy.DASHES);
onh3.SetpaintingStrategy(paintingStrategy.DASHES);

onh0.SetDefaultColor(Color.WHITE);
onh1.SetDefaultColor(Color.WHITE);
onh2.SetDefaultColor(Color.WHITE);
onh3.SetDefaultColor(Color.WHITE);

input lineweight = 4;
onh0.SetLineWeight(lineweight);
onh1.SetLineWeight(lineweight);
onh2.SetLineWeight(lineweight);
onh3.SetLineWeight(lineweight);

AddChartBubble(IsNaN(onh0[1]) and !IsNaN(onh0), onh0, onh0, CreateColor(204, 204, 255));
AddChartBubble(IsNaN(onh1[1]) and !IsNaN(onh1), onh1, onh1, CreateColor(204, 204, 255));
AddChartBubble(IsNaN(onh2[1]) and !IsNaN(onh2), onh2, onh2, CreateColor(204, 204, 255));
AddChartBubble(IsNaN(onh3[1]) and !IsNaN(onh3), onh3, onh3, CreateColor(204, 204, 255));

plot onl0 = if show_plots_for_daysback>=1 then onh(daysback = 1).rangelow else double.nan;
plot onl1 = if show_plots_for_daysback>=3 then onh(daysback = 3).rangelow else double.nan;
plot onl2 = if show_plots_for_daysback>=5 then onh(daysback = 5).rangelow else double.nan;
plot onl3 = if show_plots_for_daysback>=7 then onh(daysback = 7).rangelow else double.nan;

onl0.SetpaintingStrategy(paintingStrategy.DASHES);
onl1.SetpaintingStrategy(paintingStrategy.DASHES);
onl2.SetpaintingStrategy(paintingStrategy.DASHES);
onl3.SetpaintingStrategy(paintingStrategy.DASHES);

onl0.SetDefaultColor(Color.BLUE);
onl1.SetDefaultColor(Color.BLUE);
onl2.SetDefaultColor(Color.BLUE);
onl3.SetDefaultColor(Color.BLUE);

onl0.SetLineWeight(lineweight);
onl1.SetLineWeight(lineweight);
onl2.SetLineWeight(lineweight);
onl3.SetLineWeight(lineweight);

AddChartBubble(IsNaN(onl0[1]) and !IsNaN(onl0), onl0, onl0, Color.RED, no);
AddChartBubble(IsNaN(onl1[1]) and !IsNaN(onl1), onl1, onl1, Color.RED, no);
AddChartBubble(IsNaN(onl2[1]) and !IsNaN(onl2), onl2, onl2, Color.RED, no);
AddChartBubble(IsNaN(onl3[1]) and !IsNaN(onl3), onl3, onl3, Color.RED, no);
 
Last edited by a moderator:
Solution

Tupar999

New member
You can limit how many plots to display @input show_plots_for_daysback . I have set it to 3 to give you the first 2 days you last indicated you wanted. Look at the explanation in the next paragraph for why you need a 3 for the 2 days.

The code uses a general snippet of code called thisday that I use that defines ranges with uniform numbers. Those numbers did not stay the same between chart timeframes. The range for your request spans 2 chart days and required some finesse to make it uniform days. It numbers them 1, 3, 5, 7, etc... Make sure your chart timeframe has a few extra days than the highest number of plots you want to display.
Thanks, this is working good!
 
Last edited by a moderator:

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.
Top