dscrockett
New member
This indicator in TOS calls for 2-values - Length and Return Length. Thus, in my mind, the Length equals 252; Return Length equals 30.
If correct, the 252 represents the number of bars during the period; 30 represents the number of bars as a moving average? Can anyone offer an alternative format since the TOS notes give little help? Lastly, the scan study in TOS rarely matches the chart results, offering furth befuddlement. Anyone?
If correct, the 252 represents the number of bars during the period; 30 represents the number of bars as a moving average? Can anyone offer an alternative format since the TOS notes give little help? Lastly, the scan study in TOS rarely matches the chart results, offering furth befuddlement. Anyone?
Code:
#
# Charles Schwab & Co. (c) 2007-2025
#
declare lower;
input length = 21;
input returnLength = 1;
input index = {Default SPX, "Nasdaq Composite", NDX, Dow30, "Russell 2000"};
assert(returnLength > 0, "'return length' must be positive: " + returnLength);
def primary = if close[returnLength] == 0 then 0 else (close - close[returnLength]) / close[returnLength] * 100;
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");
}
def secondary = if logic[returnLength] == 0 then 0 else (logic - logic[returnLength]) / logic[returnLength] * 100;
plot Beta = covariance(primary, secondary, length) / Sqr(stdev(secondary, length));
Beta.SetDefaultColor(GetColor(9));
Last edited by a moderator: