german burrito
New member
I find this helpful, this is a comparative indicator found on TOS called relative strength; however, what this indicator does different it has regression channels to help gauge how much longer the difference in the strength should be or could be, i also added the 50 moving average to it because i find this helpful to see break out in strength against the /ES or SPY, however the SPY i have it comparing the DOW industrial, you may also compare the VIX and the NDAQ to the SPY, wha i see fits better is a 9 month regression lookback on the daily. a year is too much and 6 months too little, but feel free to play around with it.
Code:
declare lower;
input CorrelationWithSecurity = "SPX";
def close2 = close(CorrelationWithSecurity);
def RS = if close2 == 0 then 0 else close/close2;
input BarsBetween = 0;
# calculate the offset
def lastBar = HighestAll(if !IsNaN(close) then BarNumber() else 0);
def offset = BarsBetween * ((lastBar - BarNumber()) / (BarsBetween + 1));
# build the candle
def o;
def h;
def l;
def c;
if offset % 1 == 0
then {
o = (RS + RS[1]) / 2;
h = Max(RS, RS[1]);
l = Min(RS, RS[1]);
c = RS;
} else {
o = Double.NaN;
h = Double.NaN;
l = Double.NaN;
c = Double.NaN;
}
# just the UP candles
def UpO;
def UpH;
def UpL;
def UpC;
if o <= c
then {
UpO = o;
UpH = h;
UpL = l;
UpC = c;
} else {
UpO = Double.NaN;
UpH = Double.NaN;
UpL = Double.NaN;
UpC = Double.NaN;
}
# just the DOWN candles
def DnO;
def DnH;
def DnL;
def DnC;
if o > c
then {
DnO = o;
DnH = h;
DnL = l;
DnC = c;
} else {
DnO = Double.NaN;
DnH = Double.NaN;
DnL = Double.NaN;
DnC = Double.NaN;
}
# Plot the new Chart
AddChart(high = UpH, low = UpL, open = UpO, close = UpC, type = ChartType.CANDLE, growcolor = Color.GREEN);
AddChart(high = DnH, low = DnL, open = DnO, close = DnC, type = ChartType.CANDLE, growcolor = Color.RED);
input standardErrors = 2;
input fullRange = Yes;
input length = 21;
def regression;
def stdError;
if (fullRange) {
regression = InertiaAll(rs);
stdError = sterrAll(rs);
} else {
regression = InertiaAll(RS, length);
stdError = sterrAll(RS, length);
}
plot UpperBand = regression + standardErrors * stdError;
plot MiddleBand = regression;
plot LowerBand = regression - standardErrors * stdError;
plot UpperBand2 = regression + 1 * stdError;
plot LowerBand2 = regression - 1 * stdError;
MiddleBand.SetDefaultColor(GetColor(1));
plot ave= average(c,50);
UpperBand.AssignValueColor(color.white);
LowerBand .AssignValueColor(color.white);
UpperBand2.AssignValueColor(color.white);
LowerBand2 .AssignValueColor(color.white);
