Code won't display label with value

tostrader994857

New member
Entered the code below, but chart label just says "N/A". I am trying to calculate implied stock move by obtaining atm put and call option prices. Then inputting a formula which is defined as "Y". But when i try to plot the value of Y, it just says "N/A", but the value of the ATMStrike is displayed.

Input ExpirationDate = 20240209;

input strikeDistance = 1; # change this value based on symbol , 5 for SPX, 1 for SPY etc.
def c = close(symbol = GetUnderlyingSymbol());
plot ATMStrike = Round(c / strikeDistance, 0) * strikeDistance;

def atmPut = close(GetATMOption(GetUnderlyingSymbol(), ExpirationDate, OptionClass.PUT));
def atmCall = close(GetATMOption(GetUnderlyingSymbol(), ExpirationDate, OptionClass.CALL));

def underlyingStockLastPrice = close(GetUnderlyingSymbol(), priceType = PriceType.LAST);


def move = (atmPut + atmCall - (ATMStrike - underlyingStockLastPrice));
plot Y = (move / underlyingStockLastPrice) * 100;

AddLabel(yes , "Closest Strike: " + ATMStrike + " ", Color.Gray);
AddLabel(yes , Y , Color.Gray);
 
Solution
Entered the code below, but chart label just says "N/A". I am trying to calculate implied stock move by obtaining atm put and call option prices. Then inputting a formula which is defined as "Y". But when i try to plot the value of Y, it just says "N/A", but the value of the ATMStrike is displayed.

Input ExpirationDate = 20240209;

input strikeDistance = 1; # change this value based on symbol , 5 for SPX, 1 for SPY etc.
def c = close(symbol = GetUnderlyingSymbol());
plot ATMStrike = Round(c / strikeDistance, 0) * strikeDistance;

def atmPut = close(GetATMOption(GetUnderlyingSymbol(), ExpirationDate, OptionClass.PUT));
def atmCall = close(GetATMOption(GetUnderlyingSymbol(), ExpirationDate, OptionClass.CALL));

def...
Entered the code below, but chart label just says "N/A". I am trying to calculate implied stock move by obtaining atm put and call option prices. Then inputting a formula which is defined as "Y". But when i try to plot the value of Y, it just says "N/A", but the value of the ATMStrike is displayed.

Input ExpirationDate = 20240209;

input strikeDistance = 1; # change this value based on symbol , 5 for SPX, 1 for SPY etc.
def c = close(symbol = GetUnderlyingSymbol());
plot ATMStrike = Round(c / strikeDistance, 0) * strikeDistance;

def atmPut = close(GetATMOption(GetUnderlyingSymbol(), ExpirationDate, OptionClass.PUT));
def atmCall = close(GetATMOption(GetUnderlyingSymbol(), ExpirationDate, OptionClass.CALL));

def underlyingStockLastPrice = close(GetUnderlyingSymbol(), priceType = PriceType.LAST);


def move = (atmPut + atmCall - (ATMStrike - underlyingStockLastPrice));
plot Y = (move / underlyingStockLastPrice) * 100;

AddLabel(yes , "Closest Strike: " + ATMStrike + " ", Color.Gray);
AddLabel(yes , Y , Color.Gray);

when asking questions,
tell us where you are using the code and what timeframe,
chart, column, scan,..

what symbol are you using,
stock or option?

if you are plotting a stock on a chart, why are you using

def underlyingStockLastPrice = close(GetUnderlyingSymbol(), priceType = PriceType.LAST);

just use close.


something related, till someone posts exact answer
https://usethinkscript.com/threads/thinkscript-not-detecting-option.15630/#post-126019
 
Last edited:

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

Entered the code below, but chart label just says "N/A". I am trying to calculate implied stock move by obtaining atm put and call option prices. Then inputting a formula which is defined as "Y". But when i try to plot the value of Y, it just says "N/A", but the value of the ATMStrike is displayed.

Input ExpirationDate = 20240209;

input strikeDistance = 1; # change this value based on symbol , 5 for SPX, 1 for SPY etc.
def c = close(symbol = GetUnderlyingSymbol());
plot ATMStrike = Round(c / strikeDistance, 0) * strikeDistance;

def atmPut = close(GetATMOption(GetUnderlyingSymbol(), ExpirationDate, OptionClass.PUT));
def atmCall = close(GetATMOption(GetUnderlyingSymbol(), ExpirationDate, OptionClass.CALL));

def underlyingStockLastPrice = close(GetUnderlyingSymbol(), priceType = PriceType.LAST);


def move = (atmPut + atmCall - (ATMStrike - underlyingStockLastPrice));
plot Y = (move / underlyingStockLastPrice) * 100;

AddLabel(yes , "Closest Strike: " + ATMStrike + " ", Color.Gray);
AddLabel(yes , Y , Color.Gray);

several things wrong,
using a friday date instead of sat.
using a past date instead of future date
for most symbols, use 3rd sat in month. for weeklies, use any sat.

made it a lower,
change close formulas
add labels for put and call symbols
add labels for put and call prices


side note,
if you look at a small timeframe, like 1 minute, there is a chance there is no trades on the options and it will return N/A. look at DAY data, to get working, then tweak if needed for smaller times ( use isnan() to check if option price is an error, then set to a previous value)


i left in my extra codes and notes

Code:
#option_atm_symbols4

#https://usethinkscript.com/threads/code-wont-display-label-with-value.17868/
#Code won't display label with value
#tostrader994857  2/17

#Entered the code below, but chart label just says "N/A". I am trying to calculate implied stock move by obtaining atm put and call option prices. Then inputting a formula which is defined as "Y". But when i try to plot the value of Y, it just says "N/A", but the value of the ATMStrike is displayed.

declare lower;

# fri
#Input ExpirationDate = 20240209;
# sat
#Input ExpirationDate = 20240210;

# fri
#Input ExpirationDate = 20240315;
# sat  works
Input ExpirationDate = 20240316;


# change this value based on symbol , 5 for SPX, 1 for SPY etc.
input strikeDistance = 1;

#def c = close(symbol = GetUnderlyingSymbol());
def c = close;

#plot ATMStrike = Round(c / strikeDistance, 0) * strikeDistance;
def ATMStrike = Round(c / strikeDistance, 0) * strikeDistance;

def atmPut = close(GetATMOption(GetUnderlyingSymbol(), ExpirationDate, OptionClass.PUT));
def atmCall = close(GetATMOption(GetUnderlyingSymbol(), ExpirationDate, OptionClass.CALL));

#def underlyingStockLastPrice = close(GetUnderlyingSymbol(), priceType = PriceType.LAST);
def underlyingStockLastPrice = close;

def move = (atmPut + atmCall - (ATMStrike - underlyingStockLastPrice));
plot Y = (move / underlyingStockLastPrice) * 100;


AddLabel(yes , "Closest Strike: " + ATMStrike + " ", Color.Gray);
AddLabel(yes , Y + " %", Color.Gray);


addlabel(1, " ", color.black);
addlabel(1, "put " +
 (GetATMOption(GetUnderlyingSymbol(), ExpirationDate, OptionClass.PUT))
, color.yellow);
addlabel(1, atmPut, color.yellow);

addlabel(1, " ", color.black);
addlabel(1, "call " +
 (GetATMOption(GetUnderlyingSymbol(), ExpirationDate, OptionClass.call))
, color.cyan);
addlabel(1, atmcall, color.cyan);

addlabel(1, " ", color.black);

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


# debugging,
# go to the code line causing an error.
# put some of the variables in a bubble to see what is happening

# add this to end of code
# both are N/A
addchartbubble(0, low,
move + "\n" +
y
, color.yellow, no);


# add this ad end of code, to show the values in move formula
# put and call are N/A
addchartbubble(0, low,
atmPut + "\n" +
atmCall + "\n" +
ATMStrike + "\n" +
underlyingStockLastPrice + "\n"
, color.yellow, no);
#
 
Solution

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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