Help color coding different time frames EMA's on watchlist tab.

DGreenleaf17

New member
Sorry for the confusing title, but essentially, I'm curious, i have a script for color coded stacked EMA's, 8 though 135 and if its positively stacked it goes green, negative is red and black is neutral. I was curious if anyone knows how if per example, the 5m, 15m, 30m, 1hr, 2hr, 4hr are all stacked positively, it would be green and so on, so that way i can only have 1 tab for all time frames under the watchlist, instead of 1 per time frame. I tried finding how to code it myself, i just don't know how to add time frames within the code itself.

This is the code i have at the moment.


Code:
def EMA8 = ExpAverage(close, 8);
def EMA13 = ExpAverage(close, 13);
def EMA21 = ExpAverage(close, 21);
def EMA34 = ExpAverage(close, 34);
def EMA45 = ExpAverage(close, 45);
def EMA90 = ExpAverage(close, 90);
def EMA135 = ExpAverage(close, 135);


def bullish = EMA8 > EMA13 and EMA13 > EMA21 and EMA21 > EMA34 and EMA34 > EMA45 and EMA45 > EMA90 and EMA90 > EMA135;
def bearish = EMA8 < EMA13 and EMA13 < EMA21 and EMA21 < EMA34 and EMA34 < EMA45 and EMA45 < EMA90 and EMA90 < EMA135;

AddLabel(bullish, "Bullish Stacked MAs", color.black);
AddLabel(bearish, "Bearish Stacked MAs", color.black);
AddLabel(!bullish and !bearish, " ", color.black);

AssignBackgroundColor(if bullish then color.green else if bearish then color.red else color.black);
 
Hey @DGreenleaf17 - What timeframes are you looking to use? It is a limitation of ToS that you cannot have data from a faster timeframe shown on a slower timeframe, meaning that you can't show a 15 min EMA on a 1-hour chart.

Anyway, you can get the ema from e.g. the hourly chart with the code:

DEF ema8Hourly = MovingAverage(averageType.EXPONENTIAL, close( period = aggregationPeriod.HOUR), 8);

This should give you the direction you need to accomplish your desired result as I understand it.

-- Matt.
 

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
311 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