How to paint price bar based on 3 different EMAs: all up, green; all down, red; and mixed, maybe gray? No need to be stacked.

DocKen

New member
For example, if 2, 5, and 8 EMA all going up, green. If 2, 5, and 8 all going down, red. If no agreement in direction, gray. Hope to use primarily on 5 minute chart.
 
Solution
For example, if 2, 5, and 8 EMA all going up, green. If 2, 5, and 8 all going down, red. If no agreement in direction, gray. Hope to use primarily on 5 minute chart.

The following has an optional price coloring as you requested

Capture.jpg
Ruby:
plot ema1 = expaverage(close,2);
plot ema2 = expaverage(close,5);
plot ema3 = expaverage(close,8);

def up = (ema1>ema1[1]) + (ema2>ema2[1]) + (ema3>ema3[1]);
def dn = (ema1<ema1[1]) + (ema2<ema2[1]) + (ema3<ema3[1]);

input pricecolor = yes;
assignpriceColor(if !pricecolor then color.current else       
                 if up == 3
                   then color.green else
                 if dn == 3
                   then color.red
                 else color.light_gray);
For example, if 2, 5, and 8 EMA all going up, green. If 2, 5, and 8 all going down, red. If no agreement in direction, gray. Hope to use primarily on 5 minute chart.

The following has an optional price coloring as you requested

Capture.jpg
Ruby:
plot ema1 = expaverage(close,2);
plot ema2 = expaverage(close,5);
plot ema3 = expaverage(close,8);

def up = (ema1>ema1[1]) + (ema2>ema2[1]) + (ema3>ema3[1]);
def dn = (ema1<ema1[1]) + (ema2<ema2[1]) + (ema3<ema3[1]);

input pricecolor = yes;
assignpriceColor(if !pricecolor then color.current else       
                 if up == 3
                   then color.green else
                 if dn == 3
                   then color.red
                 else color.light_gray);
 
Solution

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

Question about the EMA in the code. Is the EMA by default the EMA of the close? Is there any way to base the EMA on high, low, and close divided by 3?

Yes. I have modified the code to allow you to choose differnt price types (eg: (H+L+C) / 3) for your request) at the input screen. Also, you can now try different average types and lengths at the input screen.

Ruby:
input length1 = 2;
input length2 = 5;
input length3 = 8;
input price   = close;
input avgtype = AverageType.EXPONENTIAL;

plot ma1 = MovingAverage(avgtype, price, length1);
plot ma2 = MovingAverage(avgtype, price, length2);
plot ma3 = MovingAverage(avgtype, price, length3);

def up = (ma1 > ma1[1]) + (ma2 > ma2[1]) + (ma3 > ma3[1]);
def dn = (ma1 < ma1[1]) + (ma2 < ma2[1]) + (ma3 < ma3[1]);

input pricecolor = yes;
AssignPriceColor(if !pricecolor then Color.CURRENT else       
                 if up == 3
                   then Color.GREEN else
                 if dn == 3
                   then Color.RED
                 else Color.LIGHT_GRAY);
 
Yes. I have modified the code to allow you to choose differnt price types (eg: (H+L+C) / 3) for your request) at the input screen. Also, you can now try different average types and lengths at the input screen.
I appreciate this so much! This will so much help with things I have been trying to follow by "eyeballing" the chart EMAs.
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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