# %CTM_Chande_Trend_Meter Scan ported in TSL by Mobius per request
#declare lower;
def h = high;
def l = low;
def c = close;
script Scale {
input c = close;
input Min = 0;
input Max = 100;
def hh = HighestAll(c);
def ll = LowestAll(c);
plot Range = (((Max - Min) * (c - ll)) / (hh - ll)) + Min;
}
script BB
{
input price = close;
input length = 20;
def avg = Average(price, length);
def sd = StDev(price, length);
def upperBand = avg + (2 * sd);
def lowerBand = avg - (2 * sd);
plot PercentB = (price - lowerBand) / (upperBand - lowerBand) * 10;
}
def BB20H = BB(h, 20);
def BB20L = BB(l, 20);
def BB20C = BB(c, 20);
def BB50H = BB(h, 50);
def BB50L = BB(l, 50);
def BB50C = BB(c, 50);
def BB75H = BB(h, 75);
def BB75L = BB(l, 75);
def BB75C = BB(c, 75);
def BB100H = BB(h, 100);
def BB100L = BB(l, 100);
def BB100C = BB(c, 100);
def zScore = ((c - Average(c, 100)) / StDev(c, 100)) * 10;
def RSI = RSI() / 10;
def PriceChannel = ((c - Lowest(l, 2)) / (Highest(h, 2) - Lowest(l, 2))) * 10;
def sum = BB20H + BB20L + BB20C + BB50H + BB50L + BB50C + BB75H + BB75L + BB75C + BB100H + BB100L + BB100C + zScore + RSI + PriceChannel;
plot CTM = scale(sum);
#plot "90" = if isNaN(c) then double.nan else 90;
#plot "80" = if isNaN(c) then double.nan else 80;
#plot "60" = if isNaN(c) then double.nan else 60;
#plot "20" = if isNaN(c) then double.nan else 20;
# End Code CTM