Plot Daily High Low & 200ma / 20ma

pensrule67

New member
I have a tos script I'm trying to write but failing misserably.
I would like a script that:

1. plots the low and high of the day as a 3 weight line (yellow?) that extends into current trading day for the time period of 1515-1600 from the previous days trading session

2. and also include the 20 and 200 SMA.

3. Of the four items(20, 200 high, low) Which ever one of these is the highest and the lowest at 1600, it would create a box where they intersect at close and create a shaded cloud that extends into current day trading session.

Any help is much appreciated.
This is for a new trading strategy I want to try out. I also have some other variables i will mention.
 
Last edited by a moderator:
Thanks BenTen. It is a very basic starting point as was looking for previous trading session for the high and lows at a certain time (last 45 minutes of the session. There is additional variables mentioned above.
 
Your original post said, "plots the low and high of the day."

Now you say "previous trading session for the high and lows."

In that case, use the DailyHighLow indicator in TOS. It will plot the previous day's high and low on your chart.
 
I have a tos script I'm trying to write but failing misserably.
I would like a script that:

1. plots the low and high of the day as a 3 weight line (yellow?) that extends into current trading day for the time period of 1515-1600 from the previous days trading session

2. and also include the 20 and 200 SMA.

3. Of the four items(20, 200 high, low) Which ever one of these is the highest and the lowest at 1600, it would create a box where they intersect at close and create a shaded cloud that extends into current day trading session.

Any help is much appreciated.
This is for a new trading strategy I want to try out. I also have some other variables i will mention.


your description is a little confusing.

do you want , to find the high and low,
from a period of 15:15-16:00,
from the previous days trading session,
and draw those levels on next day?

this sounds like an ORB study, but shifted to the end of the day...

i didn't know how the averages were supposed to fit into this, so i left them out.

this will find the high and low of a time period (15:15 to 16:00).
then draw those lines on the next day.


Code:
#prev_day_levels_200_20_

#https://usethinkscript.com/threads/plot-daily-high-low-200ma-20ma.15362/
#Plot Daily High Low & 200ma / 20ma

def na = double.nan;
def bn = barnumber();

def big = 99999;

# open/close times  (EST)
#input start = 0930;
input start = 1515;
input end = 1600;
#def before = if secondstillTime(start) > 0 then 1 else 0;
#def after = if secondsfromTime(end) > 0 then 1 else 0;
def period_start = if secondstillTime(start) == 0 then 1 else 0;
def period = if secondsfromTime(start) >= 0 and secondstillTime(end) > 0 then 1 else 0;

def phi = if bn == 1 then 0
 else if period_start then high
 else if period then max(phi[1], high)
 else phi[1];

def plo = if bn == 1 then big
 else if period_start then low
 else if period then min(plo[1], low)
 else plo[1];


def phi2 = if period[1] and !period then phi
 else phi2[1];

def plo2 = if period[1] and !period then plo
 else plo2[1];


plot zhi = if bn == 1 then na
 else if phi2 == 0 then na
# else if phi[1] != 0 and period then phi[1]
 else phi2;

plot zlo = if bn == 1 then na
 else if plo2 == big then na
# else if plo[1] != big and period then plo[1]
 else plo2;

zhi.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zlo.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
#

THYEFls.jpg
 
Thanks Guys, I will give this a shot. @BigTen, I did mention the time frame in the original post but all is ok. Thanks guys for the help.

I was going to plot the 20 and 200 sma also in this code to mark points of intersection of the 20, 200 high and low of the day right at close of previous session. I would then want to pick the highest and lowest of these points and draw a box essentially and shade the box across the Current days trading session.
 
Thanks Guys, I will give this a shot. @BigTen, I did mention the time frame in the original post but all is ok. Thanks guys for the help.

I was going to plot the 20 and 200 sma also in this code to mark points of intersection of the 20, 200 high and low of the day right at close of previous session. I would then want to pick the highest and lowest of these points and draw a box essentially and shade the box across the Current days trading session.

this is a post to help you (and others) describe a request,
i'm not nitpicking , i am trying to help you to learn to better describe a question.
often people get an idea in their head, and have trouble communicating it to others.

you are leaving out punctuation, and describing conflicting actions , that make it hard to understand.
take a look at the beginning of my post5. i listed several, short, specific conditions, that make it clear what is to happen.

-----------------------
in post 1, #1
1. plots the low and high of the day as a 3 weight line (yellow?) that extends into current trading day for the time period of 1515-1600 from the previous days trading session

plot high and low of day.
for the time period of 1515-1600
...so which is it? all day or just during a specific time period?


post1 - #3 is similarly confusing,
3. Of the four items(20, 200 high, low) Which ever one of these is the highest and the lowest at 1600, it would create a box where they intersect at close and create a shaded cloud that extends into current day trading session.

the highest and the lowest at 1600
where they intersect at close
?? what does intersect mean ? what intersections? which action do you want to look for, highest and lowest , or intersections? at close.. of each bar? close of the day?


then is post6, you repeated your previous words, which are still confusing, so it doesn't help.
i'm sure it makes sense to you. i'm just letting you know, your words don't make sense to me.
 
this is a post to help you (and others) describe a request,
i'm not nitpicking , i am trying to help you to learn to better describe a question.
often people get an idea in their head, and have trouble communicating it to others.

you are leaving out punctuation, and describing conflicting actions , that make it hard to understand.
take a look at the beginning of my post5. i listed several, short, specific conditions, that make it clear what is to happen.

-----------------------
in post 1, #1
1. plots the low and high of the day as a 3 weight line (yellow?) that extends into current trading day for the time period of 1515-1600 from the previous days trading session

plot high and low of day.
for the time period of 1515-1600
...so which is it? all day or just during a specific time period?


post1 - #3 is similarly confusing,
3. Of the four items(20, 200 high, low) Which ever one of these is the highest and the lowest at 1600, it would create a box where they intersect at close and create a shaded cloud that extends into current day trading session.

the highest and the lowest at 1600
where they intersect at close
?? what does intersect mean ? what intersections? which action do you want to look for, highest and lowest , or intersections? at close.. of each bar? close of the day?


then is post6, you repeated your previous words, which are still confusing, so it doesn't help.
i'm sure it makes sense to you. i'm just letting you know, your words don't make sense to me


Thanks for the input. Sorry it seems confusing. I will try to draw something up to better describe what I'm looking for.
 
Last edited by a moderator:
Thanks for the input. Sorry it seems confusing. I will try to draw something up to better describe what I'm looking for.
I just tried out your Code and works great! Is it possible to show only one days previous session (If not, no biggie) For example, todays close on AAPL 05/03/2023, shows the exact thing I was looking for (the high/low between 15:15 and 16:00, PERFECTLY! extended into tommorrows chart) This is exactly what I needed!
It also seems to show the closing info for the previous closes session of 5/2/2023-This is what I am wondering if is possible to not have shown (Again not a biggie if not).

I'll work on the drawing of the other portion I was trying to describe in earlier posts. So far so good! Thanks again for the effort!
 
I was looking for the previous day and liked the code @halcyonguy put up. But only wanted the day previous to the current one. I also use it for futures - 24/5 so if I use a stock it grabs the overnight session and I was only wanting the RTH / Cash Session as I find those levels to be more relevant to use, like for TPO etc. I have a separate script for the Overnight session as I find those useful as well
 
I was looking at this code from what you sent @BenTen on the DailyHighLow but with the manual time entries I don't think this will work

Code:
input aggregationPeriod = AggregationPeriod.DAY;
input length = 1;
input displace = -1;
input showOnlyLastPeriod = yes;
if showOnlyLastPeriod and !IsNaN(close(period = aggregationPeriod)[-1]) {
    XxXxX = Double.NaN;
    XxXxX = Double.NaN;
} else {
    XxXxX = Highest(high(period = aggregationPeriod)[-displace], length);
    XxXxX = Lowest(low(period = aggregationPeriod)[-displace], length);
}
 
This program displays everyday, please help me to adjust it to display only today. Thank you


#prev_day_levels_200_20_

#https://usethinkscript.com/threads/plot-daily-high-low-200ma-20ma.15362/
#Plot Daily High Low & 200ma / 20ma

def na = double.nan;
def bn = barnumber();

def big = 99999;

# open/close times (EST)
#input start = 0930;
input start = 1515;
input end = 1600;
#def before = if secondstillTime(start) > 0 then 1 else 0;
#def after = if secondsfromTime(end) > 0 then 1 else 0;
def period_start = if secondstillTime(start) == 0 then 1 else 0;
def period = if secondsfromTime(start) >= 0 and secondstillTime(end) > 0 then 1 else 0;

def phi = if bn == 1 then 0
else if period_start then high
else if period then max(phi[1], high)
else phi[1];

def plo = if bn == 1 then big
else if period_start then low
else if period then min(plo[1], low)
else plo[1];


def phi2 = if period[1] and !period then phi
else phi2[1];

def plo2 = if period[1] and !period then plo
else plo2[1];


plot zhi = if bn == 1 then na
else if phi2 == 0 then na
# else if phi[1] != 0 and period then phi[1]
else phi2;

plot zlo = if bn == 1 then na
else if plo2 == big then na
# else if plo[1] != big and period then plo[1]
else plo2;

zhi.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zlo.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
#
 
This program displays everyday, please help me to adjust it to display only today. Thank you


#prev_day_levels_200_20_

#https://usethinkscript.com/threads/plot-daily-high-low-200ma-20ma.15362/
#Plot Daily High Low & 200ma / 20ma

def na = double.nan;
def bn = barnumber();

def big = 99999;

# open/close times (EST)
#input start = 0930;
input start = 1515;
input end = 1600;
#def before = if secondstillTime(start) > 0 then 1 else 0;
#def after = if secondsfromTime(end) > 0 then 1 else 0;
def period_start = if secondstillTime(start) == 0 then 1 else 0;
def period = if secondsfromTime(start) >= 0 and secondstillTime(end) > 0 then 1 else 0;

def phi = if bn == 1 then 0
else if period_start then high
else if period then max(phi[1], high)
else phi[1];

def plo = if bn == 1 then big
else if period_start then low
else if period then min(plo[1], low)
else plo[1];


def phi2 = if period[1] and !period then phi
else phi2[1];

def plo2 = if period[1] and !period then plo
else plo2[1];


plot zhi = if bn == 1 then na
else if phi2 == 0 then na
# else if phi[1] != 0 and period then phi[1]
else phi2;

plot zlo = if bn == 1 then na
else if plo2 == big then na
# else if plo[1] != big and period then plo[1]
else plo2;

zhi.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zlo.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
#

Select input showtodayonly = yes.

At the plots, it is used to indicate if any day, getday(), is not equal to the last day, getlastday(), on the chart, then do not display the prior day's, double.nan, plots

It is one of the most asked requests and there are many examples in the search to use.

Screenshot 2024-04-08 080304.png
Code:
#prev_day_levels_200_20_

#https://usethinkscript.com/threads/plot-daily-high-low-200ma-20ma.15362/
#Plot Daily High Low & 200ma / 20ma

input showtodayonly = yes;
def na = Double.NaN;
def bn = BarNumber();

def big = 99999;

# open/close times (EST)
#input start = 0930;
input start = 1515;
input end = 1600;
#def before = if secondstillTime(start) > 0 then 1 else 0;
#def after = if secondsfromTime(end) > 0 then 1 else 0;
def period_start = if SecondsTillTime(start) == 0 then 1 else 0;
def period = if SecondsFromTime(start) >= 0 and SecondsTillTime(end) > 0 then 1 else 0;

def phi = if bn == 1 then 0
else if period_start then high
else if period then Max(phi[1], high)
else phi[1];

def plo = if bn == 1 then big
else if period_start then low
else if period then Min(plo[1], low)
else plo[1];


def phi2 = if period[1] and !period then phi
else phi2[1];

def plo2 = if period[1] and !period then plo
else plo2[1];


plot zhi = if showtodayonly and GetDay() != GetLastDay()
then Double.NaN
else if bn == 1 then na
else if phi2 == 0 then na
# else if phi[1] != 0 and period then phi[1]
else phi2;

plot zlo = if showtodayonly and GetDay() != GetLastDay()
then Double.NaN
else if bn == 1 then na
else if plo2 == big then na
# else if plo[1] != big and period then plo[1]
else plo2;

zhi.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zlo.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

#
 
somehow it displays the day BEFORE previous day low on my chart. Please help to adjust of day. I want to display only last 45 mins of trading hour high & low. THANKS
 
Is someone can help me to fix the LOW side? I don't know what reason, It displays inaccurate and low from another day (High side is ok). I want it display HL from time 1515 to 1600.
Thanks for your help


#prev_day_levels_200_20_

#https://usethinkscript.com/threads/plot-daily-high-low-200ma-20ma.15362/
#Plot Daily High Low & 200ma / 20ma

input showtodayonly = yes;
def na = Double.NaN;
def bn = BarNumber();

def big = 99999;

# open/close times (EST)
#input start = 0930;
input start = 1515;
input end = 1600;
#def before = if secondstillTime(start) > 0 then 1 else 0;
#def after = if secondsfromTime(end) > 0 then 1 else 0;
def period_start = if SecondsTillTime(start) == 0 then 1 else 0;
def period = if SecondsFromTime(start) >= 0 and SecondsTillTime(end) > 0 then 1 else 0;

def phi = if bn == 1 then 0
else if period_start then high
else if period then Max(phi[1], high)
else phi[1];

def plo = if bn == 1 then big
else if period_start then low
else if period then Min(plo[1], low)
else plo[1];


def phi2 = if period[1] and !period then phi
else phi2[1];

def plo2 = if period[1] and !period then plo
else plo2[1];


plot zhi = if showtodayonly and GetDay() != GetLastDay()
then Double.NaN
else if bn == 1 then na
else if phi2 == 0 then na
# else if phi[1] != 0 and period then phi[1]
else phi2;

plot zlo = if showtodayonly and GetDay() != GetLastDay()
then Double.NaN
else if bn == 1 then na
else if plo2 == big then na
# else if plo[1] != big and period then plo[1]
else plo2;

zhi.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zlo.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

#
 
I have this program similar like above, I try to eliminate display everyday in many feature but it isn't working. I know you have strong handful can able to knock it down . Please help me to adjust display only today. THank you

input aggperiod = AggregationPeriod.HOUR;
input ORopentime = 1515;
input ORendtime = 1600;
input ORextendtime = 2000;
input showtodayonly = yes;

def na = Double.NaN;

#Find range of bars during aggperiod; Current day's OR excluded
def ORActive = if showtodayonly and GetDay() != GetlastDay() and
SecondsFromTime(ORopentime) >= 0 and SecondsFromTime(ORendtime) < 0
then 1 else 0;
#Extended bars plot from ORActive Aggperiod that are stopped at ORendtime
def ORExtend = if GetDay() != GetlastDay() and
SecondsFromTime(ORopentime) >= 0 and SecondsFromTime(ORExtendtime) <= 0
then 1 else 0;

#ORActive plots are Extended
def high1 = if ORActive then high(period = aggperiod) else high1[1];
def low1 = if ORActive then low(period = aggperiod) else low1[1];
def close1 = if ORActive then close(period = aggperiod) else close1[1];

#Extended ORActive plots are stopped at ORExtend time
def high1ext = if ORExtend then high1 else na;
def low1ext = if ORExtend then low1 else na;
def close1ext = if ORExtend then close1 else na;

plot high1_2000 = high1;
high1_2000.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
plot close1_2000 = close1ext;
close1_2000.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
plot low1_2000 = low1;
low1_2000.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
 
Is someone can help me to fix the LOW side? I don't know what reason, It displays inaccurate and low from another day (High side is ok). I want it display HL from time 1515 to 1600.
Thanks for your help


#prev_day_levels_200_20_

#https://usethinkscript.com/threads/plot-daily-high-low-200ma-20ma.15362/
#Plot Daily High Low & 200ma / 20ma

input showtodayonly = yes;
def na = Double.NaN;
def bn = BarNumber();

def big = 99999;

# open/close times (EST)
#input start = 0930;
input start = 1515;
input end = 1600;
#def before = if secondstillTime(start) > 0 then 1 else 0;
#def after = if secondsfromTime(end) > 0 then 1 else 0;
def period_start = if SecondsTillTime(start) == 0 then 1 else 0;
def period = if SecondsFromTime(start) >= 0 and SecondsTillTime(end) > 0 then 1 else 0;

def phi = if bn == 1 then 0
else if period_start then high
else if period then Max(phi[1], high)
else phi[1];

def plo = if bn == 1 then big
else if period_start then low
else if period then Min(plo[1], low)
else plo[1];


def phi2 = if period[1] and !period then phi
else phi2[1];

def plo2 = if period[1] and !period then plo
else plo2[1];


plot zhi = if showtodayonly and GetDay() != GetLastDay()
then Double.NaN
else if bn == 1 then na
else if phi2 == 0 then na
# else if phi[1] != 0 and period then phi[1]
else phi2;

plot zlo = if showtodayonly and GetDay() != GetLastDay()
then Double.NaN
else if bn == 1 then na
else if plo2 == big then na
# else if plo[1] != big and period then plo[1]
else plo2;

zhi.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zlo.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

#

this worked when i made it.
what did you change?
why didn't you post this question on the original thread, instead of making a new post?
 
Last edited by a moderator:

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
345 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