 # Stacked Moving Averages

#### SmellyCat

##### New member
VIP
This is a simple plot on a lower study showing the color condition of short term EMAs.
However, I do not know the code to keep it from plotting cyan dots into the expansion area.
Can someone correct it for me?

###
Code:
``````declare lower;
def EMA5 = ExpAverage(close, 5);
def EMA8 = ExpAverage(close, 8);
def EMA13 = ExpAverage(close, 13);
def cond1 = (EMA5 > EMA8) and (EMA8 > EMA13);
def cond2 = (EMA5 < EMA8) and (EMA8 < EMA13);

plot dot = 1;
dot.SetStyle(Curve.POINTS);
dot.SetLineWeight(5);
dot.AssignValueColor(if cond1 then Color.GREEN
else if cond2 then Color.RED
else color.YELLOW);``````

Last edited by a moderator:

#### generic

##### Active member
@SmellyCat Replace the plot line.
Code:
``plot dot = if IsNaN(close) then Double.NaN else 1;``

#### Branch

##### Member
VIP
Can someone help me with making this code into a label? The text on the label can be the number 5. The label should turn colors base on the criteria below.

input price = close;

AddLabel (yes, if ma5 >= ma5 and ma5>ma100
then color.Green else if ma5 < ma5 and ma5>ma100
then color.Blue else if ma5<= ma5 and ma5 <ma100
then color.red else if ma5 >= ma5 and ma5 < ma100
then color.Blue else color.gray);

##### Well-known member
VIP
@Branch Something like this...??? You were very close... Note that I didn't verify your logic...

Ruby:
``````def ma5 = Average(close, 5);
def ma100 = Average(close, 100);

if ma5 >= ma5 and ma5 > ma100 then Color.GREEN
else if ma5 < ma5 and ma5 > ma100 then Color.BLUE
else if ma5 <= ma5 and ma5 < ma100 then Color.RED
else if ma5 >= ma5 and ma5 < ma100 then Color.BLUE
else Color.GRAY
);``````

• Branch

#### Optionzilla

##### New member
Hello I came across this watch list indicator on YouTube. I was wondering if some one could help me code it to fit my tradeing style I use the EMA 13 and 20 Ema 65 and 100SMA. But I primarily us the the crossing of the 13 and the 20 to enter trades when the stock is below the 13 and the 20 am short and when above the 13 and 20 am long

Below is the video am referring to along with the code

Code: def EMA8 = ExpAverage(close, 8); def EMA13 = ExpAverage(close, 13); def EMA21 = ExpAverage(close, 21); def EMA34 = ExpAverage(close, 34); def bullish = EMA8 > EMA13 and EMA13 > EMA21 and EMA21 > EMA34; def bearish = EMA8 < EMA13 and EMA13 < EMA21 and EMA21 < EMA34; ADDlabel(bullish, "Bullish", color.black); ADDlabel(bearish, "Bearish", color.black); ADDlabel(!bullish and!bearish, "", color.black); AssignBackgroundColor (if bullish then color.green else if bearish then color.red else color.black);
Show less

My chart 20ema purple 13ema white 65ema blue 100sma red Last edited:

#### M1keG

##### New member
New to the forum, I'm looking to implement a scan to filter only instruments where the moving averages are above each other, meaning 20EMA>40EMA>50SMA... (uptrend) and use in ToS to create scans in different timeframes, 1D, 1W, 1M.....

Appreciate if someone can point me in the right direction, perhaps a similar script original script already exists and I can adapt ?....not an expert by any means but I can handle modifications

thanks!

#### SleepyZ

##### Well-known member
New to the forum, I'm looking to implement a scan to filter only instruments where the moving averages are above each other, meaning 20EMA>40EMA>50SMA... (uptrend) and use in ToS to create scans in different timeframes, 1D, 1W, 1M.....

Appreciate if someone can point me in the right direction, perhaps a similar script original script already exists and I can adapt ?....not an expert by any means but I can handle modifications

thanks!
This should help
Ruby:
``````def ema20 = ExpAverage(close, 20);
def ema40 = ExpAverage(close, 40);
def sma50 = SimpleMovingAvg(close, 50);
plot scan = ema20 > ema40 and ema40 > sma50;``````

• M1keG

#### M1keG

##### New member
Thanks, found out the ToS stock hacker/condition wizard allows building "stacked" filters...this filters securities with all classic moving averages aligned on top of each other...

the GUI

the code
MovAvgExponential("length" = 20)."AvgExp" is greater than or equal to MovAvgExponential("length" = 40)."AvgExp" and MovAvgExponential("length" = 40)."AvgExp" is greater than or equal to SimpleMovingAvg("length" = 50)."SMA" and SimpleMovingAvg("length" = 50)."SMA" is greater than or equal to SimpleMovingAvg("length" = 100)."SMA" and SimpleMovingAvg("length" = 100)."SMA" is greater than or equal to SimpleMovingAvg("length" = 150)."SMA" and SimpleMovingAvg("length" = 150)."SMA" is greater than or equal to SimpleMovingAvg("length" = 200)."SMA"