# How to add label that calculates real time price distance from ema

#### bitgA

##### New member
Hello and thanks for reading, first post here.

Spent some hours this weekend looking for this seemingly simple script but hit no pay dirt.

I used to have this on my chart, it would give me the real time price distance from the 8 ema for a 1 minute chart.

For example if 8 ema was was at 50 and last trade was at 53 the label would read "+3"

Would someone here be able to post a script that would enable me to have a label that calculates real time price distance from the 8 ema for a 1 minute chart?

AND ALSO a second script that calculates real time price percent distance from the 8 ema for a 1 minute chart?

I would like to have access to both scripts and then be able to choose which one I prefer. Thanks for reading, I hope that was clear.

Solution
Code:
``````input Style = {default Raw, Percent, Both};
def EMA = expAverage(close,8);
def rawDist = Close - EMA;
def perDist = (Close - EMA) / EMA;
AddLabel(style == Style.Raw or style == Style.Both,
rawDist,
if rawDist > 0 then color.green
else if rawDist < 0 then color.red
else color.yellow
);
AddLabel(style == Style.Percent or style == Style.Both,
asPercent(perDist),
if rawDist > 0 then color.green
else if rawDist < 0 then color.red
else color.yellow
);``````
Code:
``````input Style = {default Raw, Percent, Both};
def EMA = expAverage(close,8);
def rawDist = Close - EMA;
def perDist = (Close - EMA) / EMA;
AddLabel(style == Style.Raw or style == Style.Both,
rawDist,
if rawDist > 0 then color.green
else if rawDist < 0 then color.red
else color.yellow
);
AddLabel(style == Style.Percent or style == Style.Both,
asPercent(perDist),
if rawDist > 0 then color.green
else if rawDist < 0 then color.red
else color.yellow
);``````

Code:
``````input Style = {default Raw, Percent, Both};
def EMA = expAverage(close,8);
def rawDist = Close - EMA;
def perDist = (Close - EMA) / EMA;
AddLabel(style == Style.Raw or style == Style.Both,
rawDist,
if rawDist > 0 then color.green
else if rawDist < 0 then color.red
else color.yellow
);
AddLabel(style == Style.Percent or style == Style.Both,
asPercent(perDist),
if rawDist > 0 then color.green
else if rawDist < 0 then color.red
else color.yellow
);``````

I am not a coder. Is there a way to add a label to show what ema we are looking at, in the case that we have multiple emas

Last edited by a moderator:

87k+ Posts
410 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
• 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?