Dynamically display underlying equity as an overlay on any option chart

bcaka

New member
Plus
I've been looking for a way to display the underlying equity value as an overlay for an option chart, dynamically. So far all I can find is the "Comparison" study in TOS which is provided by Schwab, but the code is proprietary, so I can't display it. It's a simple study, shown here;

# Charles Schwab & Co. (c) 2011-2026
#
# Source code isn't available.

input comparisonStyle = {"BAR", "CANDLE", default "LINE"};
input secondarySecurity = "";

I can enter a 'secondarySecurity' between the quote marks, but that value is now fixed and if I choose another option holding in my account watchlist the original 'secondarySecurity' remains the same as in the previously displayed chart.

What I would like to have is the value of this 'secondarySecurity' to dynamically follow the changing option 'Symbol' when I open a different chart.

Unfortunately my script writing skills are pathetic, so I am asking for help! Is there a variable I can plug in between those quote marks that will equal the chart 'Symbol'?

Thanks in advance for any help.
 
Solution
I've been looking for a way to display the underlying equity value as an overlay for an option chart, dynamically. So far all I can find is the "Comparison" study in TOS which is provided by Schwab, but the code is proprietary, so I can't display it. It's a simple study, shown here;

# Charles Schwab & Co. (c) 2011-2026
#
# Source code isn't available.

input comparisonStyle = {"BAR", "CANDLE", default "LINE"};
input secondarySecurity = "";

I can enter a 'secondarySecurity' between the quote marks, but that value is now fixed and if I choose another option holding in my account watchlist the original 'secondarySecurity' remains the same as in the previously displayed chart.

What I would like to have is the value of this...
I've been looking for a way to display the underlying equity value as an overlay for an option chart, dynamically. So far all I can find is the "Comparison" study in TOS which is provided by Schwab, but the code is proprietary, so I can't display it. It's a simple study, shown here;

# Charles Schwab & Co. (c) 2011-2026
#
# Source code isn't available.

input comparisonStyle = {"BAR", "CANDLE", default "LINE"};
input secondarySecurity = "";

I can enter a 'secondarySecurity' between the quote marks, but that value is now fixed and if I choose another option holding in my account watchlist the original 'secondarySecurity' remains the same as in the previously displayed chart.

What I would like to have is the value of this 'secondarySecurity' to dynamically follow the changing option 'Symbol' when I open a different chart.

Unfortunately my script writing skills are pathetic, so I am asking for help! Is there a variable I can plug in between those quote marks that will equal the chart 'Symbol'?

Thanks in advance for any help.

this scales a stock chart (yellow line) to fit on an option chart

Code:
# compare_stock_option

#https://usethinkscript.com/threads/dynamically-display-underlying-equity-as-an-overlay-on-any-option-chart.22449/
#Dynamically display underlying equity as an overlay on any option chart
#bcaka  5/28

#I've been looking for a way to display the underlying equity value as an overlay for an option chart, dynamically. 


def na = double.nan;
def bn = barnumber();


def isopt = !IsOptionable();

#addlabel(1, isopt, color.cyan);
AddLabel(isopt, GetSymbolPart() + " is an option for ",color.cyan);
addlabel(isopt, " ", color.black);
AddLabel(isopt, GetUnderlyingSymbol(),color.yellow);


def n = 1000;
def big = 99999;

# find hi and lo of option
def ohi;
def olo;
if bn == 1 then {
 ohi = fold a = 0 to n
 with b
 while !isnan(getvalue(close , -a))
 do max(getvalue(high , -a), b);

 olo = fold c = 0 to n
 with d = big
 while !isnan(getvalue(close , -c))
 do min(getvalue(low , -c), d);
} else {
 ohi = ohi[1];
 olo = olo[1];
}


#plot zohi = ohi;
#plot zolo = olo;

#---------------------------

def stk;
if isopt then {
 stk = close(GetUnderlyingSymbol());
} else {
 stk = 0;
}



# find hi and lo of stock
def shi;
def slo;
if !isopt then {
 shi = 0;
 slo = 0;
} else if bn == 1 then {
 shi = fold e = 0 to n
 with f
 while !isnan(getvalue(stk , -e))
 do max(getvalue(stk , -e), f);

 slo = fold g = 0 to n
 with h = big
 while !isnan(getvalue(stk , -g))
 do min(getvalue(stk , -g), h);
} else {
 shi = shi[1];
 slo = slo[1];
}


#plot zshi = shi;
#plot zslo = slo;
#def stk = close(GetUnderlyingSymbol());

#plot zp = stk;
#zp.SetDefaultColor(Color.yellow);
#zp.setlineweight(2);
#zp.hidebubble();



#---------------------

# scale stk price range to option

# scalefactor =  (option hi - option lo) / (stk hi - stk lo) 

def scalef;
def stk2;
if isopt then {
 scalef = (ohi-olo)/(shi-slo);
 stk2 = ((stk-slo) * scalef) + olo;
} else {
 scalef = 0;
 stk2 = 0;
}


plot zstk2 = if stk2 > 0 then stk2 else na;
zstk2.SetDefaultColor(Color.yellow);
zstk2.setlineweight(2);
zstk2.hidebubble();
#
 
Solution

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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