I’m attempting to write a screener that finds stocks which are moving within a price range and is fairly volatile. Here’s an example of what I’m looking for: https://www.tradingview.com/x/dknyWipv/
I know of multiple indicators that measure the volatility. I guess the trick will be to somehow find an indicator/code something that identifies the ranging/trendless behaviour. Does anyone have any ideas as how to approach this?
Try to count how many times moving average cross over occurred and compare their prices with the median of the last highest high and lowest low, within a percentage margin. Rough idea from your picture, need to be coded and tested!
I will give that a shot and see how it works out. 🙂
Before your answer I was working on a screener that tried to measure how far away the 100 EMA and the 200 EMA was from each other on average. The idea was that if the distance was less than 2.5% for maybe 70 bars, that could have been one critiera.
1
2
3
4
5
6
7
8
9
10
11
12
ema200=ExponentialAverage[200]
ema100=ExponentialAverage[100]
periodsMatching=0
FORi=0to200DO
distance=ema100[i]/ema200[i]
IFdistance<1.025anddistance>0.975THEN
periodsMatching=periodsMatching+1
ENDIF
NEXT
SCREENER[periodsMatching>50](periodsMatchingas"bars within range")
To my suprise, this screener returned a lot of stocks where the amount of bars that exactly fit the criteria was 56. So I think there’s some kind of bug in my screener code here?
To help us continually offer you the best experience on ProRealCode, we use cookies. By clicking on "Continue" you are agreeing to our use of them. You can also check our "privacy policy" page for more information.Continue