# Chande_Trend_Meter
# BY;
declare lower;
input ma1Len = 10;
input ma2Len = 20;
input ma3Len = 50;
input ma4Len = 100;
input ma5Len = 200;
DefineGlobalColor("Lime", CreateColor(0, 255, 0));
DefineGlobalColor("Green", CreateColor(0, 170, 0));
DefineGlobalColor("Orange", CreateColor(255, 165, 0));
DefineGlobalColor("Red", CreateColor(220, 0, 0));
DefineGlobalColor("Maroon", CreateColor(128, 0, 0));
DefineGlobalColor("Gray", CreateColor(130, 130, 130));
def ma1 = Average(close, ma1Len);
def ma2 = Average(close, ma2Len);
def ma3 = Average(close, ma3Len);
def ma4 = Average(close, ma4Len);
def ma5 = Average(close, ma5Len);
# Price Position Score
def priceScore =
(if close > ma1 then 20 else 0) +
(if close > ma2 then 20 else 0) +
(if close > ma3 then 20 else 0) +
(if close > ma4 then 20 else 0) +
(if close > ma5 then 20 else 0);
# MA Slope Score
def slopeScore =
(if ma1 > ma1[1] then 20 else 0) +
(if ma2 > ma2[1] then 20 else 0) +
(if ma3 > ma3[1] then 20 else 0) +
(if ma4 > ma4[1] then 20 else 0) +
(if ma5 > ma5[1] then 20 else 0);
# MA Alignment Score
def alignScore =
(if ma1 > ma2 then 25 else 0) +
(if ma2 > ma3 then 25 else 0) +
(if ma3 > ma4 then 25 else 0) +
(if ma4 > ma5 then 25 else 0);
def CTMValue = (priceScore + slopeScore + alignScore) / 3;
plot CTM = CTMValue;
CTM.SetLineWeight(2);
CTM.AssignValueColor(
if CTMValue >= 80 then GlobalColor("Lime")
else if CTMValue >= 60 then GlobalColor("Green")
else if CTMValue >= 40 then GlobalColor("Orange")
else if CTMValue >= 20 then GlobalColor("Red")
else GlobalColor("Maroon")
);
plot StrongBull = 80;
StrongBull.SetDefaultColor(GlobalColor("Green"));
StrongBull.SetStyle(Curve.SHORT_DASH);
plot Neutral = 50;
Neutral.SetDefaultColor(GlobalColor("Gray"));
Neutral.SetStyle(Curve.SHORT_DASH);
plot StrongBear = 20;
StrongBear.SetDefaultColor(GlobalColor("Red"));
StrongBear.SetStyle(Curve.SHORT_DASH);
plot ZeroLine = 0;
ZeroLine.SetDefaultColor(GlobalColor("Gray"));
ZeroLine.HideBubble();
plot HundredLine = 100;
HundredLine.SetDefaultColor(GlobalColor("Gray"));
HundredLine.HideBubble();
AddCloud(
if CTMValue >= 50 then HundredLine else Double.NaN,
if CTMValue >= 50 then ZeroLine else Double.NaN,
GlobalColor("Green"),
GlobalColor("Green")
);
AddCloud(
if CTMValue < 50 then HundredLine else Double.NaN,
if CTMValue < 50 then ZeroLine else Double.NaN,
GlobalColor("Red"),
GlobalColor("Red")
);
def bullishCross = CTMValue crosses above 50;
def bearishCross = CTMValue crosses below 50;
plot BullSignal = if bullishCross then 0 else Double.NaN;
BullSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
BullSignal.SetDefaultColor(GlobalColor("Green"));
BullSignal.SetLineWeight(3);
plot BearSignal = if bearishCross then 100 else Double.NaN;
BearSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
BearSignal.SetDefaultColor(GlobalColor("Red"));
BearSignal.SetLineWeight(3);
AddLabel(
yes,
"CTM: " + Round(CTMValue, 1),
if CTMValue >= 80 then GlobalColor("Lime")
else if CTMValue >= 60 then GlobalColor("Green")
else if CTMValue >= 40 then GlobalColor("Orange")
else if CTMValue >= 20 then GlobalColor("Red")
else GlobalColor("Maroon")
);
AddLabel(
yes,
if CTMValue >= 80 then "Strong Bull"
else if CTMValue >= 60 then "Bullish"
else if CTMValue >= 40 then "Neutral / Mixed"
else if CTMValue >= 20 then "Bearish"
else "Strong Bear",
if CTMValue >= 80 then GlobalColor("Lime")
else if CTMValue >= 60 then GlobalColor("Green")
else if CTMValue >= 40 then GlobalColor("Orange")
else if CTMValue >= 20 then GlobalColor("Red")
else GlobalColor("Maroon")
);
Alert(bullishCross, "CTM crossed above 50 - bullish trend", Alert.BAR, Sound.Ding);
Alert(bearishCross, "CTM crossed below 50 - bearish trend", Alert.BAR, Sound.Bell);
# Chande Trend Meter BB
declare lower;
input bbMult = 2.0;
input rsiLen = 14;
input chanLen = 2;
input sdLen = 100;
def basis20 = Average(close, 20);
def dev20 = bbMult * StDev(close, 20);
def upper20 = basis20 + dev20;
def lower20 = basis20 - dev20;
def range20 = upper20 - lower20;
def bb20 =
if range20 > 0 then
Max(0, Min(1, (close - lower20) / range20)) * 5 +
Max(0, Min(1, (high - lower20) / range20)) * 2.5 +
Max(0, Min(1, (low - lower20) / range20)) * 2.5
else 0;
def basis50 = Average(close, 50);
def dev50 = bbMult * StDev(close, 50);
def upper50 = basis50 + dev50;
def lower50 = basis50 - dev50;
def range50 = upper50 - lower50;
def bb50 =
if range50 > 0 then
Max(0, Min(1, (close - lower50) / range50)) * 5 +
Max(0, Min(1, (high - lower50) / range50)) * 2.5 +
Max(0, Min(1, (low - lower50) / range50)) * 2.5
else 0;
def basis75 = Average(close, 75);
def dev75 = bbMult * StDev(close, 75);
def upper75 = basis75 + dev75;
def lower75 = basis75 - dev75;
def range75 = upper75 - lower75;
def bb75 =
if range75 > 0 then
Max(0, Min(1, (close - lower75) / range75)) * 5 +
Max(0, Min(1, (high - lower75) / range75)) * 2.5 +
Max(0, Min(1, (low - lower75) / range75)) * 2.5
else 0;
def basis100 = Average(close, 100);
def dev100 = bbMult * StDev(close, 100);
def upper100 = basis100 + dev100;
def lower100 = basis100 - dev100;
def range100 = upper100 - lower100;
def bb100 =
if range100 > 0 then
Max(0, Min(1, (close - lower100) / range100)) * 5 +
Max(0, Min(1, (high - lower100) / range100)) * 2.5 +
Max(0, Min(1, (low - lower100) / range100)) * 2.5
else 0;
def bbTotal = bb20 + bb50 + bb75 + bb100;
def sd = StDev(close, sdLen);
def priceChg = close - close[sdLen];
def normChg = if sd > 0 then priceChg / (sd * Sqrt(sdLen)) else 0;
def sdScore = Max(0, Min(20, (normChg + 1) * 10));
def rsiVal = RSI(length = rsiLen);
def rsiScore = Max(0, Min(20, rsiVal / 5));
def chanHigh = Highest(high[1], chanLen);
def chanLow = Lowest(low[1], chanLen);
def chanRange = chanHigh - chanLow;
def chanScore =
if close > chanHigh then 20
else if close < chanLow then 0
else if chanRange > 0 then Max(0, Min(20, ((close - chanLow) / chanRange) * 20))
else 10;
def rawCTM = bbTotal + sdScore + rsiScore + chanScore;
def ctmValue = Max(0, Min(100, rawCTM));
plot VeryStrongBull = 90;
VeryStrongBull.SetDefaultColor(Color.LIGHT_GREEN);
VeryStrongBull.SetStyle(Curve.SHORT_DASH);
plot StrongBull = 80;
StrongBull.SetDefaultColor(Color.GREEN);
StrongBull.SetStyle(Curve.SHORT_DASH);
plot WeakBull = 60;
WeakBull.SetDefaultColor(Color.CYAN);
WeakBull.SetStyle(Curve.SHORT_DASH);
plot Neutral = 50;
Neutral.SetDefaultColor(Color.GRAY);
Neutral.SetStyle(Curve.SHORT_DASH);
plot BearLine = 20;
BearLine.SetDefaultColor(Color.RED);
BearLine.SetStyle(Curve.SHORT_DASH);
plot CTMLine = ctmValue;
CTMLine.SetLineWeight(2);
CTMLine.AssignValueColor(
if ctmValue >= 90 then Color.LIME
else if ctmValue >= 80 then Color.GREEN
else if ctmValue >= 60 then Color.CYAN
else if ctmValue >= 20 then Color.ORANGE
else Color.RED
);
AddCloud(
if ctmValue >= 50 then 100 else Double.NaN,
if ctmValue >= 50 then 0 else Double.NaN,
Color.DARK_GREEN,
Color.DARK_GREEN
);
AddCloud(
if ctmValue < 50 then 100 else Double.NaN,
if ctmValue < 50 then 0 else Double.NaN,
Color.DARK_RED,
Color.DARK_RED
);
def bullishCross = ctmValue crosses above 80;
def bearishCross = ctmValue crosses below 20;
plot BullSignal = if bullishCross then 0 else Double.NaN;
BullSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
BullSignal.SetDefaultColor(Color.GREEN);
BullSignal.SetLineWeight(2);
plot BearSignal = if bearishCross then 100 else Double.NaN;
BearSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
BearSignal.SetDefaultColor(Color.RED);
BearSignal.SetLineWeight(2);
AddLabel(
yes,
"CTM: " + Round(ctmValue, 1),
if ctmValue >= 90 then Color.LIME
else if ctmValue >= 80 then Color.GREEN
else if ctmValue >= 60 then Color.CYAN
else if ctmValue >= 20 then Color.ORANGE
else Color.RED
);
Alert(bullishCross, "CTM crossed above 80 — strong uptrend", Alert.BAR, Sound.Ding);
Alert(bearishCross, "CTM crossed below 20 — strong downtrend", Alert.BAR, Sound.Ding);
# Chande Trend Meter CTM
# StockCharts-Style
declare lower;
input bbMult = 2.0;
input rsiLen = 14;
input chanLen = 2;
input sdLen = 100;
input showBackgroundZones = yes;
input showSignals = yes;
input showLabel = yes;
# ─────────────────────────────
# Bollinger Band Scores
# ─────────────────────────────
def basis20 = Average(close, 20);
def dev20 = bbMult * StDev(close, 20);
def upper20 = basis20 + dev20;
def lower20 = basis20 - dev20;
def range20 = upper20 - lower20;
def bb20 =
if range20 > 0 then
Max(0, Min(1, (close - lower20) / range20)) * 5 +
Max(0, Min(1, (high - lower20) / range20)) * 2.5 +
Max(0, Min(1, (low - lower20) / range20)) * 2.5
else 0;
def basis50 = Average(close, 50);
def dev50 = bbMult * StDev(close, 50);
def upper50 = basis50 + dev50;
def lower50 = basis50 - dev50;
def range50 = upper50 - lower50;
def bb50 =
if range50 > 0 then
Max(0, Min(1, (close - lower50) / range50)) * 5 +
Max(0, Min(1, (high - lower50) / range50)) * 2.5 +
Max(0, Min(1, (low - lower50) / range50)) * 2.5
else 0;
def basis75 = Average(close, 75);
def dev75 = bbMult * StDev(close, 75);
def upper75 = basis75 + dev75;
def lower75 = basis75 - dev75;
def range75 = upper75 - lower75;
def bb75 =
if range75 > 0 then
Max(0, Min(1, (close - lower75) / range75)) * 5 +
Max(0, Min(1, (high - lower75) / range75)) * 2.5 +
Max(0, Min(1, (low - lower75) / range75)) * 2.5
else 0;
def basis100 = Average(close, 100);
def dev100 = bbMult * StDev(close, 100);
def upper100 = basis100 + dev100;
def lower100 = basis100 - dev100;
def range100 = upper100 - lower100;
def bb100 =
if range100 > 0 then
Max(0, Min(1, (close - lower100) / range100)) * 5 +
Max(0, Min(1, (high - lower100) / range100)) * 2.5 +
Max(0, Min(1, (low - lower100) / range100)) * 2.5
else 0;
def bbTotal = bb20 + bb50 + bb75 + bb100;
# ─────────────────────────────
# Std Dev Score
# ─────────────────────────────
def sd = StDev(close, sdLen);
def priceChg = close - close[sdLen];
def normChg = if sd > 0 then priceChg / (sd * Sqrt(sdLen)) else 0;
def sdScore = Max(0, Min(20, (normChg + 1) * 10));
# ─────────────────────────────
# RSI Score
# ─────────────────────────────
def rsiVal = RSI(length = rsiLen);
def rsiScore = Max(0, Min(20, rsiVal / 5));
# ─────────────────────────────
# Channel Breakout Score
# ─────────────────────────────
def chanHigh = Highest(high[1], chanLen);
def chanLow = Lowest(low[1], chanLen);
def chanRange = chanHigh - chanLow;
def chanScore =
if close > chanHigh then 20
else if close < chanLow then 0
else if chanRange > 0 then Max(0, Min(20, ((close - chanLow) / chanRange) * 20))
else 10;
# ─────────────────────────────
# CTM Composite
# ─────────────────────────────
def rawCTM = bbTotal + sdScore + rsiScore + chanScore;
def ctmValue = Max(0, Min(100, rawCTM));
# ─────────────────────────────
# Background Bands Like Image
# ─────────────────────────────
plot TopLine = 100;
TopLine.SetDefaultColor(Color.GRAY);
TopLine.SetStyle(Curve.SHORT_DASH);
TopLine.HideBubble();
plot L90 = 90;
L90.SetDefaultColor(Color.GRAY);
L90.SetStyle(Curve.SHORT_DASH);
L90.HideBubble();
plot L70 = 70;
L70.SetDefaultColor(Color.GRAY);
L70.SetStyle(Curve.SHORT_DASH);
L70.HideBubble();
plot L50 = 50;
L50.SetDefaultColor(Color.GRAY);
L50.SetStyle(Curve.SHORT_DASH);
L50.HideBubble();
plot L30 = 30;
L30.SetDefaultColor(Color.GRAY);
L30.SetStyle(Curve.SHORT_DASH);
L30.HideBubble();
plot L10 = 10;
L10.SetDefaultColor(Color.GRAY);
L10.SetStyle(Curve.SHORT_DASH);
L10.HideBubble();
plot BottomLine = 0;
BottomLine.SetDefaultColor(Color.GRAY);
BottomLine.SetStyle(Curve.SHORT_DASH);
BottomLine.HideBubble();
AddCloud(if showBackgroundZones then 100 else Double.NaN, 70, Color.DARK_GREEN, Color.DARK_GREEN);
AddCloud(if showBackgroundZones then 70 else Double.NaN, 50, Color.GREEN, Color.GREEN);
AddCloud(if showBackgroundZones then 50 else Double.NaN, 30, Color.YELLOW, Color.YELLOW);
AddCloud(if showBackgroundZones then 30 else Double.NaN, 0, Color.LIGHT_RED, Color.LIGHT_RED);
# ─────────────────────────────
# CTM Line
# ─────────────────────────────
plot CTMLine = ctmValue;
CTMLine.SetDefaultColor(Color.BLACK);
CTMLine.SetLineWeight(2);
# ─────────────────────────────
# Signals
# ─────────────────────────────
def bullishCross = ctmValue crosses above 80;
def bearishCross = ctmValue crosses below 20;
plot BullSignal = if showSignals and bullishCross then 5 else Double.NaN;
BullSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
BullSignal.SetDefaultColor(Color.GREEN);
BullSignal.SetLineWeight(2);
BullSignal.HideBubble();
plot BearSignal = if showSignals and bearishCross then 95 else Double.NaN;
BearSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
BearSignal.SetDefaultColor(Color.RED);
BearSignal.SetLineWeight(2);
BearSignal.HideBubble();
# ─────────────────────────────
# Label
# ─────────────────────────────
AddLabel(
showLabel,
"CTM: " + GetSymbol() + " " + Round(ctmValue, 2),
Color.LIGHT_GRAY
);
# ─────────────────────────────
# Alerts
# ─────────────────────────────
Alert(bullishCross, "CTM crossed above 80 — strong uptrend", Alert.BAR, Sound.Ding);
Alert(bearishCross, "CTM crossed below 20 — strong downtrend", Alert.BAR, Sound.Ding);
# Chande Trend Meter CTM
#
declare lower;
input bbMult = 2.0;
input rsiLen = 14;
input chanLen = 2;
input sdLen = 100;
input showSignals = yes;
input lineColorMode = {default White, Dynamic};
DefineGlobalColor("VeryBull", CreateColor(0, 80, 0));
DefineGlobalColor("Bull", CreateColor(0, 140, 0));
DefineGlobalColor("WeakBull", CreateColor(60, 180, 60));
DefineGlobalColor("Neutral", CreateColor(180, 180, 0));
DefineGlobalColor("Bear", CreateColor(180, 90, 140));
# Bollinger Score 20
def basis20 = Average(close, 20);
def dev20 = bbMult * StDev(close, 20);
def upper20 = basis20 + dev20;
def lower20 = basis20 - dev20;
def range20 = upper20 - lower20;
def bb20 =
if range20 > 0 then
Max(0, Min(1, (close - lower20) / range20)) * 5 +
Max(0, Min(1, (high - lower20) / range20)) * 2.5 +
Max(0, Min(1, (low - lower20) / range20)) * 2.5
else 0;
# Bollinger Score 50
def basis50 = Average(close, 50);
def dev50 = bbMult * StDev(close, 50);
def upper50 = basis50 + dev50;
def lower50 = basis50 - dev50;
def range50 = upper50 - lower50;
def bb50 =
if range50 > 0 then
Max(0, Min(1, (close - lower50) / range50)) * 5 +
Max(0, Min(1, (high - lower50) / range50)) * 2.5 +
Max(0, Min(1, (low - lower50) / range50)) * 2.5
else 0;
# Bollinger Score 75
def basis75 = Average(close, 75);
def dev75 = bbMult * StDev(close, 75);
def upper75 = basis75 + dev75;
def lower75 = basis75 - dev75;
def range75 = upper75 - lower75;
def bb75 =
if range75 > 0 then
Max(0, Min(1, (close - lower75) / range75)) * 5 +
Max(0, Min(1, (high - lower75) / range75)) * 2.5 +
Max(0, Min(1, (low - lower75) / range75)) * 2.5
else 0;
# Bollinger Score 100
def basis100 = Average(close, 100);
def dev100 = bbMult * StDev(close, 100);
def upper100 = basis100 + dev100;
def lower100 = basis100 - dev100;
def range100 = upper100 - lower100;
def bb100 =
if range100 > 0 then
Max(0, Min(1, (close - lower100) / range100)) * 5 +
Max(0, Min(1, (high - lower100) / range100)) * 2.5 +
Max(0, Min(1, (low - lower100) / range100)) * 2.5
else 0;
def bbTotal = bb20 + bb50 + bb75 + bb100;
# Std Dev Score
def sd = StDev(close, sdLen);
def priceChg = close - close[sdLen];
def normChg = if sd > 0 then priceChg / (sd * Sqrt(sdLen)) else 0;
def sdScore = Max(0, Min(20, (normChg + 1) * 10));
# RSI Score
def rsiVal = RSI(length = rsiLen);
def rsiScore = Max(0, Min(20, rsiVal / 5));
# Channel Score
def chanHigh = Highest(high[1], chanLen);
def chanLow = Lowest(low[1], chanLen);
def chanRange = chanHigh - chanLow;
def chanScore =
if close > chanHigh then 20
else if close < chanLow then 0
else if chanRange > 0 then Max(0, Min(20, ((close - chanLow) / chanRange) * 20))
else 10;
# Composite CTM
def rawCTM = bbTotal + sdScore + rsiScore + chanScore;
def ctm = Max(0, Min(100, rawCTM));
# Background Zones
AddCloud(100, 90, GlobalColor("VeryBull"), GlobalColor("VeryBull"));
AddCloud(90, 80, GlobalColor("Bull"), GlobalColor("Bull"));
AddCloud(80, 60, GlobalColor("WeakBull"), GlobalColor("WeakBull"));
AddCloud(60, 20, GlobalColor("Neutral"), GlobalColor("Neutral"));
AddCloud(20, 0, GlobalColor("Bear"), GlobalColor("Bear"));
# Level Lines
plot H100 = 100;
plot H90 = 90;
plot H80 = 80;
plot H60 = 60;
plot H20 = 20;
plot H0 = 0;
H100.SetDefaultColor(Color.DARK_GRAY);
H90.SetDefaultColor(Color.DARK_GRAY);
H80.SetDefaultColor(Color.DARK_GRAY);
H60.SetDefaultColor(Color.DARK_GRAY);
H20.SetDefaultColor(Color.DARK_GRAY);
H0.SetDefaultColor(Color.DARK_GRAY);
H100.SetStyle(Curve.SHORT_DASH);
H90.SetStyle(Curve.SHORT_DASH);
H80.SetStyle(Curve.SHORT_DASH);
H60.SetStyle(Curve.SHORT_DASH);
H20.SetStyle(Curve.SHORT_DASH);
H0.SetStyle(Curve.SHORT_DASH);
H100.HideBubble();
H90.HideBubble();
H80.HideBubble();
H60.HideBubble();
H20.HideBubble();
H0.HideBubble();
# CTM Line
plot CTMLine = ctm;
CTMLine.SetLineWeight(2);
CTMLine.AssignValueColor(
if lineColorMode == lineColorMode.White then Color.WHITE
else if ctm >= 90 then Color.WHITE
else if ctm >= 80 then Color.CYAN
else if ctm >= 60 then Color.GREEN
else if ctm >= 20 then Color.YELLOW
else Color.PINK
);
# Signals
def BullCross = ctm crosses above 80;
def BearCross = ctm crosses below 20;
plot BullSignal = if showSignals and BullCross then 5 else Double.NaN;
BullSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
BullSignal.SetDefaultColor(Color.GREEN);
BullSignal.SetLineWeight(3);
BullSignal.HideBubble();
plot BearSignal = if showSignals and BearCross then 95 else Double.NaN;
BearSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
BearSignal.SetDefaultColor(Color.RED);
BearSignal.SetLineWeight(3);
BearSignal.HideBubble();
# Label
AddLabel(
yes,
"CTM " + GetSymbol() + " " + Round(ctm, 2),
if ctm >= 90 then Color.GREEN
else if ctm >= 80 then Color.CYAN
else if ctm >= 60 then Color.LIGHT_GREEN
else if ctm >= 20 then Color.YELLOW
else Color.PINK
);
# Alerts
Alert(BullCross, "CTM crossed above 80", Alert.BAR, Sound.Ding);
Alert(BearCross, "CTM crossed below 20", Alert.BAR, Sound.Ding);
Join useThinkScript to post your question to a community of 21,000+ developers and traders.
Start a new thread and receive assistance from our community.
useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.
We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.
If you are new, or just looking for guidance, here are some helpful links to get you started.