PROTECTED SOURCE SCRIPT
Nifty Sectoral Performance Comparison

This Pine Script indicator tracks and compares the percentage performance of Indian sectoral and thematic indices (e.g., Nifty 50, Nifty Bank, Nifty IT) relative to their starting price in a user-defined timeframe. Performance is plotted as colored lines on the chart, with transparent labels showing percentage changes. A user-configurable label offset ensures clarity. Ideal for analyzing sectoral trends in the Indian market.
Features
Multi-Index Tracking:
Monitors up to 21 indices in five groups:
Core/Large Cap: Nifty 50, Nifty Bank, Nifty Auto, Nifty IT, Nifty FMCG, Nifty Fin Services
Thematic/Sectoral: SENSEX, Nifty Healthcare, Nifty Metal, Nifty Pharma
Bank Sub-Indices & Realty: Nifty Pvt Bank, Nifty PSU Bank, Nifty Realty
Consumption & Energy: Nifty ConsDurables, Nifty Oil & Gas
MidSmall Cap Thematic: Nifty MidSmFinSrv, S&P BSE Healthcare, Nifty MidSmIT&Tel
Calculates performance as the percentage change from the first valid close in the timeframe.
Customizable Display:
Toggle each index on/off via boolean inputs.
Define ticker symbols and colors for each index (e.g., Blue for Nifty 50, Green for Nifty Fin Services).
Colors are preset but editable for clear differentiation.
Labeling:
Displays index name and performance (e.g., "Nifty 50: 12.34%") with transparent labels (no background).
Labels match the plot color and are positioned using a user-defined offset (in bars) to avoid overlap.
Precision and Timeframe:
Shows performance with two decimal places.
Supports custom timeframes (e.g., daily, weekly) for flexible analysis.
Overlay Mode:
Plots performance lines on the price chart for direct comparison with price movements.
Inputs
Label Offset (Bars): Set label position left of the current bar (default: 5, min: 0).
Show [Index]: Enable/disable each index’s plot and label.
Ticker [Index]: Specify ticker symbols (e.g., NSE:NIFTY).
Color [Index]: Choose plot and label colors.
How It Works
Performance Calculation:
Fetches closing prices via request.security for the specified ticker and timeframe.
Captures the first valid close as the starting price.
Computes performance: ((current_price / start_price) - 1) * 100.
Handles invalid data (e.g., na or zero start price) by returning na.
Plotting:
Plots enabled indices with valid performance as lines (linewidth: 1) in user-defined colors.
Labeling:
Creates labels for enabled indices with valid performance at bar_index - label_offset and the performance value.
Labels show the index name and percentage (e.g., "Auto: 5.67%") in the plot’s color, with no background.
Usage
Setup: Apply to a TradingView chart and set the desired timeframe.
Customize:
Enable relevant indices, adjust tickers, and modify colors.
Set Label Offset to position labels clearly.
Analyze:
Compare lines to spot outperforming/underperforming sectors.
Use labels for precise performance values.
Pair with price action or other indicators for trading insights.
Features
Multi-Index Tracking:
Monitors up to 21 indices in five groups:
Core/Large Cap: Nifty 50, Nifty Bank, Nifty Auto, Nifty IT, Nifty FMCG, Nifty Fin Services
Thematic/Sectoral: SENSEX, Nifty Healthcare, Nifty Metal, Nifty Pharma
Bank Sub-Indices & Realty: Nifty Pvt Bank, Nifty PSU Bank, Nifty Realty
Consumption & Energy: Nifty ConsDurables, Nifty Oil & Gas
MidSmall Cap Thematic: Nifty MidSmFinSrv, S&P BSE Healthcare, Nifty MidSmIT&Tel
Calculates performance as the percentage change from the first valid close in the timeframe.
Customizable Display:
Toggle each index on/off via boolean inputs.
Define ticker symbols and colors for each index (e.g., Blue for Nifty 50, Green for Nifty Fin Services).
Colors are preset but editable for clear differentiation.
Labeling:
Displays index name and performance (e.g., "Nifty 50: 12.34%") with transparent labels (no background).
Labels match the plot color and are positioned using a user-defined offset (in bars) to avoid overlap.
Precision and Timeframe:
Shows performance with two decimal places.
Supports custom timeframes (e.g., daily, weekly) for flexible analysis.
Overlay Mode:
Plots performance lines on the price chart for direct comparison with price movements.
Inputs
Label Offset (Bars): Set label position left of the current bar (default: 5, min: 0).
Show [Index]: Enable/disable each index’s plot and label.
Ticker [Index]: Specify ticker symbols (e.g., NSE:NIFTY).
Color [Index]: Choose plot and label colors.
How It Works
Performance Calculation:
Fetches closing prices via request.security for the specified ticker and timeframe.
Captures the first valid close as the starting price.
Computes performance: ((current_price / start_price) - 1) * 100.
Handles invalid data (e.g., na or zero start price) by returning na.
Plotting:
Plots enabled indices with valid performance as lines (linewidth: 1) in user-defined colors.
Labeling:
Creates labels for enabled indices with valid performance at bar_index - label_offset and the performance value.
Labels show the index name and percentage (e.g., "Auto: 5.67%") in the plot’s color, with no background.
Usage
Setup: Apply to a TradingView chart and set the desired timeframe.
Customize:
Enable relevant indices, adjust tickers, and modify colors.
Set Label Offset to position labels clearly.
Analyze:
Compare lines to spot outperforming/underperforming sectors.
Use labels for precise performance values.
Pair with price action or other indicators for trading insights.
Skrip dilindungi
Skrip ini diterbitkan sebagai sumber tertutup. Akan tetapi, anda boleh menggunakannya dengan percuma dan tanpa had – ketahui lebih lanjut di sini.
Penafian
Maklumat dan penerbitan adalah tidak dimaksudkan untuk menjadi, dan tidak membentuk, nasihat untuk kewangan, pelaburan, perdagangan dan jenis-jenis lain atau cadangan yang dibekalkan atau disahkan oleh TradingView. Baca dengan lebih lanjut di Terma Penggunaan.
Skrip dilindungi
Skrip ini diterbitkan sebagai sumber tertutup. Akan tetapi, anda boleh menggunakannya dengan percuma dan tanpa had – ketahui lebih lanjut di sini.
Penafian
Maklumat dan penerbitan adalah tidak dimaksudkan untuk menjadi, dan tidak membentuk, nasihat untuk kewangan, pelaburan, perdagangan dan jenis-jenis lain atau cadangan yang dibekalkan atau disahkan oleh TradingView. Baca dengan lebih lanjut di Terma Penggunaan.