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)
Scan for stocks above or below simple moving average
Was told TOS script is very powerful and hope to build a script to scan for stocks that is above or below 20 day simple moving. For bullish scan, the previous day close has to be below the 20 day simple moving average. Vice versa for a bearing scan. Attached is a picture for better understanding.
Can somebody teach me how to build? If such script is too difficult, am willing to pay a small fee for your time.
Thanks for your time and help but I can't achieve what you have shown.
Using your Watchlist Indicator:
input ma_length = 20;
def sma = SimpleMovingAvg(length=ma_length);
def bearish = open > sma && close < sma;
def bullish = close > sma && open < sma;
plot signal = if bullish then 1 else if bearish then 0 else -1;
signal.AssignValueColor(if signal == 1 then Color.Green else if signal == 0 then Color.Red else Color.Black);
AssignBackgroundCOlor(if signal == 1 then Color.Green else if signal == 0 then Color.Red else Color.Black);
Below is my scan result:
OMF is not touching the SMA 20:
XPO also not touching the sma 20:
Its a bullish scan, GFF is below sma 20:
Finally when i use the last code you share, i can't save the script.
Did i do anything wrong? Really appreciate your time and help.
Are you using the right script in the right location? The watchlist and scan only allow for one plot. It looks like you used the watchlist scanner for the scan, the chart study for the watchlist, and didn't use the scan code. The way I set up scan is you can only search for ONLY bearish or ONLY bullish trades.
Sad to say, still not 100% to what you have shown. If i use the 1st code:
input ma_length = 20;
def sma = SimpleMovingAvg(length=ma_length);
plot signal = open > sma && close < sma;
The price bar will be above the SMA.
However if i use the last code:
input maLength = 20;
def sma = SimpleMovingAvg(length=maLength);
def bearish = open > sma && close < sma;
def bullish = close > sma && open < sma;
plot ma = sma;
plot bullSignal = if bullish then low - (0.5 + tickSize())else DOuble.NaN;
plot bearSignal = if bearish then high + (0.5 + tickSize()) else Double.NaN;
The stock market crashed shortly after and didnt have much opportunity to test further the script.
Can you add another condition for me? I want the scan to show stocks that is making a new high as compared to the last price bar. That is to say, i want stocks that are above their 20 sma and when scan today, current price bar has made a higher high as compared to previous day.