Moving Average Crossover Watchlist Column for ThinkorSwim

@BenTen II'd like to take it a step further and can't figure out if I have a study that doesn't have an input but a plot, how to get the same notification in the watchlist if the MovAvgExp is set to 9 and crosses my NQ line on the up swing or down swing. I think using similar code would work, but I'm struggle to understand how to get this concept to work if I don't have an input on one of the studies

drHSNX1.jpg


AnYI0zl.jpg
 

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

crosses my NQ line on the up swing or down swing

What's this "NQ line" that you were referring to? You may want to merge it with the EMA (9) indicator.
 
What's this "NQ line" that you were referring to? You may want to merge it with the EMA (9) indicator.
It's a simple Indicator I got here...

Code:
plot myindicator=ExpAverage(close,20);
myindicator.SetDefaultColor(Color.White);
myindicator.AssignValueColor(if close>=myindicator then Color.Green else Color.Red);
myindicator.SetStyle(curve.LONG_DASH);
myindicator.SetPaintingStrategy(paintingstrategy.LINE_VS_SQUARES);
myindicator.SetLineWeight(5);
myindicator.setHiding(if close>open(period="DAY") then 0 else 1);
 
@NYSmakTalker So you want to get alerted for the 9 and 20 EMA crossovers?
Yeah, dang ultimately that is what it is. Good talking through it.

Now the complex part become for my holdings to define the positive (between the cross above and cross below) to be green vs negative when it actually crosses below that threshold. Is there code already out there I can pull to add to this watch item column?

Really appreciate y'alls help, it's why I wanted to pay for the great service I heard about. Thank you.
 
@NYSmakTalker The code provided on the first page of this thread will do just that. By default, it's using the 10 and 20 EMA. Just modify the code to fit your needs, in this case 9 and 20 EMA.
 
Help. please, I'm trying to load the code from page 1 into the scan function but it won't let me save it. I copied the code into a study and saved it. When I tried to create a scan query using that study, the green "Save" button won't work.
 
@mkalavitz Because for SHAK the next candle was over the current candle . for other 2 tickers next candles are very close and until they move higher or lower (clear signal) the signal will be on and off and that's why it came late.
 
@BenTen Thanks for sharing this amazing script. I am looking to modify it slightly. The script basically identifies a pattern when ema crossover happens in a certain lookback period but what if in the same lookback period the price moves down below one of the ema say 5d ema. That would invalidate the play. Is there anyway that we can identify that if the crossover happened in last 5 bars and the price remained above 5d ema in all those 5 bar?
 
Sure. So if you see the attached screenshot, all EMA crossed over right at the open and stayed the same throughout the next 20/30 candles. With your script, I will be able to identify the crossover in first 5 bars but on the 6th bar the cell will turn back to orange. Is there anyway that
(a) I get a green signal because crossover happened in last 5 bars and price stayed over all key EMA in the lookback period (irrespective of whether the bars were green or red) or just 8d EMA
(b) I get a green signal because crossover already happened because the price is over all key EMA in the lookback period (irrespective of whether the bars were green or red) or just 8d EMA

bcj5WBF.png


Correction point (b). I get a green signal because crossover already happened and the price is over all key EMA in the lookback period (irrespective of whether the bars were green or red) or just 8d EMA
 
@sunny007 For what you described in #1 you would be looking for a "stacked" indicator... I just posted one last week that was for 8, 21, 34, 55, 89 EMA's... It stays Green when stacked Up, Red when stacked Down, otherwise Gray...
 
@sunny007 For what you described in #1 you would be looking for a "stacked" indicator... I just posted one last week that was for 8, 21, 34, 55, 89 EMA's... It stays Green when stacked Up, Red when stacked Down, otherwise Gray...

I cant find the post. You mind directing me to your code ?
 
@sunny007 Sure... Here you go... This code may need work... I have another personal copy with more potential bells and whistles but it isn't ready to be shared here yet...

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);
 
@rad14733 thanks for sharing the code but does this code checks every bar in a lookback period (say 5 candles) to see if ema crossover happened and all key EMAs are above each other?
 
@sunny007 Actually, here is my work-in-progress code... I offer it AS-IS so you'll have to figure out whether you need and changes and make them yourself... As of right now it serves MY needs and that is all I'm concerned with at this point...

Ruby:
#EMA_x5_Stack
#Created by rad14733 for usethinkscript.com
#v1.0 2021-01-02
#NOTE: EMA crossovers can be set to only paint based on long term trends.
#      When configured, EMA crossovers will only paint when filtered by longer term trends (ema1 <> ema5).

# EMA Length's
input ema1Length = 8;
input ema2Length = 21;
input ema3Length = 34;
input ema4Length = 55;
input ema5Length = 89;


# Display EMA's Stacked Label
input show_stacked_label = yes;


# Conditionally Plot EMA's

plot ema1 = ExpAverage(close, ema1Length);
ema1.SetPaintingStrategy(PaintingStrategy.LINE);
ema1.SetStyle(Curve.FIRM);
ema1.SetLineWeight(2);
ema1.SetDefaultColor(Color.GREEN);

plot ema2 = ExpAverage(close, ema2Length);
ema2.SetPaintingStrategy(PaintingStrategy.LINE);
ema2.SetStyle(Curve.FIRM);
ema2.SetLineWeight(2);
ema2.SetDefaultColor(Color.YELLOW);

plot ema3 = ExpAverage(close, ema3Length);
ema3.SetPaintingStrategy(PaintingStrategy.LINE);
ema3.SetStyle(Curve.FIRM);
ema3.SetLineWeight(2);
ema3.SetDefaultColor(Color.RED);

plot ema4 = ExpAverage(close, ema4Length);
ema4.SetPaintingStrategy(PaintingStrategy.LINE);
ema4.SetStyle(Curve.FIRM);
ema4.SetLineWeight(2);
ema4.SetDefaultColor(Color.MAGENTA);

plot ema5 = ExpAverage(close, ema5Length);
ema5.SetPaintingStrategy(PaintingStrategy.LINE);
ema5.SetStyle(Curve.FIRM);
ema5.SetLineWeight(2);
ema5.SetDefaultColor(Color.BLUE);


# Calculate EMA Crossovers
# (Un-)Comment to Enable/Disable EMA corssover trend filtering
#plot x1a2 = plot_ema1 and plot_ema2 and ema1 crosses above ema2 and ema1 > ema5; #Filtered Crossovers
#plot x1a2 = plot_ema1 and plot_ema2 and ema1 crosses above ema2; #Un-Filtered Crossovers
#plot x1a2 = ema1 crosses above ema2 and ema1 > ema5; #Filtered Crossovers
plot x1a2 = ema1 crosses above ema2; #Un-Filtered Crossovers
x1a2.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
x1a2.SetStyle(Curve.FIRM);
x1a2.SetLineWeight(3);
x1a2.SetDefaultColor(Color.YELLOW);

# (Un-)Comment to Enable/Disable EMA corssover trend filtering
#plot x1b2 = plot_ema1 and plot_ema2 and ema1 crosses below ema2 and ema1 < ema5; #Filtered Crossovers
#plot x1b2 = plot_ema1 and plot_ema2 and ema1 crosses below ema2; #Un-Filtered Crossovers
#plot x1b2 = ema1 crosses below ema2 and ema1 < ema5; #Filtered Crossovers
plot x1b2 = ema1 crosses below ema2; #Un-Filtered Crossovers
x1b2.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
x1b2.SetStyle(Curve.FIRM);
x1b2.SetLineWeight(3);
x1b2.SetDefaultColor(Color.DARK_ORANGE);

# Define Global Colors For Clouds

# Crosses Above
DefineGlobalCOlor("x1a2", Color.GREEN);
#DefineGlobalCOlor("x2a3", Color.DARK_GREEN);
#DefineGlobalCOlor("x3a4", Color.YELLOW);
#DefineGlobalCOlor("x4a5", Color.WHITE);

# Crosses Below
DefineGlobalCOlor("x1b2", Color.RED);
#DefineGlobalCOlor("x2b3", Color.DARK_RED);
#DefineGlobalCOlor("x3b4", Color.MAGENTA);
#DefineGlobalCOlor("x4b5", Color.BLUE);


# Paint Clouds

AddCloud(ema1, ema2, GlobalColor("x1a2"), GlobalColor("x1b2"));
#AddCloud(ema2, ema3, GlobalColor("x2a3"), GlobalColor("x2b3"));
#AddCloud(ema3, ema4, GlobalColor("x3a4"), GlobalColor("x3b4"));
#AddCloud(ema4, ema5, GlobalColor("x4a5"), GlobalColor("x4b5"));


# Create Chart Label to signify that EMA's are Stacked

def stackedUp = ema1 > ema2 and ema2 > ema3 and ema3 > ema4 and ema4 > ema5;
def stackedDn = ema1 < ema2 and ema2 < ema3 and ema3 < ema4 and ema4 < ema5;
#def stackedUp = ema1 > ema2 and ema2 > ema3;
#def stackedDn = ema1 < ema2 and ema2 < ema3;

AddLabel(show_stacked_label, " EMA's Stacked ", if stackedUp then Color.GREEN else if stackedDn then Color.RED else Color.GRAY);


# END EMA_5_Stack
 
@rad14733 - This basically plots all the ema on the chart. What I am looking in what Ben has created. I want to created a watchlist column which gives me this kind of information.

@BenTen - Did you get a chance to look at the example I provided?
 
Hello I am trying to create an alert on my watch list that would change the column color and ring a bell when a 3min candle closes above the 200 ema (just for the stocks im watching)

close crosses above MovAvgExponential("length" = 200)."AvgExp" from 1 bars ago
  • I want the column to turn Green when true
  • Alert (Chime) to go off
 
Last edited by a moderator:
@pga0008 Edited: So just when cross is above 200... Have you tried coding it yet...??? We need to know what Study you are using on your Charts... Please post the code, not just a shared link and I'll look into it for you...
 
Last edited:

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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