Stacked Moving Averages For ThinkOrSwim

is there a way to get an arrow on mobile when 3 ema's are stacked correctly?

Here ya go:
Ruby:
def stackedUp = Average(close,10) is greater than Average(close,20)
and Average(close,20) is greater than Average(close,50);

def stackedDn = Average(close,10) is less than Average(close,20)
and Average(close,20) is less than Average(close,50);



AddLabel(yes, " Stacked ",
    if stackedUp then Color.GREEN else if stackedDn then Color.RED else Color.GRAY);
what is the code to scan when this occurs?
 
Last edited by a moderator:

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

is there a way to get an arrow on mobile when 3 ema's are stacked correctly?


what is the code to scan when this occurs?
This version can be used for mobile and scanner.
To reference a study in the scanner:
https://usethinkscript.com/threads/how-to-use-thinkorswim-stock-hacker-scans.284/
Ruby:
def stackedUp = Average(close,10) is greater than Average(close,20)
and Average(close,20) is greater than Average(close,50);

def stackedDn = Average(close,10) is less than Average(close,20)
and Average(close,20) is less than Average(close,50);



plot ArrowUP = stackedUP ;
ArrowUP.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
ArrowUP.SetDefaultColor(color.cyan) ;
ArrowUP.SetLineWeight(1);

plot ArrowDN = stackedDN;
ArrowDN.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
ArrowDN.SetDefaultColor(color.magenta) ;
ArrowDN.SetLineWeight(1);
hXqTSvj.png
 
is there a way to get an arrow on mobile when 3 ema's are stacked correctly?


what is the code to scan when this occurs?
i'm getting an error that no label so I deleted that but it says at least one plot needs to be defined.
what im trying to accomplish is an alert when they are stacked, I thought if I did it as a scan it would alert when it happened in my scan.
 
i'm getting an error that no label so I deleted that but it says at least one plot needs to be defined.
what im trying to accomplish is an alert when they are stacked, I thought if I did it as a scan it would alert when it happened in my scan.
Actually there are two plots defined in the above script so your error is not possible.
And as you can see it works in the above image just fine with no errors.
And there is no label, so there can be no label error message.

Maybe the problem lies with your cutting and pasting of the above script into a new study?
https://usethinkscript.com/threads/how-to-import-existing-thinkscript-code-on-thinkorswim.10/
or
You didn't follow these instructions when setting up your scan?
https://usethinkscript.com/threads/how-to-use-thinkorswim-stock-hacker-scans.284/

For Alerts:
There are scanned watchlist alerts which alert whenever the results of the scan changes.
These alerts can be 3min delayed. They can have custom sounds, they can be sent to phone/email, if you have notifications turned on in the app setup.
https://tlc.thinkorswim.com/center/howToTos/thinkManual/Scan/Stock-Hacker#:~:text=Scan results are,scan results change…
 
Last edited:
Actually there are two plots defined in the above script so your error is not possible.
And as you can see it works in the above image just fine with no errors.
And there is no label, so there can be no label error message.

Maybe the problem lies with your cutting and pasting of the above script into a new study?
https://usethinkscript.com/threads/how-to-import-existing-thinkscript-code-on-thinkorswim.10/
or
You didn't follow these instructions when setting up your scan?
https://usethinkscript.com/threads/how-to-use-thinkorswim-stock-hacker-scans.284/

For Alerts:
There are scanned watchlist alerts which alert whenever the results of the scan changes.
These alerts can be 3min delayed. They can have custom sounds, they can be sent to phone/email, if you have notifications turned on in the app setup.
https://tlc.thinkorswim.com/center/howToTos/thinkManual/Scan/Stock-Hacker#:~:text=Scan results are,scan results change…
Thank you!!
 
Hi . I use this bullish stacked EMA scan code.
I'd like to scan also for bearish stacked EMA.
Can someone please edit the code ? Thanks !

MovAvgExponential("length" = 8)."AvgExp" is greater than MovAvgExponential("length" = 21)."AvgExp" and MovAvgExponential("length" = 21)."AvgExp" > MovAvgExponential("length" = 34)."AvgExp" and MovAvgExponential("length" = 34)."AvgExp" > MovAvgExponential("length" = 55)."AvgExp" and MovAvgExponential("length" = 55)."AvgExp" > MovAvgExponential("length" = 89)."AvgExp"


Or what would you use instead ?
 
Last edited by a moderator:
Hi . I use this bullish stacked EMA scan code.
I'd like to scan also for bearish stacked EMA.
Can someone please edit the code ? Thanks !

MovAvgExponential("length" = 8)."AvgExp" is greater than MovAvgExponential("length" = 21)."AvgExp" and MovAvgExponential("length" = 21)."AvgExp" > MovAvgExponential("length" = 34)."AvgExp" and MovAvgExponential("length" = 34)."AvgExp" > MovAvgExponential("length" = 55)."AvgExp" and MovAvgExponential("length" = 55)."AvgExp" > MovAvgExponential("length" = 89)."AvgExp"

To change from bullish to bearish; change the 'greater than' signs to 'less than' signs.

I am not sure that this script provides any significant value. No, I have no other suggestions.
I have never seen any research or articles that stacked bearish EMA's provide a good exit point or a good place to short.

But you should do what works for you,
Come back if you find this useful and explain how.

MovAvgExponential("length" = 8)."AvgExp" is less than MovAvgExponential("length" = 21)."AvgExp" and MovAvgExponential("length" = 21)."AvgExp" < MovAvgExponential("length" = 34)."AvgExp" and MovAvgExponential("length" = 34)."AvgExp" < MovAvgExponential("length" = 55)."AvgExp" and MovAvgExponential("length" = 55)."AvgExp" < MovAvgExponential("length" = 89)."AvgExp"
 
Last edited:
Here is my EMA_Stack... Watch it and see if it will get you most of the way to where you want to be...
Ruby:
def stackedUp = MovAvgExponential("length" = 8)."AvgExp" is greater than MovAvgExponential("length" = 21)."AvgExp"
and MovAvgExponential("length" = 21)."AvgExp" is greater than MovAvgExponential("length" = 34)."AvgExp"
and MovAvgExponential("length" = 34)."AvgExp" is greater than MovAvgExponential("length" = 55)."AvgExp"
and MovAvgExponential("length" = 55)."AvgExp" is greater than MovAvgExponential("length" = 89)."AvgExp";


def stackedDn = MovAvgExponential("length" = 8)."AvgExp" is less than MovAvgExponential("length" = 21)."AvgExp"
and MovAvgExponential("length" = 21)."AvgExp" is less than MovAvgExponential("length" = 34)."AvgExp"
and MovAvgExponential("length" = 34)."AvgExp" is less than MovAvgExponential("length" = 55)."AvgExp"
and MovAvgExponential("length" = 55)."AvgExp" is less than MovAvgExponential("length" = 89)."AvgExp";


AddLabel(yes, " Stacked ", if stackedUp then Color.GREEN else if stackedDn then Color.RED else Color.GRAY);
TOS says @ 13:1 AddLabel is not useable in this context
 
Last edited by a moderator:
I am trying to get a label to show me when the 8, 21, 34, 55 and 89 EMAs are all stacked (turns green) . Does anyone have this code or setup ?
Thank you in advance
 
@BenTen i posted the image earlier

can you help arrange this into one code (EMA 200, EMA 50, EMA 21, EMA 9) + VWAP to only alert when >3, 4 or 5 are in sync.
 
Last edited by a moderator:
I am trying to get a label to show me when the 8, 21, 34, 55 and 89 EMAs are all stacked (turns green) . Does anyone have this code or setup ?
Thank you in advance
I think this code will give what you want, and it supplies a label:

# TOS Stacked EMA 8,21,34,55,89

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 AND exp21>exp34 AND exp34>exp55 AND exp34>exp55 AND exp55>exp89;

Eup.hide();

# Add label for Eup
AddLabel(yes, if Eup then "EMAs 8-21-34-55-89 Stacked" else "EMAs 8-21-34-55-89 Not Stacked",
if Eup then Color.GREEN else color.RED );
 
on the time frame you are currently viewing?

I am trying to get a label to show me when the 8, 21, 34, 55 and 89 EMAs are all stacked (turns green) . Does anyone have this code or setup ?
Thank you in advance
declare upper;

input useCustomTimeframe = no; # Toggle between current and custom timeframe
input customTimeframe = AggregationPeriod.DAY; # Set custom timeframe

def agg = if useCustomTimeframe then customTimeframe else GetAggregationPeriod();

def ema8 = ExpAverage(close(period = agg), 8);
def ema21 = ExpAverage(close(period = agg), 21);
def ema34 = ExpAverage(close(period = agg), 34);
def ema55 = ExpAverage(close(period = agg), 55);
def ema89 = ExpAverage(close(period = agg), 89);

def stacked = (ema8 > ema21 and ema21 > ema34 and ema34 > ema55 and ema55 > ema89) or
(ema8 < ema21 and ema21 < ema34 and ema34 < ema55 and ema55 < ema89);

AddLabel(1,
if stacked then "EMAs Stacked" else "EMAs Not Stacked",
if stacked then Color.GREEN else Color.RED);

this should do it, you can set it to evaluate whichever timeframe/chart you are currently viewing OR, set it to scan just a particular time frame no matter what you are looking at
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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