Moving average stacked as label

RBO

New member
VIP
Trying exp moving average trend to show as label.. but it is not showing any.. and also , if the condition not met how to show the label as " No Signal " Any help

Code:
def exp8 = reference movAvgExponential(length=8);
def exp21 = reference movAvgExponential(length=21);
def exp34 = reference movAvgExponential(length=34);
def exp55 = reference movAvgExponential(length=55);
def exp89 = reference movAvgExponential(length=89);
def exp100 = reference movAvgExponential(length=100);
def exp200 = reference movAvgExponential(length=200);

def Eup  =exp8>exp21>exp34>exp55>exp89>exp100>exp100>exp200  ;

# Add label for Eup
AddLabel(Eup, "E Up", Color.GREEN);
 

MerryDay

Moderator
Staff member
VIP
@Rambo
Here is the scanner
Code:
# TOS Stacked EMA

def exp8 = reference movAvgExponential(length=8);
def exp21 = reference movAvgExponential(length=21);
def exp34 = reference movAvgExponential(length=34);
def exp55 = reference movAvgExponential(length=55);
def exp89 = reference movAvgExponential(length=89);
def exp100 = reference movAvgExponential(length=100);
def exp200 = reference movAvgExponential(length=200);

plot Eup =exp8>exp21>exp34>exp55>exp89>exp100>exp100>exp200 ;
Eup.hide();

# Add label for Eup
AddLabel(yes, if Eup then "E Up" else "No Signal",
              if Eup then Color.GREEN else color.RED );

But no stocks matched your criteria

 
Last edited:

RBO

New member
VIP
@MerryDay

Code:
#Rambo Exp Moving average Stack
def exp8 = reference movAvgExponential(length=8);
def exp21 = reference movAvgExponential(length=21);
def exp34 = reference movAvgExponential(length=34);
def exp55 = reference movAvgExponential(length=55);
def exp89 = reference movAvgExponential(length=89);
def exp100 = reference movAvgExponential(length=100);
def exp200 = reference movAvgExponential(length=200);

def Eup  =exp8>exp21 && exp34 > exp55 && exp89 > exp100;

# Add label for Eup
AddLabel(yes, if Eup then "E Up" else "No Signal", if Eup then Color.GREEN else Color.RED);

I did the above , getting results - is this right ?
 

MerryDay

Moderator
Staff member
VIP
@Rambo
You can't scan w/o a plot definition.

Code:
#your code:
def Eup =exp8>exp21>exp34>exp55>exp89>exp100>exp100>exp200 ;

#change your code, to this to scan:
plot Eup =exp8>exp21>exp34>exp55>exp89>exp100>exp100>exp200 ;
Eup.hide();
Maybe by scanning different aggregations, you will have better luck than me.
Come back and let us know
 
Last edited:

andre.muhammad

Member
VIP
@MerryDay Hi, I have absolutely no coding abilities, but I was wondering if there was a way for green/red labels to indicate a 15 SMA over a 30 SMA for 1 min, 2 min, 5 min, 8 min, and 10min. (I was hoping that green color would indicate 15 SMA over 30 SMA was true and red would indicate the opposite). Is this at all possible?
 

MerryDay

Moderator
Staff member
VIP
@andre.muhammad

Your use of TOS will be greatly enhanced by picking up some rudimentary searching and coding skills. There is a fountain of expertise that has been shared on this forum, by searching through it; it has answered questions that I didn't even know to ask.

A search of the forum for MTF (multi-time frame) MA labels yielded many results. I believe this script by @Pensar could be modified to do what you want. https://usethinkscript.com/threads/ema-multi-timeframe-chart-label.1483/#post-31448

Change the aggregations to what you want. To find what aggregation periods are available and the syntax required: https://tlc.thinkorswim.com/center/reference/thinkScript/Constants/AggregationPeriod

There is no 8min agg available.

As you see what @Rambo did, make your attempt at setting up what you want, come back w/ any questions you may have.
HTH
 
Last edited:

andre.muhammad

Member
VIP
@MerryDay I followed the example and the labels did not appear... Thank you, but unfortunately, it did not work.

Code:
def c1 = close(period = aggregationperiod.min);
def c2 = close(period = aggregationperiod.two_min);
def c3 = close(period = aggregationperiod.five_min);
def c4 = close(period = aggregationperiod.ten_min);
def c5 = close(period = aggregationperiod.thirty_min);

def avg1 = average(c1,20);
def avg2 = average(c2,20);
def avg3 = average(c3,20);
def avg4 = average(c4,20);
def avg5 = average(c5,20);

addlabel(1, if close > avg1 then "1 min above 20 SMA" else "1 min below 20 SMA",
         if close > avg1 then color.green else color.red);
addlabel(1, if close > avg2 then "2 min above 20 SMA" else "5 min below 20 SMA",
         if close > avg2 then color.green else color.red);
addlabel(1, if close > avg3 then "5 min above 20 SMA" else "15 min below 20 SMA",
         if close > avg3 then color.green else color.red);
addlabel(1, if close > avg3 then "10 min above 20 SMA" else "15 min below 20 SMA",
         if close > avg3 then color.green else color.red);
addlabel(1, if close > avg3 then "30 min above 20 SMA" else "15 min below 20 SMA",
         if close > avg3 then color.green else color.red);
 

MerryDay

Moderator
Staff member
VIP
@andre.muhammad
You sell yourself short! You did that fast and well!
What aggregation is the chart upon which you are putting your labels?
You can only reference HIGHER aggregations, but not a lower aggregation than the chart you’re on.
So if you are on a 15min chart, you can only have labels for aggregations greater than 15min.
HTH
 

Baller2356

New member
Code:
def exp8 = reference movAvgExponential(length=8);
def exp21 = reference movAvgExponential(length=21);
def exp34 = reference movAvgExponential(length=34);
def exp55 = reference movAvgExponential(length=55);
def exp89 = reference movAvgExponential(length=89);


plot Eup = exp8>exp21>exp34>exp55>exp89 ;
Eup.hide();

# Add label for Eup
AddLabel(yes, if Eup then "E Up" else "No Signal",
              if Eup then color.GREEN else color.RED );

Here's my code. This isn't working. I would appreciate any help!
 

MerryDay

Moderator
Staff member
VIP
@Baller2356 This post probably belongs here.

Technically, your code does work.

1eE9YmG.png


This isn't a syntax issue. It's a logic issue.

Your criteria currently is only currently true for 100 stocks all under the value of $1

aaHmIJD.png
 
Last edited by a moderator:

MerryDay

Moderator
Staff member
VIP
@Baller2356 Tonight seems to be a night for vague questions. What would you like fixed?
The penny stocks met the conditions. If I had to guess, I would say that they don't have anywhere to fall or rise to, so they fit your parameters.
You need to change your logic.

Perhaps you should try loading the Madrid Ribbons on your charts, review which stacked averages best represent the strategy you are attempting to create. Your current stack doesn't work.
 

MerryDay

Moderator
Staff member
VIP
@Baller2356

I did a google search for ema 8 21 34 55 89 as this has been a request that has appeared before which doesn't make sense as exp8>exp21>exp34>exp55>exp89 never works.

My search revealed there are several websites that suggest that these averages when plotted on a graph make a good trend indicator.
HOWEVER, they do not suggest that they have to be greater than each other which is the basis of this code. Just that they should all be plotted on a chart and their direction is indicative. In fact, they discuss the meaning of when they cross so that implies that at times they are less than each other.

So I am thinking the problem with this logic is the assumption that they all have to be greater than the next.
HTH
 

Similar threads

Top