This is the pine script which calculate the nifty 50 .
Take each stock contribute to nifty 50 and find it's .
Multiply the same with contribution percentage of the same on Nifty 50
Add up all of them and find the total .
I took the open source code from @daytraderph script called, Custom
I will make sure I will update the contribution percentage of all stocks my self instead o you update using input methods. This is the difference. Some people don't know where to look at this to update the value, so for them this script might be useful. And this is the only difference comparing to Custom script.
In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in a publication is governed by House Rules. You can favorite it to use it on a chart.