How to automatically find ATM strike prices

unkn0wn

New member
Plus
I need to find out if thinkscripts can make automatic trades for both iron condor and straddles that automatically find ATM strike prices.

Since ATM option strike prices can constantly change, is there a way the script can automatically find the ATM strike price and use its value for a trade instead of a set value?
 
Solution
Last edited:
Solution
I have a similar need to find the ATM strike of "SPX" while plotting the SPXW options volume*price on SPY. I don't need it to make the trades, i just need it to return the ATM Strike. If there isn't an easy way I'll look at OptionsHacker and use the "Centerstrike" code...messy but should get it done.
I think you can try the "floor (close)". It will always return to ATM.
 
I think you can try the "floor (close)". It will always return to ATM.
Can you elaborate? I have problems with the GetATMOption function being too unstable to produce a consistent plot when it's used on an equities or futures chart. In other words, the plot appears and disappears as if the value returned by the GetATMOption function is not retained in a persistent or stable fashion, even when the code should be storing it recursively. Are you aware of a workaround to this problem for getting the ATM option contract's close price, or is your workaround only getting the ATM strike price?
 
I have a similar need to find the ATM strike of "SPX" while plotting the SPXW options volume*price on SPY. I don't need it to make the trades, i just need it to return the ATM Strike. If there isn't an easy way I'll look at OptionsHacker and use the "Centerstrike" code...messy but should get it done.

This will be a close approximation to start with. It is possible to check if the close is above/below strike and may be selective to use different values for puts versus calls. I didn't study TOS on how it changes ATM during the live market. If someone made notes around edge value (say price is 4557.5, exactly between 2 strikes), please share.

Sample output from running now.

1701534364981.png

Ruby:
# 12/02/2023 Raj B, initial code to calculate ATM Strike

# calculated ATMStrike
input strikeDistance = 5; # 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;

# comparison code
input expirationDate = 20231205; # use +1 day, a value for 20231205 refers to .SPXW231204 option
AddLabel(IsOptionable(), "ATM Call option is " + GetATMOption(GetUnderlyingSymbol(), expirationDate, OptionClass.CALL), Color.Gray);
AddLabel(IsOptionable(), "ATM Put option is " + GetATMOption(GetUnderlyingSymbol(), expirationDate, OptionClass.PUT),  Color.Gray);
AddLabel(yes , ATMStrike , Color.Gray);
 
Can you elaborate? I have problems with the GetATMOption function being too unstable to produce a consistent plot when it's used on an equities or futures chart. In other words, the plot appears and disappears as if the value returned by the GetATMOption function is not retained in a persistent or stable fashion, even when the code should be storing it recursively. Are you aware of a workaround to this problem for getting the ATM option contract's close price, or is your workaround only getting the ATM strike price?
input optionSeriesPrefix = ".QQQ231204";
def strike = floor(close);
def putOptionClose = if IsNaN(close(Concat(optionSeriesPrefix, Concat("P", strike)))) then 0 else close(Concat(optionSeriesPrefix, Concat("P", strike)));

This will always return the 0DTE ATM put option close contract for today. All the best!
 
input optionSeriesPrefix = ".QQQ231204";
def strike = floor(close);
def putOptionClose = if IsNaN(close(Concat(optionSeriesPrefix, Concat("P", strike)))) then 0 else close(Concat(optionSeriesPrefix, Concat("P", strike)));

This will always return the 0DTE ATM put option close contract for today. All the best!

Thank you for suggesting this workaround, it makes sense. If I want to get the ATM option price for SPX then I am assuming I'd use (Round( (close(symbol="SPX") / 5), 0) * 5) instead of the floor function. I will give this a try today. All the best.
 

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

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
462 Online
Create Post

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