```
# Beta with a Correlation label
# Mobius
# Chat Room discussion
# V01.01.11.2015
declare lower;
input length = 60;
input returnLength = 1;
input index = {default SPX, "Nasdaq Composite", NDX, Dow30, "Russell 2000", "/GC","/CL"};
input price = FundamentalType.CLOSE;
Assert(returnLength > 0, "'return length' must be positive: " + returnLength);
def logic;
switch (index) {
case SPX:
logic = close("SPX");
case "Nasdaq Composite":
logic = close("COMP");
case NDX:
logic = close("NDX");
case "Dow30":
logic = close("$DJI");
case "Russell 2000":
logic = close("RUT");
case "/GC":
logic = close("/GC");
case "/CL":
logic = close("/CL");
}
def c1 = close(period = AggregationPeriod.DAY);
def c2 = close(symbol = index, period = AggregationPeriod.DAY);
def primary = if c1[returnLength] == 0 then 0 else (c1 - c1[returnLength]) / c1[returnLength] * 100;
def secondary = if c2[returnLength] == 0 then 0 else (c2 - c2[returnLength]) / c2[returnLength] * 100;
plot Beta = Covariance(primary, secondary, length) / Sqr(StDev(secondary, length));
Beta.SetDefaultColor(GetColor(9));
plot corr = Correlation(c1, c2, length);
AddLabel(1, "Correlation: " + corr);#, if corr > .75 then color.green else if between(corr, 0, .75) then color.yellow else color.red);
# End Study
```