My code isn't working to get yesterday's highest high on 30 minute Watchlist column

greco26

Active member
HI,

I'm trying to return the value of yesterday's highest high but on a 30 minute watchlist column. The code below returns a high from yesterday but not the highest high for the entire day. Any thoughts on what I'm doing wrong?

Code:
def yesthi = if getday() then highest(high) else yesthi[1];
addlabel(yes, yesthi,color.white);
 
Solution
HI,

I'm trying to return the value of yesterday's highest high but on a 30 minute watchlist column. The code below returns a high from yesterday but not the highest high for the entire day. Any thoughts on what I'm doing wrong?

Code:
def yesthi = if getday() then highest(high) else yesthi[1];
addlabel(yes, yesthi,color.white);


regarding this line,
def yesthi = if getday() then highest(high) else yesthi[1];

for this to work, the condition would have to be true on the first bar of today, and the correct length in highest(). ( but the length will need to be different, depending on what the chart time is, and you can't use a complex formula for a length).


...getday() returns the day number of the year. it is not a...
HI,

I'm trying to return the value of yesterday's highest high but on a 30 minute watchlist column. The code below returns a high from yesterday but not the highest high for the entire day. Any thoughts on what I'm doing wrong?

Code:
def yesthi = if getday() then highest(high) else yesthi[1];
addlabel(yes, yesthi,color.white);


regarding this line,
def yesthi = if getday() then highest(high) else yesthi[1];

for this to work, the condition would have to be true on the first bar of today, and the correct length in highest(). ( but the length will need to be different, depending on what the chart time is, and you can't use a complex formula for a length).


...getday() returns the day number of the year. it is not a true/false condition.
it is never 0, so i think it might be always interpreted as true.

add this to a chart study to see the day numbers of the year.
addchartbubble(1, low*0.992, getday(), color.yellow, no);

...highest() expects to have a length, how many bars to look at.
if the length is missing, the default is 12. which will not be the correct amount to look at yesterday.

https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Date---Time/GetDay
https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Tech-Analysis/Highest



----------------------------

this will work in a column, to get 1 of 4 stats from yesterday. open, high, low, or close.
there are plots and labels, because i tested it on a chart, before testing in a column.

the high plot is the only output line that is not commented out.
if a different stat is desired, add a # to plot zh = yhigh; and remove # from another plot.

this is roberts' code, from here
https://usethinkscript.com/threads/...allowed-in-thinkorswim-scanner.927/#post-7189


Ruby:
def today = GetDay() == GetLastDay();
def mktOpen = SecondsFromTime(0930) == 0 or GetDay() <> GetDay()[1];

def yOpen = if today then yOpen[1] else if mktOpen then open else yOpen[1]; #yesterday's open
def yHigh = if today then yHigh[1] else if mktOpen then high else if high > yHigh[1] then high else yHigh[1]; #yesterday's high
def yLow = if today then yLow[1] else if mktOpen then low else if low < yLow[1] then low else yLow[1]; #yesterday's low
def yClose = if today then yClose[1] else close; #yesterday's close

#plot zo = yopen;
plot zh = yhigh;
#plot zl = ylow;
#plot zc = yclose;

#addlabel(1, "yest open: " + yopen, color.yellow);
#addlabel(1, "yest high: " + yhigh, color.yellow);
#addlabel(1, "yest low: " + ylow, color.yellow);
#addlabel(1, "yest close: " + yclose, color.yellow);
#
 
Last edited:
Solution

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

@halcyonguy , my theory is that T below should return the highest high for today but it doesn't look like I'm getting that. Do you happen to see what I'm doing wrong? Thank you as always!!

def H = high;
def L = low;
def C = close;
def O = open;
def bn = barnumber();

def isRollover = GetYYYYMMDD() != GetYYYYMMDD()[1];
def beforeStart = GetTime() < RegularTradingStart(GetYYYYMMDD());
def firstBarOfDay = if (beforeStart[1] == 1 and beforeStart == 0) or (isRollover and beforeStart == 0) then bn else firstBarOfDay[1];

def t = if bn >= firstbarofday and high >= highest(high) then high else t[1];
 
@halcyonguy , my theory is that T below should return the highest high for today but it doesn't look like I'm getting that. Do you happen to see what I'm doing wrong? Thank you as always!!

def H = high;
def L = low;
def C = close;
def O = open;
def bn = barnumber();

def isRollover = GetYYYYMMDD() != GetYYYYMMDD()[1];
def beforeStart = GetTime() < RegularTradingStart(GetYYYYMMDD());
def firstBarOfDay = if (beforeStart[1] == 1 and beforeStart == 0) or (isRollover and beforeStart == 0) then bn else firstBarOfDay[1];

def t = if bn >= firstbarofday and high >= highest(high) then high else t[1];

just staring at the code....

have you tried turning on extended hours?

if extended hours is off,
i think beforeStart will never be true.
i think isRollover can determine the 1st bar
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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