Close in the upper or lower half of yesterdays range


Category:
0
0

Hello there Mr. Hahn,

I have another very simple request for you. I already found the code to scan for inside bars on your site. What I would like next would be to scan for stocks that close in the upper 40% or lower 40% of the previous bars’ range and for the current bar to also close in the upper 40% or lower 40% of its range. Thanks in advance. Very much appreciate all you do.

Regards,

Marked as spam
Posted by (Questions: 3, Answers: 4)
Asked on June 21, 2020 12:08 pm
80 views
1
Private answer

I see you have four individual conditions but you did not explain how you wanted each of these conditions to be matched up.

So my solution includes for variables named signalOne, signalTwo, signalThree and signalFour. The last line is the plot statment for the scan and you can see that it combines signalOne and signalTwo conditions. You can mix and match as needed to get the combination you want to apply. However you will note that signalOne and signalThree are contradictory and likewise for signalTwo and SignalFour. So don't try combining those!

input percentThreshold = 40.0;
def percentOfRangeCurrent = (close - low) / (high - low);
def percentOfRangePrevious = (close - low[1]) / (high[1] - low[1]);
# scan for current close within upper x percent of current range
def signalOne = percentOfRangeCurrent > 1 - percentThreshold * 0.01;
# scan for current close within upper x percent of previous range
def signalTwo = percentOfRangePrevious > 1 - percentThreshold * 0.01;
# scan for current close within lower x percent of current range
def signalThree = percentOfRangeCurrent < percentThreshold * 0.01;
# scan for current close within lower x percent of previous range
def signalFour = percentOfRangePrevious < percentThreshold * 0.01;
plot scan = signalOne and signalTwo;

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on June 21, 2020 12:34 pm
0
That's right I apologize. So yes it would be one scan for the bar to close on the upper 40% of the current and previous bar and another scan to close on the lower 40% of the current and previous bar. Thank you again for your prompt reply.
( at June 21, 2020 1:36 pm)
0
Would it be possible to apply this scan to just the second bar of the day? For example: The second 5 minute bar closes on the upper 40% of the first bars range and its current range. The other scan would be the second 5 minute bar closes on lower 40% of the first bars range and its current range.
( at June 21, 2020 2:08 pm)
0

Just set the time frame to whatever you want to use. The code knows nothing whatsoever about time. The only thing the code knows is to compare the current bar’s close to the current bar’s range and the current bars close compared to the previous bar’s range.

( at June 21, 2020 2:22 pm)