Highest of the Time Interval

mps

New member
VIP
Hi ThinsScript Gurus,
I am looking for a script with indicator which marks an arrow whenever current high breaks above the highest from the time interval selected. I am new in scripting so have limited ability to script.

If there is any such script existing , please point in that.

For Eg.
  • If time interval and Aggregation Period selected On Chart is "1 Day - 1 Min", I want an arrow on candle when current high of Candle breaks above the day's highest.
  • If time interval and Aggregation Period selected On Chart is "1 Year - Daily ", I want an arrow to show up whenever current high on daily chart exceeds the highest price in the whole year. So, for eg on daily chart , if in calendar year 2024 , highest price was $15 in February .. and now in August if it goes above $15 .. the arrow should be displayed.


I had this one script which shows for day's highest , but it does not work dynamically picking up time interval and aggregation period.


# Breakout Above Current Day's High Indicator

# Define the condition to identify the current day's high
def todayHigh = if GetDay() != GetDay()[1] then high else Max(high, todayHigh[1]);

# Condition for breaking above the current day's high
def breakout = high > todayHigh[1];

# Plot the Blue Arrow when the breakout condition is true
plot breakoutSignal = if breakout then high else Double.NaN;
breakoutSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
breakoutSignal.SetDefaultColor(Color.BLUE);
breakoutSignal.SetLineWeight(2);
 
Solution
Hi ThinsScript Gurus,
I am looking for a script with indicator which marks an arrow whenever current high breaks above the highest from the time interval selected. I am new in scripting so have limited ability to script.

If there is any such script existing , please point in that.

For Eg.
  • If time interval and Aggregation Period selected On Chart is "1 Day - 1 Min", I want an arrow on candle when current high of Candle breaks above the day's highest.
  • If time interval and Aggregation Period selected On Chart is "1 Year - Daily ", I want an arrow to show up whenever current high on daily chart exceeds the highest price in the whole year. So, for eg on daily chart , if in calendar year 2024 , highest price was $15 in...
Hi ThinsScript Gurus,
I am looking for a script with indicator which marks an arrow whenever current high breaks above the highest from the time interval selected. I am new in scripting so have limited ability to script.

If there is any such script existing , please point in that.

For Eg.
  • If time interval and Aggregation Period selected On Chart is "1 Day - 1 Min", I want an arrow on candle when current high of Candle breaks above the day's highest.
  • If time interval and Aggregation Period selected On Chart is "1 Year - Daily ", I want an arrow to show up whenever current high on daily chart exceeds the highest price in the whole year. So, for eg on daily chart , if in calendar year 2024 , highest price was $15 in February .. and now in August if it goes above $15 .. the arrow should be displayed.


I had this one script which shows for day's highest , but it does not work dynamically picking up time interval and aggregation period.


# Breakout Above Current Day's High Indicator

# Define the condition to identify the current day's high
def todayHigh = if GetDay() != GetDay()[1] then high else Max(high, todayHigh[1]);

# Condition for breaking above the current day's high
def breakout = high > todayHigh[1];

# Plot the Blue Arrow when the breakout condition is true
plot breakoutSignal = if breakout then high else Double.NaN;
breakoutSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
breakoutSignal.SetDefaultColor(Color.BLUE);
breakoutSignal.SetLineWeight(2);


this finds the highest high in 4 periods. day, week, month, year.
the chart time determines which period is used. 1min , 15min, hour, day.
an arrow is drawn when a new high happens.
can draw a line at the highest level.
if chart time is something else, then nothing is plotted.
day - minute
week - 15 min
month - hour
year - day


Code:
#high_new_in_period
#https://usethinkscript.com/threads/highest-of-the-time-interval.19453/
#Highest of the Time Interval

def na = double.nan;
def bn = barnumber();
def d = GetDay();
def w = getweek();
def m = getmonth();
def y = getyear();
def o = open;
def h = high;
def l = low;
def c = close;

def dhi = if bn == 1 or d != d[1] then h else max(h, dhi[1]);
def whi = if bn == 1 or w != w[1] then h else max(h, whi[1]);
def mhi = if bn == 1 or m != m[1] then h else max(h, mhi[1]);
def yhi = if bn == 1 or y != y[1] then h else max(h, yhi[1]);

def chartagg = getaggregationperiod();
def chartmin = chartagg/60000;
#addlabel(1, chartmin);


# day - minute
def newdayhi;
if chartmin == 1 then {
 newdayhi = (h > dhi[1]);
} else {
 newdayhi = 0;
}


# week - 15 min
def newweekhi;
if chartmin == 15 then {
 newweekhi = (h > whi[1]);
} else {
 newweekhi = 0;
}


# month - hour
def newmonthhi;
if chartmin == 60 then {
 newmonthhi = (h > mhi[1]);
} else {
 newmonthhi = 0;
}


# year - day
def newyearhi;
if chartmin == 1440 then {
 newyearhi = (h > dhi[1]);
} else {
 newyearhi = 0;
}


plot z1 = if newdayhi then l*0.9996 else na;
z1.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
z1.SetDefaultColor(Color.cyan);
z1.SetLineWeight(2);

plot z2 = if newweekhi then l*0.9996 else na;
z2.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
z2.SetDefaultColor(Color.cyan);
z2.SetLineWeight(2);

plot z3 = if newmonthhi then l*0.9996 else na;
z3.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
z3.SetDefaultColor(Color.cyan);
z3.SetLineWeight(2);

plot z4 = if newyearhi then l*0.9996 else na;
z4.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
z4.SetDefaultColor(Color.cyan);
z4.SetLineWeight(2);


input draw_hi_line = no;
plot l1 = if draw_hi_line and chartmin == 1 then dhi else na;
plot l2 = if draw_hi_line and chartmin == 15 then whi else na;
plot l3 = if draw_hi_line and chartmin == 60 then mhi else na;
plot l4 = if draw_hi_line and chartmin == 1440 then yhi else na;

input bubbles = no;
addchartbubble(bubbles and newdayhi, h, "new high of day", color.yellow, yes);
addchartbubble(bubbles and newweekhi, h, "new high of week", color.yellow, yes);
addchartbubble(bubbles and newmonthhi, h, "new high of month", color.yellow, yes);
addchartbubble(bubbles and newyearhi, h, "new high of year", color.yellow, yes);
#
 

Attachments

  • img1.JPG
    img1.JPG
    41.7 KB · Views: 56
Solution

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