Scanner to find distance between price and moving average?

  • Thread starter YungTraderFromMontana
  • Start date
YungTraderFromMontana

YungTraderFromMontana

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

mc01439

Well-known member
2019 Donor
VIP
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).

P is greater than .50 would be the scan.

#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

This would be the results for the S&P 100.
Watchlist Scanner
Results
SymbolDescriptionSMA Diff
TGTTARGET CORP COM
23.18​
LMTLOCKHEED MARTIN CORP COM
15.94​
NEENEXTERA ENERGY INC COM
14.97​
PGPROCTER & GAMBLE CO COM
14.49​
SOSOUTHERN CO. COM
14.45​
COSTCOSTCO WHOLESALE CORP COM
14.38​
AAPLAPPLE INC COM
14.01​
TAT&T INC COM
13.92​
HDHOME DEPOT INC COM
13.73​
QCOMQUALCOMM INC COM
13.62​
AIGAMER INTL GRP INC COM
13.16​
TXNTEXAS INSTRUMENTS INC COM
12.99​
WMTWALMART INC COM
12.39​
SBUXSTARBUCKS CORP COM
12.11​
MSFTMICROSOFT CORP COM
11.79​
MDTMEDTRONIC PLC COM
11.77​
CHTRCHARTER COMMUNICATIONS INC COM CL A
11.36​
AGNALLERGAN PLC. COM
11.26​
MAMASTERCARD INCORPORATED COM CL A
11.23​
ALLALLSTATE CORP COM
10.89​
DHRDANAHER CORP COM
10.25​
RTNRAYTHEON CO COM
9.88​
MDLZMONDELEZ INTL INC COM CL A
9.81​
NKENIKE INC COM CL B
9.72​
UPSUNITED PARCEL SERVICE INC COM CL B
9.42​
ACNACCENTURE PLC COM
9.01​
VVISA INC COM CL A
8.9​
CMCSACOMCAST CORP COM CL A
8.79​
KOCOCA-COLA CO COM
8.7​
PEPPEPSICO INC COM
8.55​
CELGCELGENE CORP COM
8.13​
GOOGALPHABET INC COM CL C
7.83​
JPMJPMORGAN CHASE & CO. COM
7.71​
GOOGLALPHABET INC COM CL A
7.54​
MCDMCDONALD'S CORPORATION COM
7.48​
DUKDUKE ENERGY CORP COM
7.45​
BKNGBOOKING HOLDINGS INC COM
7.4​
UTXUNITED TECHNOLOGIES CORP COM
7.4​
LOWLOWE'S COMPANIES INC COM
7.24​
USBUS BANCORP COM
7.24​
CCITIGROUP INC COM
6.23​
GDGENERAL DYNAMICS CORP COM
6.22​
BABOEING CO COM
5.65​
COFCAPITAL ONE FINANCIAL CORP COM
5.46​
IBMINTERNATIONAL BUS MACH CORP COM
5.44​
VZVERIZON COMMUNICATIONS COM
5.43​
CLCOLGATE-PALMOLIVE CO COM
5.3​
GSGOLDMAN SACHS GROUP INC COM
5.01​
KMIKINDER MORGAN INC COM
4.94​
ABTABBOTT LABORATORIES COM
4.72​
CVSCVS HEALTH CORPORATION COM
4.36​
HONHONEYWELL INTERNATIONAL INC COM
4.19​
AXPAMERICAN EXPRESS CO COM
4.12​
AMGNAMGEN INC COM
4.09​
MRKMERCK & CO INC COM
4.04​
BMYBRISTOL-MYERS SQUIBB CO COM
3.98​
DISWALT DISNEY COMPANY (THE) COM
3.7​
FBFACEBOOK INC COM CL A
3.03​
BACBANK OF AMERICA CORPORATION COM
2.83​
WFCWELLS FARGO & COMPANY COM
2.74​
INTCINTEL CORP COM
2.64​
METMETLIFE INC COM
2.62​
EXCEXELON CORP COM
2.55​
BLKBLACKROCK INC COM
2.43​
ORCLORACLE CORP COM
1.95​
BRK/BBERKSHIRE HATHAWAY INC COM CL B
1.17​
PYPLPAYPAL HOLDINGS INC COM
0.66​
CVXCHEVRON CORPORATION COM
0.53​
 
2

2sureshk

Member
P is greater than .50 would be the scan.

#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

This would be the results for the S&P 100.
Watchlist Scanner
Results
SymbolDescriptionSMA Diff
TGTTARGET CORP COM
23.18​
LMTLOCKHEED MARTIN CORP COM
15.94​
NEENEXTERA ENERGY INC COM
14.97​
PGPROCTER & GAMBLE CO COM
14.49​
SOSOUTHERN CO. COM
14.45​
COSTCOSTCO WHOLESALE CORP COM
14.38​
AAPLAPPLE INC COM
14.01​
TAT&T INC COM
13.92​
HDHOME DEPOT INC COM
13.73​
QCOMQUALCOMM INC COM
13.62​
AIGAMER INTL GRP INC COM
13.16​
TXNTEXAS INSTRUMENTS INC COM
12.99​
WMTWALMART INC COM
12.39​
SBUXSTARBUCKS CORP COM
12.11​
MSFTMICROSOFT CORP COM
11.79​
MDTMEDTRONIC PLC COM
11.77​
CHTRCHARTER COMMUNICATIONS INC COM CL A
11.36​
AGNALLERGAN PLC. COM
11.26​
MAMASTERCARD INCORPORATED COM CL A
11.23​
ALLALLSTATE CORP COM
10.89​
DHRDANAHER CORP COM
10.25​
RTNRAYTHEON CO COM
9.88​
MDLZMONDELEZ INTL INC COM CL A
9.81​
NKENIKE INC COM CL B
9.72​
UPSUNITED PARCEL SERVICE INC COM CL B
9.42​
ACNACCENTURE PLC COM
9.01​
VVISA INC COM CL A
8.9​
CMCSACOMCAST CORP COM CL A
8.79​
KOCOCA-COLA CO COM
8.7​
PEPPEPSICO INC COM
8.55​
CELGCELGENE CORP COM
8.13​
GOOGALPHABET INC COM CL C
7.83​
JPMJPMORGAN CHASE & CO. COM
7.71​
GOOGLALPHABET INC COM CL A
7.54​
MCDMCDONALD'S CORPORATION COM
7.48​
DUKDUKE ENERGY CORP COM
7.45​
BKNGBOOKING HOLDINGS INC COM
7.4​
UTXUNITED TECHNOLOGIES CORP COM
7.4​
LOWLOWE'S COMPANIES INC COM
7.24​
USBUS BANCORP COM
7.24​
CCITIGROUP INC COM
6.23​
GDGENERAL DYNAMICS CORP COM
6.22​
BABOEING CO COM
5.65​
COFCAPITAL ONE FINANCIAL CORP COM
5.46​
IBMINTERNATIONAL BUS MACH CORP COM
5.44​
VZVERIZON COMMUNICATIONS COM
5.43​
CLCOLGATE-PALMOLIVE CO COM
5.3​
GSGOLDMAN SACHS GROUP INC COM
5.01​
KMIKINDER MORGAN INC COM
4.94​
ABTABBOTT LABORATORIES COM
4.72​
CVSCVS HEALTH CORPORATION COM
4.36​
HONHONEYWELL INTERNATIONAL INC COM
4.19​
AXPAMERICAN EXPRESS CO COM
4.12​
AMGNAMGEN INC COM
4.09​
MRKMERCK & CO INC COM
4.04​
BMYBRISTOL-MYERS SQUIBB CO COM
3.98​
DISWALT DISNEY COMPANY (THE) COM
3.7​
FBFACEBOOK INC COM CL A
3.03​
BACBANK OF AMERICA CORPORATION COM
2.83​
WFCWELLS FARGO & COMPANY COM
2.74​
INTCINTEL CORP COM
2.64​
METMETLIFE INC COM
2.62​
EXCEXELON CORP COM
2.55​
BLKBLACKROCK INC COM
2.43​
ORCLORACLE CORP COM
1.95​
BRK/BBERKSHIRE HATHAWAY INC COM CL B
1.17​
PYPLPAYPAL HOLDINGS INC COM
0.66​
CVXCHEVRON CORPORATION COM
0.53​
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
 
V

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
 
T

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

close crosses above ExpAverage(close, 50) * 1.1
 
F

freedom Traders

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
 

Similar threads

Top