TradingView
scheplick
2022年4月10日下午5點32分

Make Your Own Index! 

NerdWallet, Inc.NASDAQ

描述

Intro

For my first script, I have released Make Your Own Index version 1. It has a long way to go so please stay tuned. Scroll down to read all the updates and notes as they come in.

Why it matters
Making your index is important to quickly see an index of symbols that you want to chart. Having the ability to assign weightings gives you the opportunity to make the index equal weighted or custom weighted. As we all know, indexes like the S&P 500 are NOT equal weighted, but more heavily weighted toward the winners. Now, you can make your own of a basket of symbols and make them custom weighted or equal weighted. Have some fun exploring this.

Features
You select the symbols of your choice and then chart them as one line with a specific weighting. This can be done in the settings menu once the indicator is selected. Use the symbol search field to add a symbol. From what I have tested, it works for any symbol whether it's stocks, crypto, FX and more. The default is set to stocks.

The Weight field in the settings menu is where you can assign a specific weight to the symbol of your choice. This way you can make an equal weighted index or a custom weighted index. By default each symbol is set to 10 or 10%. There are 10 symbols in the menu, so at 10%, they are equally weighted! In the script I have made it so each weighting is in percentage terms. So type in the percentage and you're good to go.

The chart is currently displayed in a separate window and not as an overlay. This may change in the future. The line can also be changed slightly and the color of it. Stay tuned for more on this.

Send in feedback
I am a Pine rookie in all regards and I am surely looking for support, feedback, and/or ideas. I want to add a lot more to this. If you look at the settings you will see have some input fields that are in their first iteration and currently needing to be improved. Rather than waiting to make them perfect, I just want to get this out there and update as I go. Also, as mentioned, I will definitely need a little support at adding more features that I have in mind.

Credit where credit is due
I used a lot of Open Source indicators as inspiration to quickly get going so thank you to the following people and accounts who share open source scripts that you can use to learn, test, and get started instantly:

@TradingView
@LucF
@PineCoders
@KioseffTrading
@norok
@RedKTrader
@NeoButane
And many others. That's the beauty of open source!

Closing note
Publishing it open source so people can fact check my code and thinking. One thing I know for sure is that this can probably be created in a more efficient way. Nonetheless, please a take look and let me know what you think - I am excited to make some updates over the coming weeks.

Thanks for reading!

發布通知

Update!

Special thanks to the Pine Code team - wow they are good! They helped me make sure I understood how to make the check boxes in the Index script work properly. The script will now calculate *only* the boxes you have checked in your settings menu. This means you can decide how many symbols you want to include. Check all 10 boxes to include the weights of 10 symbols or only check 3 boxes to make an index with just 3 checks.

More updates coming. Also, if you are using this tool at all, please let me know. I am curious if there is any value or certain things that need to be fixed or improved.

The comments section my pal Alex made a good observation about the weighting calculation. I will look to fix this or add it as a different option so you can decide the math of your weights.

發布通知

Hello friends! I made this script a few years ago, for fun, and to get into Pine Script, a product I learned to love and see immense value in since I first got started at TradingView. This script, is not perfect, and I am relying on all of you to make it better. I just fixed an important update with the calculations. Please reach out to me if you want to help me improve this – I need to add a few new features. Thanks!

發布通知

Meaningless quick update to change the default symbols: removed some inactive symbols I had as a default.
評論
WicktatorFX
Brilliant work! I needed something like this! Thank you Stef!
dgtrd
welcome to incredible pine world :-)
KioseffTrading
This is an awesome idea, seriously!

I don't know why I never saw this ping?! Maybe I don't know where to look? Haha.

AlexWe1992
Nice idea!

I am not sure the weight works as intended though.
Let's take 50% AMZN and 50% MSFT:
symcalc01*weighting_1+symcalc02*weighting_2 => 3080*1/2 + 288*1/2 = 1684
So we are giving AMZN a weight of 90% because the stockprice is higher.
Stock Price should be normalized in my opinion.
scheplick
@AlexWe1992, You are totally right! I need to fix that. Want to help? ;)
AlexWe1992
@scheplick,I think you could normalize the prices on a specific date.
I don't think there is a way the weight stays the same, when prices develop.
That is why indices typically rebalance a consistent schedule.
sokoleden
@scheplick, hi, ty for your effort.
Basically one has to "normalize" each indexvalue at a certain date (ReferenceDatePrice) vs CurrentDatePrice.
If the index should track your portfolio value, one has to manually put the time (date) and price.
If you just to create just an arbitrary own index, well this has to start at a certain date,
at least for each indexvalue must be specified a date an a price as a reference point.
ReferenceDatePrice
Also one has to determine the starting price of the index. Is it 100, 1, 1000 or whatever.
Inputs
Starting indexvalue (or -price) = START , f.e. 100
Eventually the number of decimals have to be specified. (?!? or does this Tradingview automatically, dont know?)
The number of indexvalues = NoIX, f.e. 10
The indexweight of each indexvalue = WeIX, f.e. 10%
Then the formula should be, imao,

START x (WeIX/NoIX) x (CurrentDatePrice(indexvalue1)/ReferenceDatePrice(indexvalue1))
+ START x (WeIX/NoIX) x (CurrentDatePrice(indexvalue2)/ReferenceDatePrice(indexvalue2))
+ ...

Comments welcomed
GoodShah
@scheplick,
Add 3080 + 288 = 3368
The weightage for AMZN and MSFT is 91% & 9% respectively
Require 50% for each
So price should 3368/2 = 1684 for both
Hence multiply AMZN price by (0.5/0.91) that is required weightage divided by current weight
Multiply MSFT price by (0.5/.09) that is required weightage divided by current weight
Price of both will become 1684 = 3368/2
hence having equal weight
GoodShah
@scheplick,
I had created this custom index of Indian Tyre stocks: NSE:MRF*0.3+NSE:BALKRISIND*12.5+NSE:APOLLOTYRE*64.7+NSE:CEATLTD*5.4+NSE:JKTYRE*50.9+NSE:GOODYEAR*4.6+NSE:TVSSRICHAK*1.6
I got the index generation part correct as explained in AMZN + MSFT example. But how do I name this custom index is Tyre stocks? Just bought PRO version yesterday.
更多