Ema Crossover Watchlist

Solution
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.
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);
 
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: 18
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: 19
Solution

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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