First time close under a moving average in x number of bars

EDDY GARCIA

New member
Im trying to setup a scan looking for trends that are on the verge of dying. so im looking for strong stocks that have respected a certain moving average, we'll say the 10 week.

1) its consecutively closed over the 10 week ma for 10 weeks, but week 11 now has closed below it. Do I need to specify a lookback period of 11 in this case and do I need to compare close to each of the 11 periods moving averages and count the streak using compound value? sorry if its confusing Ive been messing with this one for a bit.
 

tomsk

Well-known member
VIP
@EDDY GARCIA Here is a scan that consecutively closed above the 10 week moving average but for the 11th week closed below it.
Make sure you run this on a WEEKLY aggregation on the scanner.
I just scanned the S&P 500 and obtained 3 hits - HCP, HD and SO

# Dying Trends Scan
# tomsk
# 11.11.2019

def MA = Average(close, 10);
plot scan = sum(close[1] > MA[1], 10) == 10 and close < MA;
# END SCAN
 
Last edited:

diazlaz

Well-known member
2019 Donor
VIP
thank you! you are the best!. my way was much sloppier comparing each close for 10 weeks. very cool stuff thanks again!
Eddy such a simple idea, trading doesn't have to be so complicated ;) I Like your idea and thoughts of using this to quickly identify weakness and trade the pullback or reverse.
 

Similar threads

Top