How to find strike gap for a stock/index dynamically in options trading ?

Asked by Sejpalsinh Jadeja · SOLVED
1 reply 1,166 views Jump to solution Reply
Sejpalsinh Jadeja Original Post
AlgoDelta Team

So while working on dynamic strike selection (ATM/ITM/OTM) in my sma cross over algo, but I am stuck on strike gap.

Right now I am hardcoding values like 50 for NIFTY and 100 for BANKNIFTY, but I want to make it dynamic for any stock.

Is there a way to calculate strike gap from data instead of hardcoding it?

Posted Apr 24
Reply

    1 Reply

    Support AlgoDelta
    Support AlgoDelta AlgoDelta Support ·

    Yes, so there’s no direct API that gives you “strike gap”.

    The one way to do that calculate it from available strikes from the any source like script master file.

    So, the simple idea is Strike gap = difference between consecutive strikes

    Can understand with simple steps:

    Fetch option chain / instruments
    Take available strikes
    Sort them
    Find difference
    Can also refer below code:

    def get_strike_gap(strikes):
        strikes = sorted(set(strikes))
        if len(strikes) < 2:
            return None
        gaps = [strikes[i+1] - strikes[i] for i in range(len(strikes)-1)]
        # Most common gap
        gap = min(gaps)
        return gap
    
    # Sample - Inplace of this have the stricks from instrument/option chain
    strikes = [19800, 19850, 19900, 19950, 20000]
    
    gap = get_strike_gap(strikes)
    print("Strike Gap:", gap)
    Verified Solution
    • Appreciate your response this clears all my confusion and with code it’s easy to resolve the problem. Thanks a lot. – Sejpalsinh Jadeja Team Jun 17
    Markdown supported · ```json for code blocks · paste or drop screenshots

    Be specific and kind. Never share API keys, passwords or personal account details.

    Welcome to the community

    Log in or create your account in under a minute.

    1. 1Mobile
    2. 2E-mail
    3. 3Password
    +91

    Have a password?

    By continuing you agree to the community guidelines. We’ll send a one-time code by SMS.