Correlation Indicator "Badge" ?

Charlie.mp3

Charlie.mp3

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?

Thanks.
 
korygill

korygill

Member
VIP
Warehouse
Can you elaborate? To show the last value only as a single number in a label?
 
Charlie.mp3

Charlie.mp3

New member
Right, in the same way that you would have the ATR=2.05 or the IV=.31 etc.
I just want it as a label that reads the daily correlation to the SPX.

Thank you
 
BenTen

BenTen

Administrative
Staff
VIP
Warehouse
Not sure if this is what you're looking for.

Code:
# 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
 
Charlie.mp3

Charlie.mp3

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.

Thanks.
 

Top