Highest High between 2 dates?

greco26

Active member
I am trying to create dynamic variable that will give me the highest(high) between 2 dates on the daily chart. Is this possible? For example:
def BeginDate = 20220615;
def EndDate = 20220715;

def HighofPeriod = highest(high,BeginDate,EndDate); I know this syntax isn't correct so that's what I need help with. Thanks!!
 
Solution
I am trying to create dynamic variable that will give me the highest(high) between 2 dates on the daily chart. Is this possible? For example:
def BeginDate = 20220615;
def EndDate = 20220715;

def HighofPeriod = highest(high,BeginDate,EndDate); I know this syntax isn't correct so that's what I need help with. Thanks!!

you didn't say what you want to see.
this will draw a horizontal line , at the highest, during the date period.
shows a label with the high price.

Code:
def na = double.nan;
def bn = barnumber();
def BeginDate = 20220615;
def EndDate = 20220715;

def isperiod = if DaysFromDate(BeginDate) >= 0 and
DaysTillDate(EndDate) >= 0 then 1 else 0;

def hi = if bn == 0 or !isperiod then na
else if isperiod and high >...
I am trying to create dynamic variable that will give me the highest(high) between 2 dates on the daily chart. Is this possible? For example:
def BeginDate = 20220615;
def EndDate = 20220715;

def HighofPeriod = highest(high,BeginDate,EndDate); I know this syntax isn't correct so that's what I need help with. Thanks!!

you didn't say what you want to see.
this will draw a horizontal line , at the highest, during the date period.
shows a label with the high price.

Code:
def na = double.nan;
def bn = barnumber();
def BeginDate = 20220615;
def EndDate = 20220715;

def isperiod = if DaysFromDate(BeginDate) >= 0 and
DaysTillDate(EndDate) >= 0 then 1 else 0;

def hi = if bn == 0 or !isperiod then na
else if isperiod and high > hi[1] then high else hi[1];

def hihi = highestall(hi);
plot z = if isperiod then hihi else na;

addlabel(1, "highest price in date range " + hihi, color.yellow);
addlabel(1, BeginDate + " to " + endDate, color.yellow);
#

https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Date---Time/GetYYYYMMDD


https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Date---Time/DaysFromDate
input BeginDate = 20090101;
plot Price = if DaysFromDate(BeginDate) >= 0 and DaysFromDate(BeginDate) <= 50 then close else double.NaN;

https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Date---Time/DaysTillDate
 
Solution
Thanks @halcyonguy. Looks like the def hi variable is coming back as N/A though. I'm playing with the code to see if I can figure it out but let me know if you spot anything. Thanks!!

Code:
def na = double.nan;
def bn = barnumber();
def BeginDate = 20220615;
def EndDate = 20220715;

def isperiod = if DaysFromDate(BeginDate) >= 0 and
DaysTillDate(EndDate) >= 0 then 1 else 0;

def hi = if bn == 0 or !isperiod then na
else if isperiod and high > hi[1] then high else hi[1];

def hihi = highestall(hi);
plot z = if isperiod then hihi else na;

addlabel(1, "highest price in date range " + hihi, color.yellow);
addlabel(1, BeginDate + " to " + endDate, color.yellow);
#

addchartbubble(1,low,isperiod,color.white,no);
addchartbubble(1,low,hi,color.yellow,no);
 
Thanks @halcyonguy. Looks like the def hi variable is coming back as N/A though. I'm playing with the code to see if I can figure it out but let me know if you spot anything. Thanks!!

Code:
def na = double.nan;
def bn = barnumber();
def BeginDate = 20220615;
def EndDate = 20220715;

def isperiod = if DaysFromDate(BeginDate) >= 0 and
DaysTillDate(EndDate) >= 0 then 1 else 0;

def hi = if bn == 0 or !isperiod then na
else if isperiod and high > hi[1] then high else hi[1];

def hihi = highestall(hi);
plot z = if isperiod then hihi else na;

addlabel(1, "highest price in date range " + hihi, color.yellow);
addlabel(1, BeginDate + " to " + endDate, color.yellow);
#

addchartbubble(1,low,isperiod,color.white,no);
addchartbubble(1,low,hi,color.yellow,no);

Try replacing def hi with

Code:
def hi = if bn == 0 or !isperiod then 0
else if isperiod and high > hi[1] then high else hi[1];
 
@SleepyZ, I tried that but it didn't seem to work either however the below did work.
Code:
def hi = if isperiod and high > hi[1] then high else hi[1];

Follow up question for you guys. I'm trying to dynamically update the BeginDate and EndDate but TOS doest seem to like my code. BeginDate and EndDate shows up properly in the labels but the isperiod is coming back as 0. Any thoughts on this?

Code:
def month = Getmonth();
def BeginDate = if
month == 1 then 20211201 else if
month == 2 then 20220101 else if
month == 3 then 20220201 else if
month == 4 then 20220301 else if
month == 5 then 20220401 else if
month == 6 then 20220501 else if
month == 7 then 20220601 else if
month == 8 then 20220701 else if
month == 9 then 20220801 else if
month == 10 then 20220901 else if
month == 11 then 20221001 else
20221101 ;

def EndDate = if
month == 1 then 20211231 else if
month == 2 then 20220131 else if
month == 3 then 20220228 else if
month == 4 then 20220331 else if
month == 5 then 20220430 else if
month == 6 then 20220531 else if
month == 7 then 20220630 else if
month == 8 then 20220731 else if
month == 9 then 20220831 else if
month == 10 then 20220930 else if
month == 11 then 20221031 else
20221130 ;


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

def isperiod = if DaysFromDate(BeginDate) >= 0 and
DaysTillDate(EndDate) >= 0 then 1 else 0;

def hi = if isperiod and high > hi[1] then high else hi[1];

def hihi =  highestall(hi);
plot z = if isperiod then hihi else na;

addlabel(1, "highest price in date range " + hihi, color.yellow);
addlabel(1, BeginDate + " to " + endDate, color.yellow);
#
addchartbubble(1,low,isperiod,color.white,no);
 
@SleepyZ, I tried that but it didn't seem to work either however the below did work.
Code:
def hi = if isperiod and high > hi[1] then high else hi[1];

Follow up question for you guys. I'm trying to dynamically update the BeginDate and EndDate but TOS doest seem to like my code. BeginDate and EndDate shows up properly in the labels but the isperiod is coming back as 0. Any thoughts on this?

Code:
def month = Getmonth();
def BeginDate = if
month == 1 then 20211201 else if
month == 2 then 20220101 else if
month == 3 then 20220201 else if
month == 4 then 20220301 else if
month == 5 then 20220401 else if
month == 6 then 20220501 else if
month == 7 then 20220601 else if
month == 8 then 20220701 else if
month == 9 then 20220801 else if
month == 10 then 20220901 else if
month == 11 then 20221001 else
20221101 ;

def EndDate = if
month == 1 then 20211231 else if
month == 2 then 20220131 else if
month == 3 then 20220228 else if
month == 4 then 20220331 else if
month == 5 then 20220430 else if
month == 6 then 20220531 else if
month == 7 then 20220630 else if
month == 8 then 20220731 else if
month == 9 then 20220831 else if
month == 10 then 20220930 else if
month == 11 then 20221031 else
20221130 ;


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

def isperiod = if DaysFromDate(BeginDate) >= 0 and
DaysTillDate(EndDate) >= 0 then 1 else 0;

def hi = if isperiod and high > hi[1] then high else hi[1];

def hihi =  highestall(hi);
plot z = if isperiod then hihi else na;

addlabel(1, "highest price in date range " + hihi, color.yellow);
addlabel(1, BeginDate + " to " + endDate, color.yellow);
#
addchartbubble(1,low,isperiod,color.white,no);
Here is what I posted above included in the code

Capture.jpg
Ruby:
def na = double.nan;
def bn = barnumber();
def BeginDate = 20220615;
def EndDate = 20220715;

def isperiod = if DaysFromDate(BeginDate) >= 0 and
DaysTillDate(EndDate) >= 0 then 1 else 0;

def hi = if bn == 0 or !isperiod then 0
else if isperiod and high > hi[1] then high else hi[1];

def hihi = highestall(hi);
plot z = if isperiod then hihi else na;

addlabel(1, "highest price in date range " + hihi, color.yellow);
addlabel(1, BeginDate + " to " + endDate, color.yellow);
#

addchartbubble(1,low,isperiod,color.white,no);
addchartbubble(1,low,hi,color.yellow,no);
 
Sorry, yes that works. I added another question about BeginDate and EndDate so I may have mixed the response which caused confusion. Anyway, thank you co much as usual. You guys are awesome!!

Code:
def month = Getmonth();
def BeginDate = if
month == 1 then 20211201 else if
month == 2 then 20220101 else if
month == 3 then 20220201 else if
month == 4 then 20220301 else if
month == 5 then 20220401 else if
month == 6 then 20220501 else if
month == 7 then 20220601 else if
month == 8 then 20220701 else if
month == 9 then 20220801 else if
month == 10 then 20220901 else if
month == 11 then 20221001 else
20221101 ;

def EndDate = if
month == 1 then 20211231 else if
month == 2 then 20220131 else if
month == 3 then 20220228 else if
month == 4 then 20220331 else if
month == 5 then 20220430 else if
month == 6 then 20220531 else if
month == 7 then 20220630 else if
month == 8 then 20220731 else if
month == 9 then 20220831 else if
month == 10 then 20220930 else if
month == 11 then 20221031 else
20221130 ;
 

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