# Scanner to find distance between price and moving average?

##### Well-known member
Does anybody have code for a scan that can filter by a stocks distance from a MA? For Example .5% away from 200 SMA (simple moving average).

Last edited by a moderator:

#### mc01439

##### Well-known member
2019 Donor
VIP
@YungTraderFromMontana P is greater than .50 would be the scan.

Code:
``````#start code
# define the percent difference of close - 200SMA

def a = Average(close, 200);
def d = close - a;
plot p = (d / close) * 100;

#end code``````

Thanks

#### 2sureshk

##### Member
@mc01439 Similar way —Is there a way to get 52 week high and 52 week low within 5% list ?

That will help for my exploration .. long at 52 week high - short at 52 week low

#### veerasareddy

##### New member
@BenTen Could you please help to compile this code for me. Scan for stocks whose price is X% above or below MA.

#### tomsk

##### Well-known member
VIP
Here is a scan for stocks with a close that is 10% above 50 day EMA. I just ran that scan query on the S&P 500 and found 2 results on a daily agg.

Code:
``close crosses above ExpAverage(close, 50) * 1.1``

##### New member
VIP
I need help with a script. Hello everyone,i am new to all of this I would like to know if it's possible for someone to help me with an alert on a 10 minute chart or 4hr chart. I need a script that can alert me when price is in a range in between two different Simple moving average for 4-5 bars. Please

#### Slickss

##### New member
Need script code for scan to load into watchlist columns of price on 60 min that is 5% or greater over 50 SMA also same for 30 min SMA ,,another column for 5% or greater over 20 SMA on 60 min and 30 min,,,,my intent is to identify prices extended from 50sma where rsi 3 day show overbought range of 90 or oversold of 20 ,,,thankyou

#### XeoNoX

##### Active member
VIP
@Slickss Just add the column and in the column define your timeframe. Price ix XYZ Percent away from XYZ Moving Average.

Code:
``````Price ix XYZ Percent away from XYZ MovingAverage
#Define Percent In Decimal
def percentvalue = .05;
#Define Moving Average Desired
def ma = simpleMovingAvg(close,50);
def s = ma*percentvalue;
plot scan = absvalue(close - ma) is greater than or equal to s;``````