Compare two instruments

jngy2k

Member
Something that looks like this yellow line in Tradingview.

fudY3TP.png


There's RelativeStrength and Correlation indicators prebuilt into TOS that gives a comparison of what the stock is doing versus the index. However I want to simplify it to ONLY plot a simple line of the price action of the index. No comparison no correlation just a simple chart price of the index as a line and as a indicator. It will essentially be a line chart of the index on the bottom of the stock price chart. I know i can adjust the screen in Flexible Grid to have the index on the bottom and stock chart on the top but I want it as an indicator declare_lower so it doesn't take up as much screen space.

The purpose is to actually easily compare relative strength of the stock to the market instead of having a indicator calculate this stock is below or above the performance of the market on a zero scale. If the stock price is up but the market line is downwards as seen in the photo, then that is huge relative strength.

IS there such a tool? I believe the code GetSymbol() can be used to make the indicator.

Nevermind figured it out.

Code:
declare lower;

input price = FundamentalType.CLOSE;
input relationWithSecurity = "SPX";

def price2 = fundamental(price, relationWithSecurity);

plot Relation = price2;
Relation.SetDefaultColor(GetColor(1));
 
Last edited:
Solution
trying to plot the difference between a ticker's current percent change :
today's price and yesterday's close
vs
the SPX's percent change,

the simplest way to to look at this is to see the Watchlist and take the difference between the %Change of 2 symbols.
I can't get one line to work.

declare lower;
plot zeroline = 0;
zeroline.SetDefaultColor(Color.RED);

# Plots today's price as a percent change versus yestday's close
input aggregationPeriod = AggregationPeriod.DAY;
def previous_close = close(period = aggregationPeriod)[1];
plot diff_close = (close - previous_close) / previous_close * 100; #this is in a percent form
AddLabel (yes, "test: " + previous_close + "," + close );
AddLabel (yes, "diff: " + diff_close );


# Previous...

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

Hello everyone,

If someone can help me create the indicator which compare 2 stocks HH, HL, LH, LL and detect the divergence in a stock. For eg. stock A is making a lower lows (LL) but stock B is making a Higher lows (HL) then it compares with stock A and plot bullish divergence for stock B. This is useful especially for comparing the companies in the same sectors or with sector ETF or even indices.

Thank you,
 
Last edited:
I am looking for the same. Would be nice to add an option to select on MTF

Higher High, higher low.. lower high lower low is what he/she meant

Would be nice to if the script uses times frames to measure the trend and show divergence for the time frame used.. if both tickets are going up, there is no divergence. If one is going higher but the other lower for the species time frame, there is a divergence

Something like this but only compares two tickets and mark the divergence trend line

https://usethinkscript.com/threads/top-5-ticker-divergence-indicator-for-thinkorswim.13086/

For me something like this would be nice


FVG stands for fair value gap as in buy/sell imbalance. I already have an indicator for it.. Just need a SMT divergence indicator as shown on the tweet picture if it isn’t supper complicated to do. Btw it is a most valuable indicator specially for futures trading.
 
Very interested in this kind of divergence indicator. I came up with a type of Strat number assignment per candle-divergence indicator that compares two symbols. I find its useful but not quite complete, as the divergence we are looking for is not only between candles but also between swings. Determining which swings will be somewhat tricky. Im sure someone out there can figure this out.
Working it out, will post if it is useful
1AFD224D-2033-44DE-BF11-812A99563740.png
 
Last edited:
trying to plot the difference between a ticker's current percent change :
today's price and yesterday's close
vs
the SPX's percent change,

the simplest way to to look at this is to see the Watchlist and take the difference between the %Change of 2 symbols.
I can't get one line to work.

declare lower;
plot zeroline = 0;
zeroline.SetDefaultColor(Color.RED);

# Plots today's price as a percent change versus yestday's close
input aggregationPeriod = AggregationPeriod.DAY;
def previous_close = close(period = aggregationPeriod)[1];
plot diff_close = (close - previous_close) / previous_close * 100; #this is in a percent form
AddLabel (yes, "test: " + previous_close + "," + close );
AddLabel (yes, "diff: " + diff_close );


# Previous Day Closing Price (PCL) of SPX
def SPX_previous_close = close("SPX", aggregationPeriod)[1]; #SPX yesterday's close
#plot SPX_diff_close = (close("SPX", AggregationPeriod.MIN) - SPX_previous_close * 100; #plot current close minus yesterday's close
# previous line doesn't work

# want to plot %Change between a ticker and the SPX
#plot diff = diff_close -SPX_diff_close;
 
Solution
I too would love to have something like this to compare ES and NQ Emini futures. For ex. When they are trending together making new lows but NQ suddenly reverses trend and ES continues to make new lows. Something that show the trend separation and degree of separation. I have been unable to find auch a thing
 
trying to plot the difference between a ticker's current percent change :
today's price and yesterday's close
vs
the SPX's percent change,

the simplest way to to look at this is to see the Watchlist and take the difference between the %Change of 2 symbols.
I can't get one line to work.

declare lower;
plot zeroline = 0;
zeroline.SetDefaultColor(Color.RED);

# Plots today's price as a percent change versus yestday's close
input aggregationPeriod = AggregationPeriod.DAY;
def previous_close = close(period = aggregationPeriod)[1];
plot diff_close = (close - previous_close) / previous_close * 100; #this is in a percent form
AddLabel (yes, "test: " + previous_close + "," + close );
AddLabel (yes, "diff: " + diff_close );


# Previous Day Closing Price (PCL) of SPX
def SPX_previous_close = close("SPX", aggregationPeriod)[1]; #SPX yesterday's close
#plot SPX_diff_close = (close("SPX", AggregationPeriod.MIN) - SPX_previous_close * 100; #plot current close minus yesterday's close
# previous line doesn't work

# want to plot %Change between a ticker and the SPX
#plot diff = diff_close -SPX_diff_close;

Scripts that contain "aggregationPeriod" are limited to providing plots on charts.
The ToS platform does not support the use of multiple timeframes in Scans, Watchlists, Chart Alerts, Conditional Orders.
 
Is there a way to pull in the last price into thinkscript other than the underlying? As in you're watching the spx, but you want to compare it to another stock without using the built in tos comparision indicator?
 
declare lower;

input symbol = "SPX";

def price = close(symbol);
def basePrice = close;
def ratio = price / basePrice;

plot RS = ratio;
RS.SetDefaultColor(GetColor(1));


You can use this code to create a custom RS line indicator that compares the price movement of the stock you are viewing with the price movement of the SPX. The RS line is calculated by dividing the closing price of the SPY ETF by the closing price of the stock you are viewing, and the resulting ratio is plotted on your chart as an overlaid line. The peaks and troughs in the RS line represent periods of relative strength and weakness for the stock you are viewing compared to the second security you have chosen to compare it with. When the RS line reaches a peak, it indicates that the stock is outperforming the other security at that point in time. When the RS line reaches a trough, it indicates that the stock is underperforming the other security at that point in time.

Data-wise, the peaks and troughs in the RS line are determined by the ratio of the price of one security to the price of another security. When this ratio is increasing, it means that the price of the first security is rising faster than the price of the second security, or that the price of the second security is falling faster than the price of the first security. This results in an upward movement in the RS line and a peak. Conversely, when this ratio is decreasing, it means that the price of the first security is falling faster than the price of the second security, or that the price of the second security is rising faster than the price of the first security. This results in a downward movement in the RS line and a trough. The RS line indicator can also be considered a leading indicator.

Also, TOS comes with a "comparison" study. You just add what instrument you want to compare then you can choose to have it plot a candle, bar, or line chart. If you select line chart, I think it plots the close, but unfortunately you can't choose what its plotting (open/high/low/close).
 
Last edited by a moderator:
I assume some of you are looking for a SMT indicator. This is as close as I've gotten. Its a watchlist column that tells you if the instrument is making a higher high / lower low over the last 5 candles. I only use SMT on the hourly and higher. So I have one written for the 1hr, 4hr, daily and weekly. It will light up (green/red) and show the level that was broken when a SMT happens. So if ES lights up, but NQ doesn't, then you have your SMT.

Its not perfect but its pretty good.

M30: http://tos.mx/uQXiUgd
H1: http://tos.mx/u8yejdO
Daily: http://tos.mx/DLHEcwI
Weekly: http://tos.mx/blGHY04

Code:
# HiLo Break by Cribbage
# 11/14/22
#
# Labels stay yellow, unless ticker is making new highs (green) or new lows (red).

##Inputs##
#input Time_Frame1 = AggregationPeriod.FIFTEEN_MIN;
input slow = 5;
input fast = 2;

##Constant##
def na = double.nan;

##Deinitions##
def H1 = Highest(high,slow);
def H2 = Highest(high,fast);
def hi = high;

def lower = H1[1] <= Hi;

def L1 = Lowest(low,slow);
def L2 = Lowest(low,fast);
def lo = low;

def higher = L1[1] >= Lo;

Def toH = H1[1] - close;
Def toL = close - L1[1];

Def HCloser = toH < toL;
Def LCloser = toL < toH;

Plot level = if Lower then H1[1] else if higher then L1[1] else if Hcloser then H1 else if LCloser then L1 else na;

assignBackgroundColor(if higher then color.light_red else if lower then color.dark_green else color.current);

level.assignValueColor(if higher then color.white else if lower then color.white else if LCloser then color.light_red else if HCloser then color.green else color.current);
 
Hello everyone,

If someone can help me create the indicator which compare 2 stocks HH, HL, LH, LL and detect the divergence in a stock. For eg. stock A is making a lower lows (LL) but stock B is making a Higher lows (HL) then it compares with stock A and plot bullish divergence for stock B. This is useful especially for comparing the companies in the same sectors or with sector ETF or even indices.

Thank you,

reply to post 4,5
divergence study
https://usethinkscript.com/threads/...of-the-lines-between-peaks-and-valleys.17406/
 
Last edited:

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
249 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.
Back
Top