Near or at High/Low of Day/Year question???

evanevans

Active member
I put the following code together. But I'm having problems getting it to work right. I'm putting it on a 1 minute chart. Is that the issue? How do you check for High of Year on a Minute chart? Any help?

(@Welkin my brother? :) )

Code:
# ChartAlert New High/Low of Year
# Evan Evans

input PCTnearHOY = 0.09;
input PCTnearLOY = 0.09;

def agg = AggregationPeriod.Day;

#def HOD = Highest(High(period = agg), 1);
def HOY = Highest(High(period = agg), 252);
#def LOD = Lowest(Low(period = agg), 1);
def LOY = Lowest(Low(period = agg), 252);

DefineGlobalColor("isHOY",Color.Green);
DefineGlobalColor("nearHOY",Color.Dark_Green);
DefineGlobalColor("nearLOY",Color.Dark_Red);
DefineGlobalColor("isLOY",Color.Red);
DefineGlobalColor("default",Color.Current);

AssignBackgroundColor(if Close >= HOY then GlobalColor("isHOY")
   else if Close >= (HOY*(1-PCTnearHOY)) then GlobalColor("nearHOY")
   else if Close <= LOY then GlobalColor("isLOY")
   else if Close <= (LOY*(1+PCTnearLOY)) then GlobalColor("nearLOY")
   else GlobalColor("default"));
 
Ok, looks like I got it all worked out. Here's the latest code:

Code:
# ChartAlert New High/Low of Year
# Evan Evans
# August 31, 2020

input PCTnearHOY = 0.09;
input PCTnearLOY = 0.09;

def agg = AggregationPeriod.Day;

def HOD = Highest(High(period = agg), 1);
def HOY = Highest(High(period = agg), 252);
def LOD = Lowest(Low(period = agg), 1);
def LOY = Lowest(Low(period = agg), 252);

DefineGlobalColor("isHOY",CreateColor(0,30,80));
DefineGlobalColor("nearHOY",CreateColor(0,60,50));
DefineGlobalColor("nearLOY",CreateColor(50,60,00));
DefineGlobalColor("isLOY",CreateColor(80,30,0));
DefineGlobalColor("default",Color.Current);

AssignBackgroundColor(if Close >= (HOY*(1-PCTnearHOY)) and Close<HOY and HOD<>HOY then GlobalColor("nearHOY")
   else if HOD==HOY then GlobalColor("isHOY")
   else if LOD==LOY then GlobalColor("isLOY")
   else if Close <= (LOY*(1+PCTnearLOY)) and Close>LOY and LOD<>LOY then GlobalColor("nearLOY")
   else GlobalColor("default"));
 

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

It appears to be correctly pulling the high and low values from the past 252 days on to the minute, however on the minute aggregation the values can be off from the daily if you show Extended Trading Hours, any highest highs or lowest lows made during ETH will be the values used. You cannot pull higher aggregation period data that is greater than 30 days (the max a 1min chart can be set to). So you could also use AggregationPeriod.MONTH with a Highest() length of 12, but AggregationPeriod.YEAR will not work.
 
It appears to be correctly pulling the high and low values from the past 252 days on to the minute, however on the minute aggregation the values can be off from the daily if you show Extended Trading Hours, any highest highs or lowest lows made during ETH will be the values used. You cannot pull higher aggregation period data that is greater than 30 days (the max a 1min chart can be set to). So you could also use AggregationPeriod.MONTH with a Highest() length of 12, but AggregationPeriod.YEAR will not work.
Thanks that's a great workaround. Many thanks. I did not get a chance to test your alternative sentiments today. I was busy buildling a 3 screen 70 position monitoring setup. Pretty much dialed in now, so I might load 'er up tomorrow and twiddle with it. Hope you're doing good.
 
Thanks that's a great workaround. Many thanks. I did not get a chance to test your alternative sentiments today. I was busy buildling a 3 screen 70 position monitoring setup. Pretty much dialed in now, so I might load 'er up tomorrow and twiddle with it. Hope you're doing good.
Doing fine, thanks for asking, and yea I haven't had much time to test it all either, mainly just put it together and threw it out into the wild Lol. will be messing around on globex with it tonight/through the rest of the week. You'll have to adjust some settings and tweak some things, as I just kind of used some random values that I thought would be appropriate but might not work in actual practice. some of the new sentiment stuff won't plot unless there is enough tick data, so if you see something not working try bumping up the tick aggregation a bit until it does.
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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