Stacked Moving Averages

Partner

New member
VIP
Can anyone help to create a script to identify the ticker when stacking of VWAP, 200 SMA, 9 EMA, 21 SMA, 34 EMA & 89 EMA are together - Timeframe 3 mins. (Pls note, we already have the script in the forum when 8EMA>21EMA>34EMA>55EMA>89EMA. However, looking for a script when they are merged together irrespective of the order). What I have observed when they merged together we normally see a big move in a ticker on either side. Below are two examples from Friday, 4th Dec.

And if possible to add - if the price is above VWAP the signal turns to Green and if the price is below VWAP the signal turns to Red.

Hw9WuEh.png
JcXP7Fu.png
 
Last edited:
  • Like
Reactions: Koa

rad14733

Well-known member
VIP
@Partner I think you'll find that if you are going to get a big move that the averages will be properly stacked in order... I have been running an EMA Stack for a week or two and virtually all major moves have stacked MA's... Let's not complicate things needlessly...

Here is my EMA_Stack... Watch it and see if it will get you most of the way to where you want to be... The only thing I want to add is to know when the averages are squeezed/converged but I'm running my TTM_Squeeze_Clouds for that presently...

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);

8|21|34|55|89 EMA Stack

ReGNbia.jpg
 
Last edited:

Shrum

Member
@rad14733 I added the above code and all I get to display is a stacked label at the top, nothing else? any ideas why it doesn't look like your screenshot?
 

rad14733

Well-known member
VIP
@rad14733 I added the above code and all I get to display is a stacked label at the top, nothing else? any ideas why it doesn't look like your screenshot?
Ha...!!! That's because all I posted was the code to produce a Stacked Chart Label, not the EMA's themselves... If that's what you're looking for I can post the code but presently I use three Studies to get the five EMA's... I had been just running the three but added two more EMA's the other day just to see how they all worked together...
 

Shrum

Member
Ha...!!! That's because all I posted was the code to produce a Stacked Chart Label, not the EMA's themselves... If that's what you're looking for I can post the code but presently I use three Studies to get the five EMA's... I had been just running the three but added two more EMA's the other day just to see how they all worked together...
So you don’t have the arrow plotting automatically? Thanks for the reply
 

rad14733

Well-known member
VIP
So you don’t have the arrow plotting automatically? Thanks for the reply
The arrows actually come from two copies of the TOS MovAvgCrossover Study... I am currently experimenting and testing which is why it takes a total of five Studies, my 3-EMA, two MovAvgCrossover's, a 34 EMA, and an 89 EMA... I haven't combined everything together as yet... This is a prime example of me not getting my own coding done due to working on code for members here... :confused:
 

rad14733

Well-known member
VIP
Can the script also me modified to display StackUp and StackDown watchlist display column?

Here is my actual Watchlist Column code... It's almost identical to the code above... I just use colors without text because I need the screen real estate for other things... Green = StackedUp, Red = StackedDown, Gray = NotStacked...

Ruby:
#EMA_Stack
#Used to indicate that 8, 21, 34, 55, 89  EMA's are ALL stacked trend-wise
#Created by rad14733 for usethinkscript.com
#v1.0 2021-01-02

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";

def state = if stackedUp then 1 else if stackedDn then -1 else 0;

AddLabel(yes, state, if stackedUp then Color.DARK_GREEN else if stackedDn then Color.DARK_RED else Color.DARK_GRAY);

AssignBackgroundColor(if stackedUp then Color.DARK_GREEN else if stackedDn then Color.DARK_RED else Color.DARK_GRAY);
 

ssagar1212

New member
#12 look there, try to create a column, using that format with the MA_Cloud???
Yes that was fabulous with Stacked as the warchlist text..thank you so much..was wondering whether columns could display the ema info as well? It may be too complex?
 

petech

Member
VIP
I don't know how to scan in TOS for the following condition...
On the 5 mins chart, I want to know when the 3,9,20,50 simple moving average are all bunched together.
Please see this image for a reference. I've highlighted the area where they are all bunched together.

ZvqwaAu.jpg


Thank you in advance
 

Prison Mike

Member
Im sure you will want to create another scan in the future. What a good project to learn on!

Condition wizard can be used to find the cross of these MA within 2 bars.
 
Last edited:

petech

Member
VIP
I got as far as pulling up the MovingAvgCrossover, in the scan section pressing the pencil button, then press the edit button. I looked through all the available options and can't figure it out. You talked about finding the cross of these MA within 2 bars. I couldn't find a way in that menu I was looking through to specify 2 bars.
 

XeoNoX

Well-known member
VIP
you can to code it like this:
the 3,9,20,50 simple moving average are within XYZ percent of each other


the code for MA1 is within XYZ percent of MA2 is on the forum somewhere. From that you can just add to custom code in the TOS scanner and make a scan for each pair crossing till you covered all 9 Possibilities. (i think its 9, could be more)
 
Last edited:

Similar threads

Top