# when price has touched a certain moving average?

##### Member
is there a watchlist column where it tells me when price has touched a certain moving average? thanks

Solution
is there a watchlist column where it tells me when price has touched a certain moving average? thanks
Change the EMA length as per your requirement

Code:
``````input price = close;
input length = 20;
input Showlabels = yes;

def AvgExp = ExpAverage(price, length);
def diff = close - AvgExp;

def diffUP = diff > AvgExp;
def diffDN =  diff < AvgExp;
def diffnet = !diffUP and !diffDN;

AddLabel(Showlabels and  diffUP, " " + Round(diff), Color.WHITE);
AddLabel(Showlabels and  diffDN, "  " + diff, Color.WHITE);
AddLabel(Showlabels and  diffnet, "  " + diff, Color.WHITE);

assignbackgroundcolor(if diff is greater than 0 then Color.DARK_GREEN else if diff is less than 0 then Color.DARK_RED else color.white);``````
is there a watchlist column where it tells me when price has touched a certain moving average? thanks
Change the EMA length as per your requirement

Code:
``````input price = close;
input length = 20;
input Showlabels = yes;

def AvgExp = ExpAverage(price, length);
def diff = close - AvgExp;

def diffUP = diff > AvgExp;
def diffDN =  diff < AvgExp;
def diffnet = !diffUP and !diffDN;

AddLabel(Showlabels and  diffUP, " " + Round(diff), Color.WHITE);
AddLabel(Showlabels and  diffDN, "  " + diff, Color.WHITE);
AddLabel(Showlabels and  diffnet, "  " + diff, Color.WHITE);

assignbackgroundcolor(if diff is greater than 0 then Color.DARK_GREEN else if diff is less than 0 then Color.DARK_RED else color.white);``````

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