Day Range calculation

wjones543

New member
VIP
I need help trying to create an indicator where: intraday after the open, a datapoint is plotted at the current 50% of the days range. As the day progresses, this 50% is updated based on the high and low of current day. It would be helpful to have an option where it will only be after the open or include premarket high and low into that range calculation.
 
Solution
I need help trying to create an indicator where: intraday after the open, a datapoint is plotted at the current 50% of the days range. As the day progresses, this 50% is updated based on the high and low of current day. It would be helpful to have an option where it will only be after the open or include premarket high and low into that range calculation.

plots 3 lines. high of day, low of day, mid line
can choose to include pre-market and post-market

Code:
#day_range_midline
#https://usethinkscript.com/threads/day-range-calculation.19678/
#Day Range calculation

def na = double.nan;
def bn = barnumber();
def big = 99999;
def d = getday();
def istoday = d == getlastday();

def prestart = 0400;
def start = 0930;
def end = 1600...
I need help trying to create an indicator where: intraday after the open, a datapoint is plotted at the current 50% of the days range. As the day progresses, this 50% is updated based on the high and low of current day. It would be helpful to have an option where it will only be after the open or include premarket high and low into that range calculation.

plots 3 lines. high of day, low of day, mid line
can choose to include pre-market and post-market

Code:
#day_range_midline
#https://usethinkscript.com/threads/day-range-calculation.19678/
#Day Range calculation

def na = double.nan;
def bn = barnumber();
def big = 99999;
def d = getday();
def istoday = d == getlastday();

def prestart = 0400;
def start = 0930;
def end = 1600;
def postend = 2000;
def pretime = if secondsfromTime(prestart) >= 0 and secondstillTime(start) > 0 then 1 else 0;
def daytime = if secondsfromTime(start) >= 0 and secondstillTime(end) > 0 then 1 else 0;
def posttime = if secondsfromTime(end) >= 0 and secondstillTime(postend) > 0 then 1 else 0;

input today_only = yes;
def today2 = if today_only then istoday else 1;

input include_pre_market_levels = no;
input include_post_market_levels = no;
#def x = if include_pre_market_levels then (pretime or daytime) else daytime;
def x = today2 and ((if include_pre_market_levels then pretime else 0) or 
 (if include_post_market_levels then posttime else 0) or
 daytime);

def hi = if bn == 1 then high
 else if d != d[1] then high
 else if x and !x[1] then high
 else if x then max(hi[1], high)
 else 0;

def lo = if bn == 1 then low
 else if d != d[1] then low
 else if x and !x[1] then low
 else if x then min(lo[1], low)
 else 0;

def mid = if x then (hi + lo)/2 else 0;

plot zhi = if hi > 0 then hi else na;
zhi.SetDefaultColor(Color.cyan);
#zhi.setlineweight(1);
zhi.hidebubble();

plot zlo = if lo < big and lo > 0 then lo else na;
zlo.SetDefaultColor(Color.cyan);
#zlo.setlineweight(1);
zlo.hidebubble();

plot zmid = if mid > 0 then mid else na;
zmid.SetDefaultColor(Color.yellow);
zmid.setlineweight(2);
zmid.hidebubble();

plot zd = if 0 and daytime then high*1.01 else double.nan;
zd.SetPaintingStrategy(PaintingStrategy.POINTS);
zd.SetDefaultColor(Color.white);
# x.setlineweight(1);
# x.hidebubble();
#
 

Attachments

  • img1.JPG
    img1.JPG
    42.6 KB · Views: 189
Solution
plots 3 lines. high of day, low of day, mid line
can choose to include pre-market and post-market

Code:
#day_range_midline
#https://usethinkscript.com/threads/day-range-calculation.19678/
#Day Range calculation

def na = double.nan;
def bn = barnumber();
def big = 99999;
def d = getday();
def istoday = d == getlastday();

def prestart = 0400;
def start = 0930;
def end = 1600;
def postend = 2000;
def pretime = if secondsfromTime(prestart) >= 0 and secondstillTime(start) > 0 then 1 else 0;
def daytime = if secondsfromTime(start) >= 0 and secondstillTime(end) > 0 then 1 else 0;
def posttime = if secondsfromTime(end) >= 0 and secondstillTime(postend) > 0 then 1 else 0;

input today_only = yes;
def today2 = if today_only then istoday else 1;

input include_pre_market_levels = no;
input include_post_market_levels = no;
#def x = if include_pre_market_levels then (pretime or daytime) else daytime;
def x = today2 and ((if include_pre_market_levels then pretime else 0) or
 (if include_post_market_levels then posttime else 0) or
 daytime);

def hi = if bn == 1 then high
 else if d != d[1] then high
 else if x and !x[1] then high
 else if x then max(hi[1], high)
 else 0;

def lo = if bn == 1 then low
 else if d != d[1] then low
 else if x and !x[1] then low
 else if x then min(lo[1], low)
 else 0;

def mid = if x then (hi + lo)/2 else 0;

plot zhi = if hi > 0 then hi else na;
zhi.SetDefaultColor(Color.cyan);
#zhi.setlineweight(1);
zhi.hidebubble();

plot zlo = if lo < big and lo > 0 then lo else na;
zlo.SetDefaultColor(Color.cyan);
#zlo.setlineweight(1);
zlo.hidebubble();

plot zmid = if mid > 0 then mid else na;
zmid.SetDefaultColor(Color.yellow);
zmid.setlineweight(2);
zmid.hidebubble();

plot zd = if 0 and daytime then high*1.01 else double.nan;
zd.SetPaintingStrategy(PaintingStrategy.POINTS);
zd.SetDefaultColor(Color.white);
# x.setlineweight(1);
# x.hidebubble();
#
This code works good to find today's range (high, low and mid). But i need to find the average of 3days or 5days for the same. Can someone help pls.
 

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

Thread starter Similar threads Forum Replies Date
Type636 Scan for price range/duration? Questions 1
T Narrow Range Scanner Questions 1
D Wick Range Questions 2
J Candle Range Breakout Questions 4
J FVG Within Fib Range Questions 5

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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