Crossover of three moving Averages

Devanreddy

New member
VIP
Hello TS community. I've looked at the other MovAvg cross-over scripts and cannot quite find the script I am looking for. Perhaps I'm not looking hard enough.
I would like for an up arrow to be printed on the close of the candle when the 9 EMA crosses above the 20 EMA and the 9 EMA crosses above the 50 SMA and the 20 crosses above the 50 SMA. Similarly I am looking for a down arrow to be printed on the close of the candle when the 9 EMA crosses below the 20 EMA and the 9 EMA crosses below the 50 SMA and the 20 crosses below the 50 SMA.

I would also like a sound alert to be provided when this occurs.

Below is a chart depicting what I am looking for. The yellow circle is where the cross over occurs.

Thank you in advance for your help. I greatly appreciate it.

1711593355608.png
 
Last edited by a moderator:
Solution
Hello TS community. I've looked at the other MovAvg cross-over scripts and cannot quite find the script I am looking for. Perhaps I'm not looking hard enough.
I would like for an up arrow to be printed on the close of the candle when the 9 EMA crosses above the 20 EMA and the 9 EMA crosses above the 50 SMA and the 20 crosses above the 50 SMA. Similarly I am looking for a down arrow to be printed on the close of the candle when the 9 EMA crosses below the 20 EMA and the 9 EMA crosses below the 50 SMA and the 20 crosses below the 50 SMA.

I would also like a sound alert to be provided when this occurs.

Below is a chart depicting what I am looking for. The yellow circle is where the cross over occurs.

Thank you in advance for your...
Hello TS community. I've looked at the other MovAvg cross-over scripts and cannot quite find the script I am looking for. Perhaps I'm not looking hard enough.
I would like for an up arrow to be printed on the close of the candle when the 9 EMA crosses above the 20 EMA and the 9 EMA crosses above the 50 SMA and the 20 crosses above the 50 SMA. Similarly I am looking for a down arrow to be printed on the close of the candle when the 9 EMA crosses below the 20 EMA and the 9 EMA crosses below the 50 SMA and the 20 crosses below the 50 SMA.

I would also like a sound alert to be provided when this occurs.

Below is a chart depicting what I am looking for. The yellow circle is where the cross over occurs.

Thank you in advance for your help. I greatly appreciate it.

View attachment 21456

This provides an arrow and alert at the crossover of Multiple Moving Averages at the same bar.

Screenshot 2024-03-28 090703.png
Code:
#Multiple_MA_Crossover_at_Same_BAR

input alerts = yes;
input len1   = 9;
input len2   = 20;
input len3   = 50;
input price  = close;


plot ema9  = ExpAverage(price, len1);
plot ema20 = ExpAverage(price, len2);
plot sma50 = SimpleMovingAvg(price, len3);

plot up = ema9 crosses above ema20 and ema9 crosses above sma50 and ema20 crosses above sma50;
up.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
plot dn = ema9 crosses below ema20 and ema9 crosses below sma50 and ema20 crosses below sma50;
dn.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);

Alert(alerts and (up or dn), if up then "UP" else "DN", Alert.BAR, Sound.Ding);

ema9.SetDefaultColor(Color.CYAN);
ema20.SetDefaultColor(Color.PINK);
sma50.SetDefaultColor(Color.ORANGE);
ema9.SetLineWeight(3);
ema20.SetLineWeight(3);
sma50.SetLineWeight(3);

up.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
dn.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
up.SetDefaultColor(Color.GREEN);
dn.SetDefaultColor(Color.RED);
up.SetLineWeight(5);
dn.SetLineWeight(5);

#
 
Solution

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

@SleepyZ. Thank you so much. This works!. I appreciate it greatly.
Can this be converted into the HMA?

Some requested a different type of moving average (HMA), which I did below,

Both images use your ma avg types and lengths.
The upper uses a trend arrow and coloring
The lower uses your regular settings.
All change can be made at the input screen.

Screenshot 2024-04-26 130932.png

Code:
#Multiple_MA_Crossover_at_Same_BAR

input mode     = {default cross, trend};
input ma_color = {default trend, defined};
input alerts = yes;
input len1   = 9;
input len2   = 20;
input len3   = 50;
input avg1   = AverageType.HULL;
input avg2   = AverageType.HULL;
input avg3   = AverageType.HULL;
input price1  = close;
input price2  = close;
input price3  = close;
input arrowlineweight = 5;
input malineweight    = 2;

plot ma1 = MovingAverage(avg1, price1, len1);
plot ma2 = MovingAverage(avg2, price2, len2);
plot ma3 = MovingAverage(avg3, price3, len3);

#Trend
def trendup = ma1 > ma1[1] and ma2 > ma2[1] and ma3 > ma3[1];
def trenddn = ma1 < ma1[1] and ma2 < ma2[1] and ma3 < ma3[1];
def cond = if trendup then 1 else if trenddn then -1 else cond[1];

#Arrows
plot up = if mode == mode.cross
then ma1 crosses above ma2 and ma1 crosses above ma3 and ma2 crosses above ma3
else
cond[1] == -1 and cond == 1;
up.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
plot dn = if mode == mode.cross
then  ma1 crosses below ma2 and ma1 crosses below ma3 and ma2 crosses below ma3
else
cond[1] == 1 and cond == -1;
dn.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);

#Alerts
Alert(alerts and (up or dn), if up then "UP" else "DN", Alert.BAR, Sound.Ding);

#Colors
DefineGlobalColor("1", Color.CYAN);
DefineGlobalColor("2", Color.PINK);
DefineGlobalColor("3", Color.ORANGE);
DefineGlobalColor("U", Color.GREEN);
DefineGlobalColor("D", Color.RED);

ma1.AssignValueColor(if ma_color == ma_color.trend then if ma1 > ma1[1] then GlobalColor("U") else GlobalColor("D") else GlobalColor("1"));
ma2.AssignValueColor(if ma_color == ma_color.trend then if ma2 > ma2[1] then GlobalColor("U") else GlobalColor("D") else GlobalColor("2"));
ma3.AssignValueColor(if ma_color == ma_color.trend then if ma3 > ma3[1] then GlobalColor("U") else GlobalColor("D") else GlobalColor("3"));

ma1.SetLineWeight(malineweight);
ma2.SetLineWeight(malineweight);
ma3.SetLineWeight(malineweight);

up.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
dn.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
up.AssignValueColor(GlobalColor("U"));
dn.AssignValueColor(GlobalColor("D"));
up.SetLineWeight(arrowlineweight);
dn.SetLineWeight(arrowlineweight);

#
 
Some requested a different type of moving average (HMA), which I did below,

Both images use your ma avg types and lengths.
The upper uses a trend arrow and coloring
The lower uses your regular settings.
All change can be made at the input screen.
Thanks @SleepyZ! This is awesome!

Sad that there isn’t too much information on HMA for an indicator like this. But I do love it for the other averages. Is there anyway to switch the arrows into a white circle?
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
380 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