plot the avg of 3 moving averages

AverageMishka

New member
Hi,

I'm looking to plot the avg of 3 moving averages and the other 2 moving averages instead of having them as 5 separate lines.


Screenshot-2021-10-29-153441.png



Code:
declare lower;

input length1 = 8.0;
input length2 = 24.0;
input length3 = 50.0;
input length4 = 113.0;
input length5 = 200.0;
input displace = 0;


input averageTypeE = AverageType.EXPONENTIAL;
input averageTypeW = AverageType.EXPONENTIAL;

def ema8 = ExpAverage(close, 8);
def ema24 = ExpAverage(close, 24);
def wma50 = WMA(close, 50);
def ema113 = ExpAverage(close, 113);
def wma200 = WMA(close, 200);
def price = close;


plot EMA8_ = ExpAverage(close, 8);
plot EMA24_ = ExpAverage(close, 24);
plot WMA50_ = WMA(close, 50);
plot EMA113_ = ExpAverage (close, 113);
plot WMA200_ = WMA(close, 200);

AddLabel(close, ”Stacked AVGs(CALLS)” , (if wma200 and price > ema113 and price > wma50 and price > ema24 and price > ema8 then Color.GREEN else Color.GRAY));

AddLabel(close, ”Stacked AVGs(PUTS)” , (if wma200 and price < ema113 and price < wma50 and price < ema24 and price < ema8 then Color.GREEN else Color.GRAY));


AddChartBubble(EMA8_ and EMA24_ and WMA50_ crosses above WMA200_ and EMA113_, close, "GO", Color.PINK);

AddChartBubble(EMA8_ crosses above WMA200_ and EMA113_, close, "9 Cross", Color.DARK_GREEN);

AddChartBubble(EMA24_ crosses above WMA200_ and EMA113_, close, "21 Cross", Color.LIGHT_GREEN);

AddChartBubble(WMA50_ crosses above WMA200_ and EMA113_, close, "50 Cross", Color.GREEN);

AddChartBubble(EMA8_ crosses below WMA200_ and EMA113_, close, "9 Cross", Color.DARK_RED);

AddChartBubble(EMA24_ crosses below WMA200_ and EMA113_, close, "21 Cross", Color.LIGHT_RED);

AddChartBubble(WMA50_ crosses below WMA200_ and EMA113_, close, "50 Cross", Color.RED);

AddChartBubble(EMA8_ and EMA24_ and WMA50_ crosses below WMA200_ and EMA113_, close, "BYE", Color.BLUE);
 
Solution
Hi,

I'm looking to plot the avg of 3 moving averages and the other 2 moving averages instead of having them as 5 separate lines.


View attachment 2697


Code:
declare lower;

input length1 = 8.0;
input length2 = 24.0;
input length3 = 50.0;
input length4 = 113.0;
input length5 = 200.0;
input displace = 0;


input averageTypeE = AverageType.EXPONENTIAL;
input averageTypeW = AverageType.EXPONENTIAL;

def ema8 = ExpAverage(close, 8);
def ema24 = ExpAverage(close, 24);
def wma50 = WMA(close, 50);
def ema113 = ExpAverage(close, 113);
def wma200 = WMA(close, 200);
def price = close;


plot EMA8_ = ExpAverage(close, 8);
plot EMA24_ = ExpAverage(close, 24);
plot WMA50_ = WMA(close, 50);
plot EMA113_ = ExpAverage (close, 113);
plot WMA200_ = WMA(close...
Hi,

I'm looking to plot the avg of 3 moving averages and the other 2 moving averages instead of having them as 5 separate lines.


View attachment 2697


Code:
declare lower;

input length1 = 8.0;
input length2 = 24.0;
input length3 = 50.0;
input length4 = 113.0;
input length5 = 200.0;
input displace = 0;


input averageTypeE = AverageType.EXPONENTIAL;
input averageTypeW = AverageType.EXPONENTIAL;

def ema8 = ExpAverage(close, 8);
def ema24 = ExpAverage(close, 24);
def wma50 = WMA(close, 50);
def ema113 = ExpAverage(close, 113);
def wma200 = WMA(close, 200);
def price = close;


plot EMA8_ = ExpAverage(close, 8);
plot EMA24_ = ExpAverage(close, 24);
plot WMA50_ = WMA(close, 50);
plot EMA113_ = ExpAverage (close, 113);
plot WMA200_ = WMA(close, 200);

AddLabel(close, ”Stacked AVGs(CALLS)” , (if wma200 and price > ema113 and price > wma50 and price > ema24 and price > ema8 then Color.GREEN else Color.GRAY));

AddLabel(close, ”Stacked AVGs(PUTS)” , (if wma200 and price < ema113 and price < wma50 and price < ema24 and price < ema8 then Color.GREEN else Color.GRAY));


AddChartBubble(EMA8_ and EMA24_ and WMA50_ crosses above WMA200_ and EMA113_, close, "GO", Color.PINK);

AddChartBubble(EMA8_ crosses above WMA200_ and EMA113_, close, "9 Cross", Color.DARK_GREEN);

AddChartBubble(EMA24_ crosses above WMA200_ and EMA113_, close, "21 Cross", Color.LIGHT_GREEN);

AddChartBubble(WMA50_ crosses above WMA200_ and EMA113_, close, "50 Cross", Color.GREEN);

AddChartBubble(EMA8_ crosses below WMA200_ and EMA113_, close, "9 Cross", Color.DARK_RED);

AddChartBubble(EMA24_ crosses below WMA200_ and EMA113_, close, "21 Cross", Color.LIGHT_RED);

AddChartBubble(WMA50_ crosses below WMA200_ and EMA113_, close, "50 Cross", Color.RED);

AddChartBubble(EMA8_ and EMA24_ and WMA50_ crosses below WMA200_ and EMA113_, close, "BYE", Color.BLUE);

1752933871285.png

Code:
# Multi-MA Average Indicator - Corrected for Smooth Plot
# Adapted by antwerks - 07/2025

declare upper;

# Inputs
input maTypeStr = {"SMA", default "EMA", "WMA", "Wilders", "Hull"}; # Use string input with options
input price = close;
input length1 = 9;
input length2 = 21;
input length3 = 34;
input length4 = 50;
input length5 = 100;

# === Function to return MA based on selected type ===
script getMA {
    input maTypeStr = "EMA"; # String input
    input price = close;
    input length = 20;
    def result = if maTypeStr == "SMA" then Average(price, length)
                 else if maTypeStr == "EMA" then ExpAverage(price, length)
                 else if maTypeStr == "WMA" then WMA(price, length)
                 else if maTypeStr == "Wilders" then WildersAverage(price, length)
                 else if maTypeStr == "Hull" then HullMovingAvg(price, length)
                 else price; # Default to price if unmatched
    plot out = result;
}

# === Calculate Each MA ===
def ma1 = getMA(maTypeStr, price, length1);
def ma2 = getMA(maTypeStr, price, length2);
def ma3 = getMA(maTypeStr, price, length3);
def ma4 = getMA(maTypeStr, price, length4);
def ma5 = getMA(maTypeStr, price, length5);

# === Plot Average of All 5 MAs ===
plot AvgOfMAs = (ma1 + ma2 + ma3 + ma4 + ma5) / 5;
AvgOfMAs.SetDefaultColor(Color.CYAN);
AvgOfMAs.SetLineWeight(2);
 
Last edited by a moderator:
Solution

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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