Ema Crossover Watchlist

How can i create a column for Tos to show a 5/8 ema crossover ?
Thanks

The following code should suffice for a Custom Watchlist Column...

Ruby:
def xUp = ExpAverage("data" = CLOSE, "length" = 5) crosses above ExpAverage("data" = CLOSE, "length" = 8);
def xDn = ExpAverage("data" = CLOSE, "length" = 5) crosses below ExpAverage("data" = CLOSE, "length" = 8);
AddLabel(yes, if xUp then "xUp" else if xDn then "xDn" else " ", Color.CURRENT);
AssignBackgroundColor(if xUp then Color.GREEN else if xDn then Color.RED else Color.GRAY);
 

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

The following code should suffice for a Custom Watchlist Column...

Ruby:
def xUp = ExpAverage("data" = CLOSE, "length" = 5) crosses above ExpAverage("data" = CLOSE, "length" = 8);
def xDn = ExpAverage("data" = CLOSE, "length" = 5) crosses below ExpAverage("data" = CLOSE, "length" = 8);
AddLabel(yes, if xUp then "xUp" else if xDn then "xDn" else " ", Color.CURRENT);
AssignBackgroundColor(if xUp then Color.GREEN else if xDn then Color.RED else Color.GRAY);
I am trying to do something extremely similar so I didn’t want to create a new thread. The column shows all results as gray if I use this exact code and it shows all results as black if I use my code attached screenshot.

For my particular instance, I am trying to create a column in my watchlist that shows “bullish" if EMA4 is currently above EMA21 and “bearish” if EMA4 is currently below EMA21 for specific timeframes. Any help with this syntax would be huge.
 

Attachments

  • Screenshot 2025-07-10 at 2.24.05 PM.png
    Screenshot 2025-07-10 at 2.24.05 PM.png
    188 KB · Views: 30
Last edited:
Since your script says 'crosses above,' it is only showing the green and red colors if the EMAs are currently crossing over each other, which means it only triggers on the exact bar the crossover happens not on every bar after. Here is a working version.
Ruby:
def ema4 = ExpAverage(close, 4);
def ema21 = ExpAverage(close, 21);

def isBullish = ema4 > ema21;
def isBearish = ema4 < ema21;

AddLabel(yes, if isBullish then "Bullish" else if isBearish then "Bearish" else "Neutral", if isBullish then color.GREEN else if isBearish then color.RED else color.LIGHT_GRAY);
If you want to change the timeframe the EMAs calculate on, just adjust the aggregation period in the column settings.
 

Attachments

  • Screenshot 2025-07-24 at 11.12.32 AM.png
    Screenshot 2025-07-24 at 11.12.32 AM.png
    242.8 KB · Views: 32
I just tested now and compared both the Watchlist data with each ticker's Chart. This worked perfect. Thank you so much for the help! Here is my code below for anyone that likes the look. Screenshot attached.

Code:
def EMA4 = ExpAverage(close, 4);
def EMA21 = ExpAverage(close, 21);

def Bullish = EMA4 > EMA21;
def Bearish = EMA4 < EMA21;

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

Attachments

  • Screenshot 2025-07-25 at 5.27.09 PM.png
    Screenshot 2025-07-25 at 5.27.09 PM.png
    50.6 KB · Views: 28
I just tested now and compared both the Watchlist data with each ticker's Chart. This worked perfect. Thank you so much for the help! Here is my code below for anyone that likes the look. Screenshot attached.

Code:
def EMA4 = ExpAverage(close, 4);
def EMA21 = ExpAverage(close, 21);

def Bullish = EMA4 > EMA21;
def Bearish = EMA4 < EMA21;

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

For some columns you’re using the 8 I see? Can you talk a bit about your experience with choosing the aggs and the ema’s ? Are you waiting for a stacked alignement to take positions? Obviously a cross happening on the 10m will lag against the hourly, so just curious on the approach. Thanks!
 
For some columns you’re using the 8 I see? Can you talk a bit about your experience with choosing the aggs and the ema’s ? Are you waiting for a stacked alignement to take positions? Obviously a cross happening on the 10m will lag against the hourly, so just curious on the approach. Thanks!
Yes. I am pretty much trading with a hybrid approach.

EMA8_10M - Is the current Ask price above the 8 EMA over a 10 minute period?
EMA8_1H - Is the current Ask price above the 8 EMA over a 60 minute period? (lately I’ve been using 30 minutes)

EMA21_1D - Is the 4 EMA currently above the 21 EMA on the Daily timeframe?
EMA21_1W - Is the 4 EMA currently above the 21 EMA on the Weekly timeframe?

For a bigger picture, at minimum, I won’t enter any trades unless the Daily and Weekly are both “Bullish” when I’m looking to buy CALLS and both Bearish when I’m looking to buy PUTS.

For a smaller picture, I use the EMA8 columns for spotting entries with recent trend. I definitely try to look for “stacked" alignment.
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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