Scan stocks within specified percent of median price


Category:
0
0

Can you please provide guidance for thinkorswim platform on how to write a stock scanner… which are within positive or negative 5% of the 20 day median value of the stock in the last 20 days? Thank you.

Example.. Median of stock – 100. Stock is oscillating between 95 to 105.. Filter all stocks that pass this criteria..

Thank you.

Marked as spam
Posted by (Questions: 1, Answers: 1)
Asked on April 17, 2021 4:19 pm
50 views
0
Private answer

The "median" price is defined as the midpoint between the high and the low of each candle. We can use any standard moving average to compute this, by simply changing the price input from close to "hl2".

There is a previous post that does most of the grunt work for this solution and that post is located here:

https://www.hahn-tech.com/ans/alert-when-sma-within-x-percent-of-another-sma/

The following code has been modified to check when the current price is within the specified percent of the 20 period simple moving average of the median price:

input withinPercent = 5.0;
input maLengthOne = 20;
input maTypeOne = AverageType.SIMPLE;
input maPriceOne = hl2;
def maOne = MovingAverage(maTypeOne, maPriceOne, maLengthOne);
def upperBound = maOne * (1 + withinPercent * 0.01);
def lowerBound = maOne * (1 - withinPercent * 0.01);
plot signal = close > lowerBound and maOne < upperBound;

Marked as spam
Posted by (Questions: 37, Answers: 4086)
Answered on April 18, 2021 3:53 pm
0
Mr. Hahn - Thank you. It helps to see how this is done and improvised this further.
( at April 21, 2021 5:36 am)