Last Bar Closes within 10% of its high

Hello,

I am trying to find a script that will scan a watchlist for days when the previous daily bar has closed within the top 10% of the bar (or closed within the bottom 10% of the bar). I have found a couple of scripts from previous posts and tweaked them but can’t seem to get them to work. They are lighting up every single bar when I test them with a showbar and all rows are true on the watchlist.

Close() > (HIGHESTHIGH(BACKTYPE=Days, BARS=1) *(1-0.10))

and also

CLOSE() >= (HIGHESTHIGH(RANGE=LOOK BACK PERIOD,BARS=1)*0.90)

Any idea what I’m doing wrong?

Thanks so much!

Jeff

Hi Jeff,

I’d use the following to find when the previous daily bars close was within the top 10% of the bars range:

//Find Bar Range
V1 = HIGH() - LOW();
//Find 10% of Bar Range
V2 = V1 * 0.1;
//Set Upper 10% Range
V3 = HIGH() - V2;
//Find Closes Equal to or Above 10% of Upper Range
V4 = CLOSE() >= V3;
//Find where previous bars Close is in the Upper 10% Range
V4[1] == 1

Thank you so much Matthew!

I put the text of your request into Optuma’s new Scripter Bot and this is what it spit back out. This thing is a game-changer!
Here’s a script that scans for days when the previous daily bar has closed within the top 10% or the bottom 10% of the bar:

// Find Bar Range
V1 = HIGH() - LOW(); 

// Find 10% of Bar Range
V2 = V1 * 0.1; 

// Set Upper 10% Range
V3 = HIGH() - V2; 

// Set Lower 10% Range
V4 = LOW() + V2; 

// Find Closes Equal to or Above 10% of Upper Range
V5 = CLOSE() >= V3; 

// Find Closes Equal to or Below 10% of Lower Range
V6 = CLOSE() <= V4; 

// Find where previous bar's Close is in the Upper 10% or Lower 10% Range
V7 = V5[1] or V6[1]; 

// Output Result
V7

Explanation:

  • V1 calculates the range of the bar by subtracting the low from the high.
  • V2 calculates 10% of that range.
  • V3 sets the upper threshold for the top 10% of the bar.
  • V4 sets the lower threshold for the bottom 10% of the bar.
  • V5 checks if the current close is greater than or equal to the upper threshold.
  • V6 checks if the current close is less than or equal to the lower threshold.
  • V7 checks if the previous bar’s close was in either the upper or lower 10% range.
  • The final output is V7, which indicates whether the criteria are met.

You can use this script to scan your watchlist for the specified conditions. Let me know if you need any further modifications!