I would like to get help with coding for creating a script that combines the 5/20 ema crossing above and below the 50 ema to scan for potential breakouts during premarket and during the regular trading session. I am specifically looking for all three moving averages to cross at the same point in time or at least within 15 minutes. I like the 5 and 15 minute timeframes to spot early entries into big movers. Thanks again.
I would like to get help with coding for creating a script that combines the 5/20 ema crossing above and below the 50 ema to scan for potential breakouts during premarket and during the regular trading session. I am specifically looking for all three moving averages to cross at the same point in time or at least within 15 minutes. I like the 5 and 15 minute timeframes to spot early entries into big movers. Thanks again.
I would like to get help with coding for creating a script that combines the 5/20 ema crossing above and below the 50 ema to scan for potential breakouts during premarket and during the regular trading session. I am specifically looking for all three moving averages to cross at the same point in time or at least within 15 minutes. I like the 5 and 15 minute timeframes to spot early entries into big movers. Thanks again.
First time I try any coding (if you can call it so) but here is the modification of the original from @halcyonguy, I added warn and sell signals for shorting and the option to show warn-sell or not. I hope I'm posting this correctly:
Code:
# three_ema_crossings_00
#https://usethinkscript.com/threads/scanner-for-multipe-ema-crossover-5-20-50.15083/
#Scanner for Multipe EMA Crossover 5/20/50
def na = Double.NaN;
def bn = BarNumber();
# last bar ( most recent)
def lastbar = !IsNaN(close[0]) and IsNaN(close[-1]);
def valid = !IsNaN(close);
# emas ---------------------------------------
def price = close;
input MA1_len = 5;
input MA1_type = AverageType.EXPONENTIAL;
def ma1 = MovingAverage(MA1_type, price, MA1_len);
input MA2_len = 20;
input MA2_type = AverageType.EXPONENTIAL;
def ma2 = MovingAverage(MA2_type, price, MA2_len);
input MA3_len = 50;
input MA3_type = AverageType.EXPONENTIAL;
def ma3 = MovingAverage(MA3_type, price, MA3_len);
# -----------------------------------------------------
input show_avg_lines = yes;
plot z1 = if show_avg_lines then ma1 else na;
#z1.SetDefaultColor(getcolor(1));
z1.SetDefaultColor(Color.CYAN);
#z1.setlineweight(1);
z1.HideBubble();
plot z2 = if show_avg_lines then ma2 else na;
z2.SetDefaultColor(Color.YELLOW);
#z2.setlineweight(1);
z2.HideBubble();
plot z3 = if show_avg_lines then ma3 else na;
z3.SetDefaultColor(Color.MAGENTA);
#z3.setlineweight(1);
z3.HideBubble();
def up1x2 = ma1 crosses above ma2;
def up1x3 = ma1 crosses above ma3;
def dwn1x2 = ma1 crosses below ma2;
def dwn1x3 = ma1 crosses below ma3;
def up1x2bn = if bn == 1 then 0 else if up1x2 then bn else up1x2bn[1];
def up1x3bn = if bn == 1 then 0 else if up1x3 then bn else up1x3bn[1];
def dwn1x2bn = if bn == 1 then 0 else if dwn1x2 then bn else dwn1x2bn[1];
def dwn1x3bn = if bn == 1 then 0 else if dwn1x3 then bn else dwn1x3bn[1];
input max_minutes_between_crossings = 15;
#---------------------------------
def chartagg = GetAggregationPeriod();
def chartmin = chartagg / (1000 * 60);
#---------------------------------
def barz = max_minutes_between_crossings / chartmin;
def buy = if (up1x3bn - up1x2bn) <= barz and bn == up1x3bn then 1 else 0;
input show_yellow_warn_lines = no;
AddVerticalLine(show_yellow_warn_lines and up1x2, "buy-warn", Color.YELLOW);
AddVerticalLine(buy, "buy", Color.GREEN);
#-------------------------------
def sell = if (dwn1x3bn - dwn1x2bn) <= barz and bn == dwn1x3bn then 1 else 0;
input show_orange_warn_lines = no;
AddVerticalLine(show_orange_warn_lines and dwn1x2, "sell-warn", Color.ORANGE);
AddVerticalLine(sell, "sell", Color.RED);
#-------------------------------
AddChartBubble(0, low * 0.994,
bn + "\n" +
up1x3bn + " 13\n" +
up1x2bn + " 12\n" +
# chartmin + " min\n" +
barz + " max\n" +
buy + " B\n"
, Color.YELLOW, no);
#
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.
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.