PROTECTED SOURCE SCRIPT

Auto Option Premium Viewer - csgnanam

6
That's a great idea! Clear documentation is key for anyone using your script. Since your selected code block is the dedicated space for documentation, I'll provide an explanation tailored for that context, covering the main features of your "Auto Option Premium Viewer" Canvas.

Here is a detailed explanation of the script's core functionality, which you can use in your Canvas description or in a separate document to help users understand it.

I will not edit the Canvas itself, as you requested a separate explanation.

***

### Explanation of the "Auto Option Premium Viewer" Canvas

This Pine Script indicator, **"Auto Option Premium Viewer — Full Auto Symbols (NSE format, improved detection),"** is designed to automatically fetch and display the At-The-Money (ATM) Call and Put option premiums for major NSE indices (NIFTY, BANKNIFTY, MIDCPNIFTY, FINNIFTY) in real-time.

The primary goal is to provide a single, clean chart overlay showing the total premium (CE + PE) for the options closest to the current spot price, without requiring the user to manually enter strike prices or steps.

#### 1. Automatic Index Detection (`AUTO` Functionality)

* **Smart Underlying Detection:** The script attempts to automatically detect the index you are currently viewing (`activeUnderlying`). For example, if your chart is set to `BANKNIFTY`, the indicator automatically focuses on Bank Nifty options.
* **Spot Ticker Mapping (The Fix):** To accurately find the spot price, the script uses a helper function (`getSpotTicker`) to map the common index name (like `FINNIFTY`) to the specific underlying ticker required by TradingView (like `CNXFINANCE` or `NIFTY_MID_SELECT`). This ensures accurate price referencing for ATM calculation across all indices.

#### 2. Fully Automated Strike & Step Sizing

* **No Base Strike Inputs:** The script dynamically calculates the At-The-Money (ATM) strike price based on the live spot price of the underlying index.
* **Fixed Strike Steps:** The strike increment (`current_step`) is hardcoded based on market conventions:
* **100:** NIFTY, BANKNIFTY, FINNIFTY
* **50:** MIDCPNIFTY
* **Dynamic ATM Calculation:** The live spot price is rounded to the nearest valid strike based on the correct step size. This automatically determines the central strike (B), along with the adjacent strikes (A and C) to ensure the fetched data is always relevant.

#### 3. Data Fetching and Display

* **Symbol Construction:** The `buildSymbol` function creates the exact NSE option symbol string (e.g., `NSE:NIFTY251028C26000`) required by the `request.security` function.
* **Option Price Request:** The script uses `request.security` to fetch the closing price (`close`) of the Call and Put options for the three relevant strikes (A, B, C) on a fixed **5-minute** timeframe (`dataTF`).
* **Plots:** The indicator displays three lines on the chart's lower panel:
1. **ATM CE Premium:** The price of the Call option closest to ATM.
2. **ATM PE Premium:** The price of the Put option closest to ATM.
3. **ATM Total Premium:** The sum of CE + PE, often used as a proxy for the minimum expected range or implied volatility.

This automatic setup makes the Canvas extremely efficient for quick analysis without needing to manually adjust any numerical settings.

Haftungsausschluss

Die Informationen und Veröffentlichungen sind nicht als Finanz-, Anlage-, Handels- oder andere Arten von Ratschlägen oder Empfehlungen gedacht, die von TradingView bereitgestellt oder gebilligt werden, und stellen diese nicht dar. Lesen Sie mehr in den Nutzungsbedingungen.