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);
#