Along with this solution I will explain the request clearly states “50% away from it’s high”. There is only one way to interpret this. And that is to take the high of the day, multiply it by 0.5. So that a high of 100 would result in a close of 50. That is the close, 50% away (down from) the high.
Since this is never going to appear on any chart I am very certain that something else entirely was intended. However I am not going to act on that until further details are provided. Here is the code based on a strict interpretation of the request.
input percent = 50.0;
def percentCloseFromHigh = 100 * (close / high - 1);
plot scan = percentCloseFromHigh >= percent;
I suspect the true intent of this request is that the close should be half way between the range of the high and low of the bar. In which case the close would be in the middle of it’s daily range. We’ll wait to see what JB has to say.
Edit
So I was correct. JB has just confirmed what I suspected was the true intention. Sorry that this post is going to be very confusing for the rest of our viewers.
Here is the solution to the close being in the lower half of the daily range (daily high to daily low).
input percent = 50.0;
def percentCloseWithinRange = (close - low) / (high - low);
plot scan = percentCloseWithinRange * 100 <= percent;
You hit the nail on the head, my true intent of this request is the close should be half way between the range of the high and low of the daily bar.
You are correct which case the close would be in the middle of its daily range.
Visually this would show a green candle with a long upwards wick.
I have updated my answer to include the code for this.
So from testing the code, it seems that the scanner picks up red candles also, I wanted to know if we could tighten the code up to only show the current dailey GREEN candle only whose close if ways off from its high on the daily chart. Thank you
This does not need to be incorporated into the code. It can be added as a separate Study Filter, set to the same time frame. You can build this with the condition wizard. Close is greater than Open. The end result should be:
close > open
thank you
Hello Hahn, do you know why the code provided for this solution is not picking up the stock NBEV right now, it seems to have closed weak off its high for the day?
As of the close on 9/18/18, this did not close in the bottom half of the range. It closed in the upper 25% of the range. Are you working with a daily time frame?
Yes, i see, I need to look at the entire range
Another question, why didnt this stock pick up CSBR as of today 9/18/18: Did the stock close 50% from the high ?
No, it just missed. CSBR would have had to close below 12.25 and it closed at 12.30.