• Get $40 off VIP by signing up for a free account! Sign Up

Help Needed for Stock Performance Vs. Industry


New member
I am trying to write a script that compares a stock performance vs the industry? Can anyone help?


RS Length = 90 Days

Exponential Moving Average Length = 3 Periods
Last edited:
I am trying to write a script that compares a stock performance vs the industry? Can anyone help?

Here is what I have:

StockPrice = Close Data1;

ReferencePrice = Close = of Data2;

If StockPrice > 0 and RefrencePRice > 0 then

LogVal = Log (StockPrice / ReveerencePrice);

Relative Strength = XAverage(LogVal – LogVal[Length],

EMALength) * 100


RS Length = 90 Days

Exponential Moving Average Length = 3 Periods

here is what i came up with.

added , declare lower; to make it a lower study

the default stock that is compared to the chart stock is SPY.
input Reference_stock = "SPY";

the average type can be changed from the default of exponential.

this line , z.hidebubble(); , stops a price bubble from showing up on the price axis.
if you want a price bubble, disable it with a # in front of the code line.

# compare_emalog_0
declare lower;

input RS_length = 90;
input ema_length = 3;
input Reference_stock = "SPY";

def na = double.nan;
def Stock_Price = Close;
def Reference_Price = close(Reference_stock);
def valid = if (Stock_Price * Reference_Price) > 0 then 1 else 0;
def LogVal = If valid then Log(Stock_Price / Reference_Price) else na;

input averageType = AverageType.EXPONENTIAL;
def Relative_Strength = MovingAverage(averageType,(LogVal – LogVal[rs_length]), ema_length) * 100;

plot z = Relative_Strength;

lower chart
MRK 1hr 180day

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


This looks great, thank you so much! Would you happen to know how I can get the indicator to look like this (see image)?

So the histogram is green one above the zero line and red when it is below does your line. https://www.screencast.com/t/KQgB8XLBS

delete the plot formula line and the lines after it. then paste in these lines

plot z = Relative_Strength;
z.AssignValueColor(if Relative_Strength > 0 then color.green else color.red);

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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