Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
I need to know how to scan in thinkorswim for a stock price that closed above or below a moving average for a certain number of days. EXAMPLE: On a chart the price has consistently closed above the 12 simple moving average for 42 days. how would I scan for this? Thank you.
Can you help answer these questions from other members on NexusFi?
Hello, you are going to have to create an indicator that can look back and check if the last 42 bars have been above the 12 SMA.
To accomplish that you are going to have to use the fold operator in thinkscript to iterate through the last 42 bars and return a true or false value.
Here are two indicators, called ChronicCloseAboveMA and ChronicCloseBelowMA. The first puts a red up arrow when the close has been above the MA for a long time and the second puts a blue down arrow when the close has been below the MA.
You can go to Edit studies, select Create, delete the default text in the box, and paste these codes in separately and then name each indicator up at the top of the page. To perform a scan, select one of the two studies and "is true" "within 1 bar" and the scan will work.
There were no stocks that fit the criteria you set for a close above the moving average when I used 42 days, so I've set the default to 25 days. When I scanned with 25 there were several hits using each indicator (for stocks with a close of 10 or higher and minimum volume of 100,000 shares).
You can change the 25 days to any length you want in the inputs. You can also change the 12 period SMA to different periods and different moving averages.
I pasted a chart of a stock that shows both types of arrows down below. Not sure if it will show up properly...
# ChronicCloseAboveMA
# Response to vrinx3547 question
# malength is the number of periods used for the moving average and length2 is the number of bars with their close above the moving average
# ChronicCloseBelowMA
# Response to vrinx3547 question
# malength is the number of periods used for the moving average and length2 is the number of bars with their close below the moving average