Help modifying this snippet to get ATM option price for external symbol instead of current symbol
I just need to replace "GetUnderlyingSymbol" with "SPX" (I need the SPX ATM contract prices to be grabbed while charting /ES) but it doesn't seem possible to input a symbol manually as a parameter for the GetATMOption function. Is there a workaround? (complete code is from this post: here)
Edit: It seems the answer is here: https://usethinkscript.com/threads/get-price-of-option-price-at-specific-strike.13332/post-112669:
Does the GetATMOption function return the bid price though? Or do I need to either change "priceType = PriceType.BID" to "priceType = PriceType.LAST" or "priceType = PriceType.MARK" to make the output the same as GetATMOption?
Edit 2, looks like from this page it's the close price which should be pricetype=last.
Code:
def ATMCprice = if isNaN(close(symbol = GetATMOption(GetUnderlyingSymbol(), OptionDateString, OptionClass.CALL)))
then ATMCprice[1]
else close(symbol = GetATMOption(GetUnderlyingSymbol(), OptionDateString, OptionClass.CALL));
def ATMPprice = if isNaN(close(symbol = GetATMOption(GetUnderlyingSymbol(), OptionDateString, OptionClass.PUT)))
then ATMCprice[1]
else close(symbol = GetATMOption(GetUnderlyingSymbol(), OptionDateString, OptionClass.PUT));
I just need to replace "GetUnderlyingSymbol" with "SPX" (I need the SPX ATM contract prices to be grabbed while charting /ES) but it doesn't seem possible to input a symbol manually as a parameter for the GetATMOption function. Is there a workaround? (complete code is from this post: here)
Edit: It seems the answer is here: https://usethinkscript.com/threads/get-price-of-option-price-at-specific-strike.13332/post-112669:
Code:
# def s = Round(close("SPY")+2,0);
def x6 = close(symbol = ".SPY" + yr2 + mm + dd + "C" + s, priceType = PriceType.BID);
addlabel(1, x6, color.magenta);
Does the GetATMOption function return the bid price though? Or do I need to either change "priceType = PriceType.BID" to "priceType = PriceType.LAST" or "priceType = PriceType.MARK" to make the output the same as GetATMOption?
Edit 2, looks like from this page it's the close price which should be pricetype=last.
Last edited: