Moving Average Stacked Label


Category:
0
0

I’m working on adding multiple labels (with or w/o plots) but I want the label itself to say Stacked and turn green if the moving averages are stacked or red if they are not stacked. I’m using 10EMA, 21EMA, 50SMA, 200 SMA. By stacked, I mean the price is above the 10EMA, 21EMA, 50SMA, 200SMA. If price is below any one of those it should be RED. So here’s my current code for the moving averages but I’m struggling with the label and read through all of the other post and still confused.  Thanks in advance!

defineGlobalColor(“EMA10”, color.yellow);
defineGlobalColor(“EMA21”, color.white);
defineGlobalColor(“SMA50”, color.magenta);
defineGlobalColor(“SMA200”, color.cyan);

def sma200 = simpleMovingAvg(close,200);
def sma50 = simpleMovingAvg (close,50);
def ema21 = expAverage(close,21);
def ema10 = expAverage(close,8);
def price = close;

plot EMA10_ = ExpAverage(close,10);
plot EMA21_ = ExpAverage(close,21);
plot SMA50_ = simpleMovingAvg (close,50);
plot SMA200_ = simpleMovingAvg (close,200);

AddLabel(sma200,sma50, ema21, ema10″Stacked: ” ) , (if SMA200 < SMA50 <EMA21 < EMA10 < price then Color.GREEN else Color.Red));

RESOLVED
Marked as spam
Posted by (Questions: 21, Answers: 47)
Asked on April 7, 2019 2:45 pm
3177 views
0
Private answer

I believe I have it fixed with labels:

input length1 = 10;
input length2 = 21;
input length3 = 50;
input length4 =200;
input displace = 0;

def sma200 = SimpleMovingAvg(close, 200);
def sma50 = SimpleMovingAvg (close, 50);
def ema21 = ExpAverage(close, 21);
def ema10 = ExpAverage(close, 10);
def price = close;

plot EMA10_ = ExpAverage(close, 10);
plot EMA21_ = ExpAverage(close, 21);
plot SMA50_ = SimpleMovingAvg (close, 50);
plot SMA200_ = SimpleMovingAvg (close, 200);

AddLabel(close, ”Stacked MAs” , (if price > sma200 and price > sma50 and price > ema21 and price > ema10 then Color.GREEN else Color.RED));

#EMA LABEL 1
def EMA1 = ExpAverage(price[-displace], length1);
def EMA2 = ExpAverage(price[-displace], length2);
AddLabel(EMA1, length1 + “EMA: ” + ExpAverage(price, length1), (if EMA1 < price then Color.CYAN else Color.RED));

#EMA LABEL 2
AddLabel(EMA2, length2 + “EMA: ” + ExpAverage(price, length2), (if EMA2 < price then Color.DARK_RED else Color.RED));

#SMA LABEL 1
def SMA1 = Average(price, length3);
def SMA2 = Average(price, length4);

AddLabel(SMA1, length3 + “SMA: ” + Average(price, length3) , (if SMA1 < price then Color.WHITE else Color.RED));

#SMA LABEL 2
AddLabel(SMA2, length4 + “SMA: ” + Average(price, length4) , (if SMA2 < price then Color.YELLOW else Color.RED));

Attachments:
Marked as spam
Posted by (Questions: 21, Answers: 47)
Answered on April 16, 2019 8:53 pm
0
Any way to get this as a WL column script instead?
( at February 28, 2021 3:24 am)