curiousOne
New member
Hi, I am trying to create a tool that would create a line for plotting the live market-cap weighted price of the top7 nasdaq companies, combined in a singe value.
Below is what i have so far, but it is not working.
Thanks in advance for any advice.
Martin
thinkscript
Below is what i have so far, but it is not working.
Thanks in advance for any advice.
Martin
thinkscript
Code:
declare lower;
input baseValue = 100;
# --- Prices ---
def AAPL = close("AAPL");
def MSFT = close("MSFT");
def NVDA = close("NVDA");
def AMZN = close("AMZN");
def META = close("META");
def GOOGL = close("GOOGL");
def TSLA = close("TSLA");
# --- Market-cap weights (approximate, sum = 1.00) ---
input wAAPL = 0.19;
input wMSFT = 0.21;
input wNVDA = 0.17;
input wAMZN = 0.14;
input wMETA = 0.11;
input wGOOGL = 0.10;
input wTSLA = 0.08;
# --- Weighted index value ---
def rawIndex =
AAPL * wAAPL +
MSFT * wMSFT +
NVDA * wNVDA +
AMZN * wAMZN +
META * wMETA +
GOOGL * wGOOGL +
TSLA * wTSLA;
# --- Normalize to baseValue at chart start ---
def base = rawIndex[GetAggregationPeriod()];
plot SyntheticIndex = (rawIndex / base) * baseValue;
SyntheticIndex.SetDefaultColor(Color.CYAN);
SyntheticIndex.SetLineWeight(2);
AddLabel(
yes,
"Nasdaq Top 7 (Mkt-Cap Weighted): " + Round(SyntheticIndex, 2),
Color.GREEN
);
Last edited by a moderator: