You cannot even begin to imagine how difficult this is for a scripting language like Thinkorswim. In order to do this properly we need to have the ability to create and work with custom sized arrays. Since we do not, the solution is not very robust. This only works if you have 5 days of 5 min data on the chart. Anything more or less and it fails. And as you mentioned, this approach also requires that the chart NOT included extended hours session.
def newDay = GetDay() <> GetDay()[1];
def firstBarRange = if newDay then high - low else 0;
rec trackRange = if newDay then firstBarRange else trackRange[1];
rec trackWidestRange = if newDay then Max(firstBarRange, trackRange[1]) else trackWidestRange[1];
plot conditionWidestRange = newDay[1] and firstBarRange[1] > trackWidestRange[2];
rec todayIsWidest = if newDay then 0 else if conditionWidestRange then 1 else todayIsWidest[1];
AddLabel(1, if todayIsWidest then “WR” else ” “, color.WHITE);
Don't even bother trying to figure out exactly how this code works unless you want to bring on a severe headache.
I will make some closing comments about your code. You need to include spaces between your operators and variable names.
Example One:
You entered def newDay = GetDay()<>GetDay()[1];
and it was reformatted to def newDay = GetDay()GetDay()[1];
Because you failed to included spaces the HTML compiler in every web browser treats those greater than and less than symbols as special characters and removes them.
Example Two:
You entered rec range3 = if newDay then high[156]-low[156] else 0;
and it should have been def range3 = if newDay then high[156] - low[156] else 0;
See the space between the minus sign and the two elements on either side?
Example Three:
You entered def WR = if newDay and range1>range2 and range1>range3 and range1>range4 and range1>range5 then 1 else 0;
and it should have been def wr = if newDay and range1 > range2 and range1 > range3 and range1 > range4 and range1 > range5 then 1 else 0;
These are the reasons that your code from the previous post got butchered. I have no idea why some folks fail to include spaces between operators and other elements. Drives me nuts to see that. So stop it. It causes problems you cannot fully fathom.
I understand the approach you took. However that is much more fragile than the solution I generated. The reason is that you can never be certain any give stock is going to have a full complement of 5 min bars. So if you have gaps in the trading day your indexes will miss their mark. The other point of failure in your approach is the statement for "wr" will only be true on the first bar of the trading session. So your label would go blank as soon as the second bar appears on the chart. You have to use recursion to carry that value forward as new bars are added to the chart.