Percentage Change with PAIRS in scanner


New member
I've been working at this for awhile, but can't get it to work. Hoping I can get some help . . . .

I'm creating a scan that takes into account the % Percentage Change of a Primary Symbol and scans for a Secondary Symbol with the following criteria:

- Daily Aggregation over a 1 year time period.

- % Percentage Change of Secondary Symbol.

- Daily Bar Count of how many times Primary Symbol's % Percentage Change is ABOVE or BELOW the Secondary Symbol.'s % Percentage Change

- Create a scan based on the number of times (as a percentage value) the Primary Symbol does better/ worse than the Secondary Symbol.

For example, I want to scan stocks that compare with the SPY % change and search for how often they out/ underperformed during the year. I'd like to search for different percentages of time greater than 50%, 60%, 70% etc.

Attaching code and an image the shows a chart of what I'm trying to turn into a scan. Can see that the Seconday (pink line) stays above the Primary 80% of the time.

Thank you to anyone who can help!!

input symbol = “SPY”;
input percent = .90;

def S1_open = open(symbol)[252] ;
def S1_close = close(symbol);
def S1_difference = S1_close - S1_open;
def S1_percent_diff = (S1_difference/ S1_open) * 100;

def S2_open = open[252];
def S2_close = close;
def S2_difference = S2_close - S2_open;
def S2_percent_diff = (S2_difference/ S2_open) * 100 ;

def S1_over = TotalSum(S1_percent_diff is greater than S2_percent_diff);
def S2_over = TotalSum(S2_percent_diff is greater than S1_percent_diff);

def Bar_Total = S1_over + S2_over;
def S1_over_percent = (S1_over/ Bar_Total);
def S2_over_percent = (S2_over/ Bar_Total);

plot scan = S2_over_percent is greater than percent;


  • 1.jpg
    85.2 KB · Views: 61

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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