high low range within specified time

MLlalala

Member
I am trying to define the high low range within a specified time each day from 9:30 to 12:00, i know i should use highest and lowest function, but i am struggling how to define this within a certain time period. after defining the range, i may want to add a label reminding me the current range

Much appreciated if anyone can help!
 
Solution
I am trying to define the high low range within a specified time each day from 9:30 to 12:00, i know i should use highest and lowest function, but i am struggling how to define this within a certain time period. after defining the range, i may want to add a label reminding me the current range

Much appreciated if anyone can help!

Try this

Ruby:
def range  = SecondsFromTime(0930) >= 0 and SecondsTillTime(1200) >= 0;
def hrange = if range[1] == 0 and range
             then high
             else if range
             then Max(high, hrange[1])
             else hrange[1];
def lrange = if range[1] == 0 and range
             then low 
             else if range
             then Min(low, lrange[1])
             else lrange[1]...
I am trying to define the high low range within a specified time each day from 9:30 to 12:00, i know i should use highest and lowest function, but i am struggling how to define this within a certain time period. after defining the range, i may want to add a label reminding me the current range

Much appreciated if anyone can help!

Try this

Ruby:
def range  = SecondsFromTime(0930) >= 0 and SecondsTillTime(1200) >= 0;
def hrange = if range[1] == 0 and range
             then high
             else if range
             then Max(high, hrange[1])
             else hrange[1];
def lrange = if range[1] == 0 and range
             then low 
             else if range
             then Min(low, lrange[1])
             else lrange[1];
input showlabel = yes;
AddLabel(showlabel, "930-1200 H:" + hrange + " L: " + lrange, Color.YELLOW);
input showplot = yes;
plot xhrange = if !showplot  then Double.NaN else hrange;
plot lhrange = if !showplot  then Double.NaN else lrange;
 
Solution
@SleepyZ Been looking for something like this, is there a way to plot another line at the close of the body at the start of the range and plot a line at the close of the body at the end of the range? This would be my support and resistance within the selected range of the timeframe. I draw them myself but time is everything :) So basically I use this from 930-1030 and i would like to see a line plotted at the close of the candle body at the low and high, just a add on to help with entries and exits, support and resistance, break of structure etc;) Thanks in advance
 
@SleepyZ Been looking for something like this, is there a way to plot another line at the close of the body at the start of the range and plot a line at the close of the body at the end of the range? This would be my support and resistance within the selected range of the timeframe. I draw them myself but time is everything :) So basically I use this from 930-1030 and i would like to see a line plotted at the close of the candle body at the low and high, just a add on to help with entries and exits, support and resistance, break of structure etc;) Thanks in advance

Sure

Screenshot-2022-11-30-091929.png

Ruby:
input begin = 0930;
input end   = 1030;
def range  = SecondsFromTime(begin) >= 0 and SecondsTillTime(end) >= 0;
def hrange = if range[1] == 0 and range
             then high
             else if range
             then Max(high, hrange[1])
             else hrange[1];
def lrange = if range[1] == 0 and range
             then low
             else if range
             then Min(low, lrange[1])
             else lrange[1];
def cstart = if range[1] == 0 and range
             then close
             else cstart[1];
def cend   = if range[-1] == 0 and range
             then close
             else cend[1];

input showlabel = yes;
AddLabel(showlabel, begin + "-" + asprice(end) + " H:" + asdollars(hrange) + " L: " + asdollars(lrange) + " CS: " + asdollars(cstart) + " CE: " + asdollars(cend), Color.YELLOW);

input showplot = yes;
plot xhrange = if !showplot then Double.NaN else hrange;
plot xlrange = if !showplot then Double.NaN else lrange;
plot xcstart = if !showplot then Double.NaN else cstart;
plot xcend   = if !showplot then Double.NaN else cend;

xhrange.SetPaintingStrategy(PaintingStrategy.DASHES);
xlrange.SetPaintingStrategy(PaintingStrategy.DASHES);
xcstart.SetPaintingStrategy(PaintingStrategy.DASHES);
xcend.SetPaintingStrategy(PaintingStrategy.DASHES);

input showbubbles = yes;
input bubblemover = 3;
def b = bubblemover;
def b1 = b + 1;

AddChartBubble(showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]), xhrange[b], "H", xhrange.TakeValueColor());
AddChartBubble(showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]), xlrange[b], "L", xlrange.TakeValueColor());
AddChartBubble(showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]), xcstart[b], "CS", xcstart.TakeValueColor());
AddChartBubble(showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]), xcend[b], "CE", xcend.TakeValueColor());

;
 
@SleepyZ Happy New Year,
I would like to find the range from the opening price at 930 to closing price 1030am on 5mins timeframe, how to modify the code?

Thanks

Easier to create a new code than to modify the above.
Option for a Label and/or Bubble display

Edit: code limited to last day and display only after end time
Screenshot-2023-01-01-092358.png

Ruby:
input start   = 0930;
input end     = 1030;
input labels  = yes;
input bubbles = yes;

def startopen = if getday() == getlastday() and
                   SecondsFromTime(start) == 0
                then open  else startopen[1];
def endclose  = if getday() == getlastday() and
                   secondsfromTime(start) >=0 and 
                   SecondsFromTime(end) == 0 
                then close else endclose[1];

AddLabel(labels and secondsfromtime(end) >= 0,
"Range (" + AsPrice(start) + " - " + AsPrice(end) + ") | " +
AsDollars(startopen) + " : " + AsDollars(endclose) +
" = " +
AsDollars(AbsValue(startopen - endclose)) + "   ",
Color.YELLOW);

AddChartBubble(bubbles and getday() == getlastday() and SecondsFromTime(end) == 0,
if high[-1] > high then low else high,
"R\n" +
AsPrice(start) + "\n" + AsPrice(end) + "\n" +
AsDollars(AbsValue(startopen - endclose)),
Color.YELLOW,
if high[-1] > high then no else yes);
 
Last edited:
Hi SleepyZ, Happy new year!
instead of end of 10:30, how could you make it till present (Last price)? i.e range from open till last price.

This might help

Screenshot-2023-01-01-144518.png
Ruby:
input start   = 0930;
input labels  = yes;
input bubbles = yes;

def startopen = if getday() == getlastday() and
                   SecondsFromTime(start) == 0
                then open  else startopen[1];
def endclose  = if getday() == getlastday() and
                   secondsfromTime(0930) >= 0 and
                   isnan(close[-1])
                then close else endclose[1];

AddLabel(labels and secondsFromTime(start) >= 0,
"Range (" + AsPrice(start) + " - Last " + ") | " +
AsDollars(startopen) + " : " + AsDollars(endclose) +
" = " +
AsDollars(AbsValue(startopen - endclose)) + "   ",
Color.YELLOW);

AddChartBubble(bubbles and getday() == getlastday() and secondsfromTime(start) >= 0 and isnan(close[-1]),
high,
"R\n" +
AsPrice(start) + "\nLast" + "\n" +
AsDollars(AbsValue(startopen - endclose)),
Color.YELLOW);
 

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
341 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