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

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

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

The following has an optional price coloring as you requested
Thank you so much! I have learned a lot by just seeing the way you put this together. And, it will be easy for me to adjust the script to try different EMA inputs depending on the type of trading.

The following has an optional price coloring as you requested
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?

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.

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
349 Online

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
• Exclusive indicators
• Proven strategies & setups
• Private Discord community
• Exclusive members-only content
• Add-ons and resources
• 1 full year of unlimited support

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?