Rajandran R Creator of OpenAlgo Sketchmaker, RagZ. Building GenAI Applications. Telecom Engineer turned Full-time Derivative Trader. Mostly Trading Nifty, Banknifty, High Liquid Stock Derivatives. Trading the Markets Since 2006 onwards. Using Market Profile and Orderflow for more than a decade. Designed and published 100+ open source trading systems on various trading tools. Now the recent curiosity on building Trading AI Agents.

Simple Option Straddle Dashboard – Tradingview Pinescript v5

3 min read

In this blog post, we’ll walk through creating a Simple Option Straddle Dashboard using TradingView’s Pine Script v5. This dashboard will dynamically calculate the At-The-Money (ATM) strike price for a given underlying asset, fetch the corresponding call and put option prices, and display the combined straddle price—all in real-time on your TradingView chart.


Overview of the Dashboard

Our straddle dashboard will:

• Calculate the ATM Strike Price based on the current price of the underlying asset.

• Generate Option Symbols for both the call and put options at the ATM strike.

• Fetch Option Premiums for these options using request.security.

• Calculate the Straddle Price by summing the call and put premiums.

• Display the Information neatly in a table on the chart.

The Pine Script Code

Below is the complete Pine Script code for the dashboard:

// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © algostudio


//@version=5
strategy("Nifty Options Straddle Dashboard", overlay=true,calc_on_every_tick = true,dynamic_requests = true, calc_bars_count = 50)

// Input for underlying symbol
underlying = input.symbol("NSE:NIFTY", "Underlying Symbol")

// Input for expiry date
i_expiry = input.string("240926", "Expiry Date (YYMMDD)")

// Input for strike interval
strikeInterval = input.int(50, "Strike Interval", minval=1)

// Function to extract ticker from full symbol
extractTicker(fullSymbol) =>
    array.get(str.split(fullSymbol, ":"), 1)

// Extract ticker from the underlying symbol
underlyingTicker = extractTicker(underlying)

// Function to round to nearest strike
roundToNearestStrike(price, strikeInterval) =>
    math.round(price / strikeInterval) * strikeInterval

// Calculate ATM strike
atmStrike = roundToNearestStrike(close, strikeInterval)

// Generate option symbols
generateOptionSymbol(ticker, exp, strikePrice, optionType) =>
    s_exp = str.tostring(exp)  // Convert input string to simple string
    "NSE:" + ticker + s_exp + optionType + str.tostring(strikePrice)

// Request security for options
getOptionPrice(ticker, exp, strikePrice, optionType) =>
    s_exp = str.tostring(exp)  // Convert input string to simple string
    s_optionType = str.tostring(optionType)  // Convert input string to simple string
    optionSymbol = generateOptionSymbol(ticker, s_exp, strikePrice, s_optionType)
    s_optionSymbol = str.tostring(optionSymbol)  // Convert input string to simple string
    request.security(s_optionSymbol, timeframe.period, close)

// Get call and put prices
callPrice = getOptionPrice(underlyingTicker, i_expiry, atmStrike, "C")
putPrice = getOptionPrice(underlyingTicker, i_expiry, atmStrike, "P")

// Calculate straddle price
straddlePrice = callPrice + putPrice

// Table settings
var table dashboardTable = table.new(position.top_right, columns=2, rows=7, border_width=1)

// Function to update table
updateTable() =>
    s_expiry = str.tostring(i_expiry)  // Convert input string to simple string
    callSymbol = generateOptionSymbol(underlyingTicker, s_expiry, atmStrike, "C")
    putSymbol = generateOptionSymbol(underlyingTicker, s_expiry, atmStrike, "P")
    
    table.cell(dashboardTable, 0, 0, "Underlying", bgcolor=color.new(color.blue, 70), text_color=color.white)
    table.cell(dashboardTable, 1, 0, underlying, text_color=color.white)
    
    table.cell(dashboardTable, 0, 1, "ATM Strike", bgcolor=color.new(color.blue, 70), text_color=color.white)
    table.cell(dashboardTable, 1, 1, str.tostring(atmStrike), text_color=color.white)
    
    table.cell(dashboardTable, 0, 2, "Call Symbol", bgcolor=color.new(color.green, 70), text_color=color.white)
    table.cell(dashboardTable, 1, 2, callSymbol, text_color=color.white)
    
    table.cell(dashboardTable, 0, 3, "Put Symbol", bgcolor=color.new(color.red, 70), text_color=color.white)
    table.cell(dashboardTable, 1, 3, putSymbol, text_color=color.white)
    
    table.cell(dashboardTable, 0, 4, "Call Premium", bgcolor=color.new(color.green, 70), text_color=color.white)
    table.cell(dashboardTable, 1, 4, str.tostring(callPrice), text_color=color.white)
    
    table.cell(dashboardTable, 0, 5, "Put Premium", bgcolor=color.new(color.red, 70), text_color=color.white)
    table.cell(dashboardTable, 1, 5, str.tostring(putPrice), text_color=color.white)
    
    table.cell(dashboardTable, 0, 6, "Straddle Price", bgcolor=color.new(color.purple, 70), text_color=color.white)
    table.cell(dashboardTable, 1, 6, str.tostring(straddlePrice), text_color=color.white)

// Update table on every bar
updateTable()

How to Use the Dashboard

1. Adding the Script to TradingView

• Copy the Code:

• Copy the entire script provided above.

• Create a New Strategy:

• In TradingView, go to Pine Editor at the bottom of the screen.

• Paste the code into the editor.

• Save and Add to Chart:

• Click Save and give it a name (e.g., “Option Straddle Dashboard”).

• Click Add to Chart.

2. Configuring the Inputs

• Access Settings:

• Click on the gear icon next to the script name in the Indicators panel.

• Set the Underlying Symbol:

• Ensure the symbol matches the underlying asset you’re interested in (e.g., NSE:NIFTY).

• Set the Expiry Date:

• Enter the option expiry date in YYMMDD format (e.g., 240926 for September 26, 2024).

• Set the Strike Interval:

• Adjust the strike interval if necessary (common intervals are 50, 100, etc.).

3. Viewing the Dashboard

• Dashboard Location:

• The dashboard appears on the top-right corner of your chart.

• Interpreting the Data:

• Underlying: The asset you’re analyzing.

• ATM Strike: The strike price closest to the current price.

• Call/Put Symbols: The option symbols for the ATM strike.

• Call/Put Premiums: The current premiums for the call and put options.

• Straddle Price: The total cost of entering the straddle position.

Practical Applications

• Real-Time Decision Making:

• Monitor the cost of entering a straddle in real-time.

• Assess whether the straddle strategy is viable based on current premiums.

• Volatility Analysis:

• The straddle price can serve as an indicator of market volatility expectations.

• Educational Tool:

• Understand how option premiums change with the underlying price movements.


Creating a dynamic option straddle dashboard in TradingView using Pine Script v5 empowers traders to make informed decisions quickly. By leveraging real-time data and Pine Script’s capabilities, you can customize tools to fit your trading strategies.

Rajandran R Creator of OpenAlgo Sketchmaker, RagZ. Building GenAI Applications. Telecom Engineer turned Full-time Derivative Trader. Mostly Trading Nifty, Banknifty, High Liquid Stock Derivatives. Trading the Markets Since 2006 onwards. Using Market Profile and Orderflow for more than a decade. Designed and published 100+ open source trading systems on various trading tools. Now the recent curiosity on building Trading AI Agents.

Leave a Reply

Get Notifications, Alerts on Market Updates, Trading Tools, Automation & More