Highest High Problem


I'm having trouble with the HighestHigh script not giving me an expected result when used in a scan, but it giving the expected result when used in a ShowTool on the code and date I'm looking at.

APT on the 2/4/19 should register using my scan for the High > All Time High, but it doesn't come up.

The script I'm using is below.

I have set up a Show Tool using the HighestHigh function, and when placed on the APT chart it is working as expected.

Any idea what is going on?

Thank you.


Hi Merrilee,

Scanning for an all-time high works slightly differently than Show Plot. All you need to do is change the > to >= for it to work in a scan:


For more examples of highest high and lowest low formulas please see here:


Hi Darren


Thanks for you quick answer, I have changed the operator to >=.

However, my scan is still not picking up APT on the 2/4/19.

I have checked and checked the chart, and it definitely did hit an all time high on the 2nd.

It also did on the 3/4, 5/4 and the 8/4.

The only date to appear in the scan as expected is the 8/4.

I've mucked around with 'include current bar', but it doesn't seem to make any difference.

Any idea what is wrong?

Thanks again for your help with this.



The HighestHigh() function, when set to All Time returns a single value, of the highest high across the entire chart.

For the type of scan you are doing you need to set the function to All History instead, which gives a progressive Highest High value as new bars are added to the chart.

The following image shows the difference between the two…


If you adjust your script to use All History instead of All Time the scanning manager will be able to return historical matches…


Oh yay, Matthew thank you!

Hello again

I'm still struggling with the HighestHigh function, I'd like to scan for the Close being greater (but not equal to) the Highest High in all history.

Below is the formula I created and ran on 2/4/19.

MFG and JIN are a few codes that should come up but don't.

What am I doing wrong?

PS. I've also tried to use the crossesabove operator but this seems to include not just the close being higher, but the high as well.

Thanks for you help :)



Hi Merrilee,

When I use HIGHESTHIGH or LOWESTLOW I am always very explicit at what type of highest high or lowest low I am looking for. In your example you are looking for a highest CLOSE, not a highest HIGH.

I would explicitly state CLOSE() after the parameters of the HIGHESTHIGH function have been stated, such as


The experts (Matthew, Darren) can confirm if this advice and coding is acceptable. In any case, my scripts have worked as expected when I script in this explicit fashion.

Good luck.

Thanks Dean, I'll try that again.

Although from memory, I think this returned the Close > the Highest Close, when I want the Close to be higher than the Highest High.

I also don't want it to show the Close being equal to this High either, but taking away the equal sign mucks things up.

It doesn't seem to work the way I'm expecting it to :(


Oh, I see. You want the CLOSE of this bar to be higher than highest high of all the bars preceding this bar. (By definition the close of a bar can never be higher than the high of the bar... it could be equal, which is usually infrequent). This could be achieved with a script something like:

previousHighestHigh = HIGHESTHIGH(RANGE=All History, HIGH());

isCloseHigherThanPreviousHighestHigh = CLOSE() > previousHighestHigh[1];

I've not tested this idea and I confess that I have not used the RANGE=All History parameter before, but from Matthew's explanation above, on face value the above script should give you the result you want. (Also note that I have explicitly included HIGH() in the HIGHESTHIGH function... while it may be redundant, I do this out of habit because it really helps with code readability).

The array index, [1], on variable previousHighestHigh tells Optuma to refer to the previous bar, not this bar. So Optuma will compare this bar's close to the highest high from all bars preceding this bar. (Incidentally, in a script like this I would prefer to use the explicit reference CLOSE(0)... then at a glance you can see that you are comparing bar 0 (current bar) with bar 1 (previous bar). This is immensely helpful in code readability).

Hope this gives you some clues and good luck.

Thank you again Dean.

I will read and re-read and play with this tomorrow.

It's very nice of you to try to help me - thanks :)

Hi Dean

Unfortunately, it didn't work. Thanks for your ideas.

I had actually tried writing it with a variable before, the sticking point seems to be the = sign, although even including it in the formula still misses results.

What I want seems so simple to me - I don't get why it's such a drama to code...

Today's close is higher than the previous all time high.


Merrilee, I'm sorry to hear that there was no success for you. That was intriguing so I tested the script because I most certainly do not want to be giving you bogus advice. I used a daily chart of the World Indices SPY (S&P 500 Stock Index) for testing. (Just use F2 and type SPY to open up its chart).

I found a date for SPY where the close was higher than the previous all-time high, and that occurred on 26 January 2018. Inspection of the chart around that time indicated that:

  • 26 January 2018: today's close was higher than the previous all-time high
  • 25 January 2018: today's close was not higher than the previous all-time high
  • 24 January 2018: today's close was not higher than the previous all-time high
  • 23 January 2018: today's close was higher than the previous all-time high
  • 22 January 2018: today's close was higher than the previous all-time high

So now we have five data points to test the script against. The script used was as follows:

previousHighestHigh = HIGHESTHIGH(RANGE=All History, HIGH());

isCloseHigherThanPreviousHighestHigh = CLOSE(0) > previousHighestHigh[1];


(I apologise that I did not include the third line of the script in my original reply ... the script editor should give an error without that third line because it needs to output something. I've included it for completeness this time around).

The script was assigned to the Show Bar tool, which used green down arrows to signal that the script returned a TRUE result. So we should see a green down arrow on 26, 23, 22 January but not 25 and 24 January.

The screen shot attached agrees with our expectation, so the script does seem to be achieving the desired outcome of determining if today's close is higher than the previous all-time high.

Incidentally, the script can be distilled down to one line without variables as follows:


This version of the script gives the same result.

One last thing that I found interesting, but you could ignore if you want. The HIGHESTHIGH function has a parameter called "Include Current Bar" which can be set to INCBAR=True or INCBAR=False. As follows:


I thought that that might be even the best way to achieve the desired outcome because the HIGHESTHIGH function would not include the current bar, essentially imitating the first two scripts. Unfortunately though, the script failed... and I'm not sure why.

My recommendation then is to use one of the first two scripts.

I really do hope that this gives you what you need.


If you encounter an unexpected result with a scan criteria the first step is to apply it to the chart as that will be where you pick up issues the fastest.

In the script you are using the issue relates to the Highest High changing the value on the same bar you're checking the Close against, so it would never trigger (this was not an issue on the first script i posted as we were dealing with High vs High).

When you are working with the HighestHigh() with All History selected, the high will always change on the day a new high is set. This means if you are looking for instances where the Close of the current day is higher than the previous days Highest High value you need to offset the function by 1.

The script to do this would be:


Close() > V1

The following example shows the results that match on a chart (Green Arrows), with the green line being the offset highest high.


Thank you Matthew, that works perfectly.

Dean seemed to be on the right track with the Offset idea, we just didn't implement it properly.

Thanks Dean also for all your effort :)