Correlation Indicator "Badge" ?


New member
Hey everyone,

I'm just trying to free up some screen space and want to put the correlation indicator in a badge as opposed to a plot. Anyone have anything like that already scripted?



Staff member
Not sure if this is what you're looking for.

# 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));

plot corr = Correlation(c1, c2, length);
AddLabel(1, "Correlation: " + corr);#, if corr > .75 then else if between(corr, 0, .75) then color.yellow else;

# End Study


New member
Close, I do see the Correlation Label displayed in the study. The "declare lower;" part puts the study at the bottom of the chart, I just wanted the label at the top displaying the current daily correlation to the SPX. But I think I'll play around with this code and see if I can Frankenstein something with it.


Similar threads