scan for sma and rsi & exclude those reporting earnings

bcbbab

New member
Just looking everywhere and Can't seem to find these. I want a TOS scan that will scan stocks that meet these requirements; 1) stock price close above 200 day sma 2) yesterday price was under 200 day sma 3) price above 10 day ema 4) RSI less than 70 5) does not have earnings before or after 2 days
 
Solution
Just looking everywhere and Can't seem to find these. I want a TOS scan that will scan stocks that meet these requirements; 1) stock price close above 200 day sma 2) yesterday price was under 200 day sma 3) price above 10 day ema 4) RSI less than 70 5) does not have earnings before or after 2 days

here is a lower study to experiment with.
should be able to remove the last part of code and use in a scan (look for comment)

top pulse line is the output of all 5 rules
bottom 5 pulse lines are each rule. listed in bubble.

AMGN day

Code:
#scan_excludenear_earnings_lower

#https://usethinkscript.com/threads/scan-for-sma-and-rsi-exclude-those-reporting-earnings.19510/
#scan for sma and rsi & exclude those reporting earnings
#bcbbab...
Just looking everywhere and Can't seem to find these. I want a TOS scan that will scan stocks that meet these requirements; 1) stock price close above 200 day sma 2) yesterday price was under 200 day sma 3) price above 10 day ema 4) RSI less than 70 5) does not have earnings before or after 2 days

here is a lower study to experiment with.
should be able to remove the last part of code and use in a scan (look for comment)

top pulse line is the output of all 5 rules
bottom 5 pulse lines are each rule. listed in bubble.

AMGN day

Code:
#scan_excludenear_earnings_lower

#https://usethinkscript.com/threads/scan-for-sma-and-rsi-exclude-those-reporting-earnings.19510/
#scan for sma and rsi & exclude those reporting earnings
#bcbbab  Aug 25, 2024

#Just looking everywhere and Can't seem to find these. I want a TOS scan that will scan stocks that meet these requirements; 
# 1) stock price close above 200 day sma 
# 2) yesterday price was under 200 day sma 
# 3) price above 10 day ema 
# 4) RSI less than 70 
# 5) does not have earnings before or after 2 days


declare lower;
#  time = day

def na = Double.NaN;
def bn = BarNumber();
def data = close;

# rule 1, 2
# 1) stock price close above 200 day sma 
# 2) yesterday price was under 200 day sma 
input avg1_type = AverageType.SIMPLE;
input avg1_length = 200;
def avg1 = MovingAverage(avg1_type, data, avg1_length );
def r1 = close > avg1;
def r2 = close[1] < avg1[1];


# rule 3
# 3) price above 10 day ema 
input avg2_type = AverageType.EXPONENTIAL;
input avg2_length = 10;
def avg2 = MovingAverage(avg2_type, data, avg2_length );
def r3 = close > avg2;


# rule 4
# 4) RSI less than 70 
input rsi_length = 14;
input rsi_over_Bought = 70;
input rsi_over_Sold = 30;
input rsi_price = close;
input rsi_averageType = AverageType.WILDERS;
def NetChgAvg = MovingAverage(rsi_averageType, rsi_price - rsi_price[1], rsi_length);
def TotChgAvg = MovingAverage(rsi_averageType, AbsValue(rsi_price - rsi_price[1]), rsi_length);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;
def RSI = 50 * (ChgRatio + 1);

def r4 = rsi < rsi_over_Bought;


#rule 5
# 5) does not have earnings before or after 2 days
input earnings_days = 2;

#ref
#https://usethinkscript.com/threads/getting-next-earnings-date-in-watchlist-column.19557/
#in a column, can look at 30 future days to check for earnings
#days to prev earnings
def PE = GetEventOffset(Events.EARNINGS, -1);
#days to next earnings
def NE = GetEventOffset(Events.EARNINGS, 0);
def r5 = pe > earnings_days and absvalue(ne) > earnings_days ;

plot scan = r1 and r2 and r3 and r4 and r5;


#----------------------------------
# remove code after this line when using as a scan

def f = 0.15;
def y = 1.4;
def iscls = isnan(close);

plot z1 = if iscls then na else (r1*f) - (1*f*y);
plot z2 = if iscls then na else (r2*f) - (2*f*y);
plot z3 = if iscls then na else (r3*f) - (3*f*y);
plot z4 = if iscls then na else (r4*f) - (4*f*y);
plot z5 = if iscls then na else (r5*f) - (5*f*y);

plot w = if iscls then na else 1.2;
w.setdefaultcolor(color.black);

def t = 5;
def x = !isnan(close[t+1]) and isnan(close[t]);
addchartbubble(x, 0,
"close > 200SMA\n" +  
"yesterday close < 200SMA\n" +
"close > 10EMA\n" + 
"RSI < 70\n" +
"no earnings within 2 days"
, color.yellow, no);

input show_avg1_line = no;
input show_avg2_line = no;
plot zavg1 = if show_avg1_line then avg1 else na;
plot zavg2 = if show_avg2_line then avg2 else na;
zavg1.SetDefaultColor(Color.CYAN);
zavg1.SetLineWeight(1);
zavg1.HideBubble();
zavg2.SetDefaultColor(Color.YELLOW);
zavg2.SetLineWeight(1);
zavg2.HideBubble();
#
 

Attachments

  • img1-amgn day.JPG
    img1-amgn day.JPG
    95.5 KB · Views: 36
Solution

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Thread starter Similar threads Forum Replies Date
S Scan for stocks Trading Within 0.xx$ of 200 SMA Questions 0
S flat sma 200 scan Questions 2
samiranadhikari SMA Stoch MACD scan Questions 2
Allen Liang SMA - simple scan Questions 2
H 20-day SMA scan Questions 7

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
448 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top