Trend Speed Analyzer (Zeiierman) for ThinkOrSwim

samer800

Moderator - Expert
VIP
Lifetime
R9YakGn.png


Author MEssage:

The Trend Speed Analyzer by Zeiierman is designed to measure the strength and speed of market trends, providing traders with actionable insights into momentum dynamics. By combining a dynamic moving average with wave and speed analysis, it visually highlights shifts in trend direction, market strength, and potential reversals. This tool is ideal for identifying breakout opportunities, gauging trend consistency, and understanding the dominance of bullish or bearish forces over various timeframes.

Upper Study:
CSS:
#// Indicator for TOS
#// © Zeiierman {
#Hint MaximumLength: This parameter sets the upper limit for the number of bars considered in the dynamic moving average. A higher value smooths out the trend line, making it less reactive to minor fluctuations but slower to adapt to sudden price movements. Use higher values for long-term trend analysis and lower values for faster-moving markets.
#Hint AcceleratorMultiplier: Adjusts the responsiveness of the dynamic moving average to price changes. A larger value makes the trend more reactive but can introduce noise in choppy markets. Lower values create a smoother trend but may lag behind rapid price movements. This is particularly useful in volatile markets where precise sensitivity is needed.
#Hint CollectionPeriod: Defines the number of bars used to normalize trend speed values. A higher value includes a broader historical range, smoothing out the speed calculation. Lower values make the speed analysis more sensitive to recent price changes, ideal for short-term trading.
#indicator('Trend Speed Analyzer (Zeiierman)', overlay = false)
# Converted by Sam4Cok@Samer800    - 02/2025

input EnableTable          = yes;  # 'Enable Table'
input colorBars = yes;             # 'Enable Candles'
input source = close;
input MaximumLength = 50;          # 'Maximum Length'
input AcceleratorMultiplier = 5.0; # 'Accelerator Multiplier'
input CollectionPeriod = 100;      # 'Collection Period'

def na = Double.NaN;
def last = IsNaN(close);

#// ~~  Dynamic Average {
def max_abs_counts_diff = Highest(source, 200);
def counts_diff_norm    = (source + max_abs_counts_diff) / (2 * max_abs_counts_diff);
def dyn_length          = 5 + counts_diff_norm * (MaximumLength - 5);

##// ~~ Gradient Coloring {
Script gradient_color {
input src = close;
input minVal = 0;
input maxVal = 1;
input loR = 173;
input loG = 216;
input loB = 230;
input hiR = 41;
input hiG = 98;
input hiB = 255;
    def value = if isNaN(src) then 0 else src;
    def clamped_value = max(min(value, maxVal), minVal);
    def normalized_value = (clamped_value - minVal) / (maxVal - minVal);
    def re = floor(loR + (hiR - loR) * normalized_value);
    def gr = floor(loG + (hiG - loG) * normalized_value);
    def bl = floor(loB + (hiB - loB) * normalized_value);
    plot r = re;
    plot g = gr;
    plot b = bl;
}

Script calc_accel_factor {
input counts_diff = close;
input prev_counts_diff = close;
    def delta_counts_diff = AbsValue(counts_diff - prev_counts_diff);
    def max_delta = highest(delta_counts_diff, 200);
    def max_delta_counts_diff = if max_delta == 0 then 1 else max_delta;
    def accel_factor = delta_counts_diff / max_delta_counts_diff;
    plot out = accel_factor;
}
Script adjust_alpha {
input dyn_length = 1;
input accel_factor = 1;
input accel_multiplier = 5;
    def alpha_base = 2 / (dyn_length + 1);
    def alpha_ = alpha_base * (1 + accel_factor * accel_multiplier);
    def alpha = min(1, alpha_); #  // Ensure alpha does not exceed 1
    plot out = alpha;
}
#// ~~ Accelerator Factor
def accel_factor = calc_accel_factor(source, source[1]);
def alpha        = adjust_alpha(dyn_length, accel_factor, AcceleratorMultiplier);
#// ~~ Compute dynamic Ema
def dyn_ema = if isNaN(dyn_ema[1]) then close else if !dyn_ema[1] then close else alpha * close + (1 - alpha) * dyn_ema[1];

#// ~~ Trend Speed {
def trend = dyn_ema;
def c = WildersAverage(close, 10);
def o = WildersAverage(open, 10);

#// ~~ Trend direction {
def speed; def speed1; def xBear; def xBull;
def bullish; def bearish; def bearish_recent; def bullish_recent;
def maxx; def minn;
if  (close > trend and close[1] <= trend) {
    bearish = Min(if !bearish[1] then c - o else bearish[1], (if !minn[1] then c - o else minn[1]));
    bearish_recent = bearish_recent[1] + (if !minn[1] then c - o else minn[1]);
    bullish_recent = bullish_recent[1];
    bullish = bullish[1];
    xBear   = xBear[1] + 1;
    xBull   = xBull[1];
    speed1 = c - o;
    minn = if !minn[1] then speed1 else minn[1];
    maxx = Max(speed1, maxx[1]);
} else if (close < trend and close[1] >= trend) {
    bullish = Max(bullish[1], (if !maxx[1] then c - o else maxx[1]));
    bearish = if !bearish[1] then c - o else bearish[1];
    bearish_recent = bearish_recent[1];
    bullish_recent = bullish_recent[1] + (if !maxx[1] then c - o else maxx[1]);
    xBear   = xBear[1];
    xBull   = xBull[1] + 1;
    speed1 = c - o;
    minn = if !minn[1] then speed1 else Min(minn[1], speed1);
    maxx = maxx[1];
} else {
    bearish = if !bearish[1] then c - o else bearish[1];
    bullish = if !bullish[1] then c - o else bullish[1];
    bearish_recent = bearish_recent[1];
    bullish_recent = bullish_recent[1];
    xBear = xBear[1];
    xBull = xBull[1];
    speed1 = speed[1];
    minn = if !minn[1] then speed1 else if close < trend then Min(minn[1], speed1) else minn[1];
    maxx = if close > trend then Max(maxx[1], speed1) else maxx[1];
}
speed = speed1 + c - o;

#Color
def min_speed = lowest(speed, CollectionPeriod);
def max_speed = highest(speed, CollectionPeriod);
def normalized_speed = (speed - min_speed) / (max_speed - min_speed);
def rDn = gradient_color(normalized_speed, 0, 0.5, 255, 0, 0, 249, 164, 164).r;
def gDn = gradient_color(normalized_speed, 0, 0.5, 255, 0, 0, 249, 164, 164).g;
def bDn = gradient_color(normalized_speed, 0, 0.5, 255, 0, 0, 249, 164, 164).b;
def rUp = gradient_color(normalized_speed, 0.5, 1, 156, 255, 207, 0, 255, 0).r;
def gUp = gradient_color(normalized_speed, 0.5, 1, 156, 255, 207, 0, 255, 0).g;
def bUp = gradient_color(normalized_speed, 0.5, 1, 156, 255, 207, 0, 255, 0).b;


# -- plot

plot DynamicEMA = if !last then dyn_ema else na;
DynamicEMA.SetLineWeight(2);
DynamicEMA.AssignValueColor(if speed < 0 then CreateColor(rDn, gDn, bDn) else CreateColor(rUp, gUp, bUp));

#-- Bar Color
AssignPriceColor(if !colorBars then Color.CURRENT else
                 if speed < 0 then CreateColor(rDn, gDn, bDn) else CreateColor(rUp, gUp, bUp));

#// ~~ Table {
#// Calculate stats
def bull_max = highest(bullish, 200);
def bear_max = lowest(bearish, 200);
def bull_avg = bullish_recent / xBull;
def bear_avg = bearish_recent / xBear;
#// Calculate wave size ratios for max and average wave heights
def wave_size_ratio_avg = bull_avg / AbsValue(bear_avg);
def wave_Round_avg = Round(wave_size_ratio_avg, 2);
def wave_size_ratio_max = bull_max / AbsValue(bear_max);
def wave_Round_max = Round(wave_size_ratio_max, 2);
#// Current wave calculations
def current_wave       = speed;
def current_ratio_avg = if current_wave > 0 then current_wave / bull_avg else current_wave / AbsValue(bear_avg);
def current_ratio_max = if current_wave > 0 then current_wave / bull_max else current_wave / AbsValue(bear_max);
def current_Round_avg = Round(current_ratio_avg, 2);
def current_Round_max = Round(current_ratio_max, 2);
#// Dominance calculation
def dominance_avg_value = bull_avg - AbsValue(bear_avg);
def dominance_max_value = bull_max - AbsValue(bear_max);

AddLabel(EnableTable, "Current Wave Ratio:", Color.WHITE);
AddLabel(EnableTable, "AvgWave(" + current_Round_avg + "x)", if current_ratio_avg > 0 then Color.GREEN else Color.RED);
AddLabel(EnableTable, "MaxWave(" + current_Round_max + "x)", if current_ratio_max > 0 then Color.GREEN else Color.RED);
AddLabel(EnableTable, "Dominance:", Color.WHITE);
AddLabel(EnableTable, "AvgWave(" + if dominance_avg_value > 0 then "Bullish +" + wave_Round_avg + "x" else
         "Bearish -" + Round(1 / wave_size_ratio_avg, 2) + "x)", if dominance_avg_value>0 then Color.GREEN else Color.RED);
AddLabel(EnableTable, "MaxWave(" + if dominance_max_value > 0 then "Bullish +" + wave_Round_max + "x" else
         "Bearish -" + Round(1 / wave_size_ratio_max, 2) + "x)", if dominance_max_value>0 then Color.GREEN else Color.RED);


#-- END of CODE

Lower Study:

CSS:
#// Indicator for TOS
#// © Zeiierman
#Hint MaximumLength: This parameter sets the upper limit for the number of bars considered in the dynamic moving average. A higher value smooths out the trend line, making it less reactive to minor fluctuations but slower to adapt to sudden price movements. Use higher values for long-term trend analysis and lower values for faster-moving markets.
#Hint AcceleratorMultiplier: Adjusts the responsiveness of the dynamic moving average to price changes. A larger value makes the trend more reactive but can introduce noise in choppy markets. Lower values create a smoother trend but may lag behind rapid price movements. This is particularly useful in volatile markets where precise sensitivity is needed.
#Hint CollectionPeriod: Defines the number of bars used to normalize trend speed values. A higher value includes a broader historical range, smoothing out the speed calculation. Lower values make the speed analysis more sensitive to recent price changes, ideal for short-term trading.
#indicator('Trend Speed Analyzer (Zeiierman)', overlay = false)
# Converted by Sam4Cok@Samer800    - 02/2025

declare lower;

input EnableTable          = yes;  # 'Enable Table'
input colorBars = yes;             # 'Enable Candles'
input source = close;
input MaximumLength = 50;          # 'Maximum Length'
input AcceleratorMultiplier = 5.0; # 'Accelerator Multiplier'
input CollectionPeriod = 100;      # 'Collection Period'

def na = Double.NaN;
def last = IsNaN(close);

#// ~~  Dynamic Average {
def max_abs_counts_diff = Highest(source, 200);
def counts_diff_norm    = (source + max_abs_counts_diff) / (2 * max_abs_counts_diff);
def dyn_length          = 5 + counts_diff_norm * (MaximumLength - 5);

##// ~~ Gradient Coloring {
Script gradient_color {
input src = close;
input minVal = 0;
input maxVal = 1;
input loR = 173;
input loG = 216;
input loB = 230;
input hiR = 41;
input hiG = 98;
input hiB = 255;
    def value = if isNaN(src) then 0 else src;
    def clamped_value = max(min(value, maxVal), minVal);
    def normalized_value = (clamped_value - minVal) / (maxVal - minVal);
    def re = floor(loR + (hiR - loR) * normalized_value);
    def gr = floor(loG + (hiG - loG) * normalized_value);
    def bl = floor(loB + (hiB - loB) * normalized_value);
    plot r = re;
    plot g = gr;
    plot b = bl;
}

Script calc_accel_factor {
input counts_diff = close;
input prev_counts_diff = close;
    def delta_counts_diff = AbsValue(counts_diff - prev_counts_diff);
    def max_delta = highest(delta_counts_diff, 200);
    def max_delta_counts_diff = if max_delta == 0 then 1 else max_delta;
    def accel_factor = delta_counts_diff / max_delta_counts_diff;
    plot out = accel_factor;
}
Script adjust_alpha {
input dyn_length = 1;
input accel_factor = 1;
input accel_multiplier = 5;
    def alpha_base = 2 / (dyn_length + 1);
    def alpha_ = alpha_base * (1 + accel_factor * accel_multiplier);
    def alpha = min(1, alpha_); #  // Ensure alpha does not exceed 1
    plot out = alpha;
}
#// ~~ Accelerator Factor
def accel_factor = calc_accel_factor(source, source[1]);
def alpha        = adjust_alpha(dyn_length, accel_factor, AcceleratorMultiplier);
#// ~~ Compute dynamic Ema
def dyn_ema = if isNaN(dyn_ema[1]) then close else if !dyn_ema[1] then close else alpha * close + (1 - alpha) * dyn_ema[1];

#// ~~ Trend Speed {
def trend = dyn_ema;
def c = WildersAverage(close, 10);
def o = WildersAverage(open, 10);

#// ~~ Trend direction {
def speed; def speed1; def xBear; def xBull;
def bullish; def bearish; def bearish_recent; def bullish_recent;
def maxx; def minn;
if  (close > trend and close[1] <= trend) {
    bearish = Min(if !bearish[1] then c - o else bearish[1], (if !minn[1] then c - o else minn[1]));
    bearish_recent = bearish_recent[1] + (if !minn[1] then c - o else minn[1]);
    bullish_recent = bullish_recent[1];
    bullish = bullish[1];
    xBear   = xBear[1] + 1;
    xBull   = xBull[1];
    speed1 = c - o;
    minn = if !minn[1] then speed1 else minn[1];
    maxx = Max(speed1, maxx[1]);
} else if (close < trend and close[1] >= trend) {
    bullish = Max(bullish[1], (if !maxx[1] then c - o else maxx[1]));
    bearish = if !bearish[1] then c - o else bearish[1];
    bearish_recent = bearish_recent[1];
    bullish_recent = bullish_recent[1] + (if !maxx[1] then c - o else maxx[1]);
    xBear   = xBear[1];
    xBull   = xBull[1] + 1;
    speed1 = c - o;
    minn = if !minn[1] then speed1 else Min(minn[1], speed1);
    maxx = maxx[1];
} else {
    bearish = if !bearish[1] then c - o else bearish[1];
    bullish = if !bullish[1] then c - o else bullish[1];
    bearish_recent = bearish_recent[1];
    bullish_recent = bullish_recent[1];
    xBear = xBear[1];
    xBull = xBull[1];
    speed1 = speed[1];
    minn = if !minn[1] then speed1 else if close < trend then Min(minn[1], speed1) else minn[1];
    maxx = if close > trend then Max(maxx[1], speed1) else maxx[1];
}
speed = speed1 + c - o;
def trendspeed = HullMovingAvg(speed, 5);

#Color
def min_speed = lowest(speed, CollectionPeriod);
def max_speed = highest(speed, CollectionPeriod);
def normalized_speed = (speed - min_speed) / (max_speed - min_speed);
def rDn = gradient_color(normalized_speed, 0, 0.5, 255, 0, 0, 249, 164, 164).r;
def gDn = gradient_color(normalized_speed, 0, 0.5, 255, 0, 0, 249, 164, 164).g;
def bDn = gradient_color(normalized_speed, 0, 0.5, 255, 0, 0, 249, 164, 164).b;
def rUp = gradient_color(normalized_speed, 0.5, 1, 156, 255, 207, 0, 255, 0).r;
def gUp = gradient_color(normalized_speed, 0.5, 1, 156, 255, 207, 0, 255, 0).g;
def bUp = gradient_color(normalized_speed, 0.5, 1, 156, 255, 207, 0, 255, 0).b;


# -- plot

plot DynamicEMA = if !last then trendspeed else na;
DynamicEMA.SetLineWeight(3);
DynamicEMA.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
DynamicEMA.AssignValueColor(if speed < 0 then CreateColor(rDn, gDn, bDn) else CreateColor(rUp, gUp, bUp));
AssignPriceColor(if !colorBars then Color.CURRENT else
                 if speed < 0 then CreateColor(rDn, gDn, bDn) else CreateColor(rUp, gUp, bUp));

#// ~~ Table {
#// Calculate stats
def bull_max = highest(bullish, 200);
def bear_max = lowest(bearish, 200);
def bull_avg = bullish_recent / xBull;
def bear_avg = bearish_recent / xBear;
#// Calculate wave size ratios for max and average wave heights
def wave_size_ratio_avg = bull_avg / AbsValue(bear_avg);
def wave_Round_avg = Round(wave_size_ratio_avg, 2);
def wave_size_ratio_max = bull_max / AbsValue(bear_max);
def wave_Round_max = Round(wave_size_ratio_max, 2);
#// Current wave calculations
def current_wave       = speed;
def current_ratio_avg = if current_wave > 0 then current_wave / bull_avg else current_wave / AbsValue(bear_avg);
def current_ratio_max = if current_wave > 0 then current_wave / bull_max else current_wave / AbsValue(bear_max);
def current_Round_avg = Round(current_ratio_avg, 2);
def current_Round_max = Round(current_ratio_max, 2);
#// Dominance calculation
def dominance_avg_value = bull_avg - AbsValue(bear_avg);
def dominance_max_value = bull_max - AbsValue(bear_max);

AddLabel(EnableTable, "Current Wave Ratio:", Color.WHITE);
AddLabel(EnableTable, "AvgWave(" + current_Round_avg + "x)", if current_ratio_avg > 0 then Color.GREEN else Color.RED);
AddLabel(EnableTable, "MaxWave(" + current_Round_max + "x)", if current_ratio_max > 0 then Color.GREEN else Color.RED);
AddLabel(EnableTable, "Dominance:", Color.WHITE);
AddLabel(EnableTable, "AvgWave(" + if dominance_avg_value > 0 then "Bullish +" + wave_Round_avg + "x" else
         "Bearish -" + Round(1 / wave_size_ratio_avg, 2) + "x)", if dominance_avg_value>0 then Color.GREEN else Color.RED);
AddLabel(EnableTable, "MaxWave(" + if dominance_max_value > 0 then "Bullish +" + wave_Round_max + "x" else
         "Bearish -" + Round(1 / wave_size_ratio_max, 2) + "x)", if dominance_max_value>0 then Color.GREEN else Color.RED);


#-- END of CODE
 
R9YakGn.png


Author MEssage:

The Trend Speed Analyzer by Zeiierman is designed to measure the strength and speed of market trends, providing traders with actionable insights into momentum dynamics. By combining a dynamic moving average with wave and speed analysis, it visually highlights shifts in trend direction, market strength, and potential reversals. This tool is ideal for identifying breakout opportunities, gauging trend consistency, and understanding the dominance of bullish or bearish forces over various timeframes.

Upper Study:
CSS:
#// Indicator for TOS
#// © Zeiierman {
#Hint MaximumLength: This parameter sets the upper limit for the number of bars considered in the dynamic moving average. A higher value smooths out the trend line, making it less reactive to minor fluctuations but slower to adapt to sudden price movements. Use higher values for long-term trend analysis and lower values for faster-moving markets.
#Hint AcceleratorMultiplier: Adjusts the responsiveness of the dynamic moving average to price changes. A larger value makes the trend more reactive but can introduce noise in choppy markets. Lower values create a smoother trend but may lag behind rapid price movements. This is particularly useful in volatile markets where precise sensitivity is needed.
#Hint CollectionPeriod: Defines the number of bars used to normalize trend speed values. A higher value includes a broader historical range, smoothing out the speed calculation. Lower values make the speed analysis more sensitive to recent price changes, ideal for short-term trading.
#indicator('Trend Speed Analyzer (Zeiierman)', overlay = false)
# Converted by Sam4Cok@Samer800    - 02/2025

input EnableTable          = yes;  # 'Enable Table'
input colorBars = yes;             # 'Enable Candles'
input source = close;
input MaximumLength = 50;          # 'Maximum Length'
input AcceleratorMultiplier = 5.0; # 'Accelerator Multiplier'
input CollectionPeriod = 100;      # 'Collection Period'

def na = Double.NaN;
def last = IsNaN(close);

#// ~~  Dynamic Average {
def max_abs_counts_diff = Highest(source, 200);
def counts_diff_norm    = (source + max_abs_counts_diff) / (2 * max_abs_counts_diff);
def dyn_length          = 5 + counts_diff_norm * (MaximumLength - 5);

##// ~~ Gradient Coloring {
Script gradient_color {
input src = close;
input minVal = 0;
input maxVal = 1;
input loR = 173;
input loG = 216;
input loB = 230;
input hiR = 41;
input hiG = 98;
input hiB = 255;
    def value = if isNaN(src) then 0 else src;
    def clamped_value = max(min(value, maxVal), minVal);
    def normalized_value = (clamped_value - minVal) / (maxVal - minVal);
    def re = floor(loR + (hiR - loR) * normalized_value);
    def gr = floor(loG + (hiG - loG) * normalized_value);
    def bl = floor(loB + (hiB - loB) * normalized_value);
    plot r = re;
    plot g = gr;
    plot b = bl;
}

Script calc_accel_factor {
input counts_diff = close;
input prev_counts_diff = close;
    def delta_counts_diff = AbsValue(counts_diff - prev_counts_diff);
    def max_delta = highest(delta_counts_diff, 200);
    def max_delta_counts_diff = if max_delta == 0 then 1 else max_delta;
    def accel_factor = delta_counts_diff / max_delta_counts_diff;
    plot out = accel_factor;
}
Script adjust_alpha {
input dyn_length = 1;
input accel_factor = 1;
input accel_multiplier = 5;
    def alpha_base = 2 / (dyn_length + 1);
    def alpha_ = alpha_base * (1 + accel_factor * accel_multiplier);
    def alpha = min(1, alpha_); #  // Ensure alpha does not exceed 1
    plot out = alpha;
}
#// ~~ Accelerator Factor
def accel_factor = calc_accel_factor(source, source[1]);
def alpha        = adjust_alpha(dyn_length, accel_factor, AcceleratorMultiplier);
#// ~~ Compute dynamic Ema
def dyn_ema = if isNaN(dyn_ema[1]) then close else if !dyn_ema[1] then close else alpha * close + (1 - alpha) * dyn_ema[1];

#// ~~ Trend Speed {
def trend = dyn_ema;
def c = WildersAverage(close, 10);
def o = WildersAverage(open, 10);

#// ~~ Trend direction {
def speed; def speed1; def xBear; def xBull;
def bullish; def bearish; def bearish_recent; def bullish_recent;
def maxx; def minn;
if  (close > trend and close[1] <= trend) {
    bearish = Min(if !bearish[1] then c - o else bearish[1], (if !minn[1] then c - o else minn[1]));
    bearish_recent = bearish_recent[1] + (if !minn[1] then c - o else minn[1]);
    bullish_recent = bullish_recent[1];
    bullish = bullish[1];
    xBear   = xBear[1] + 1;
    xBull   = xBull[1];
    speed1 = c - o;
    minn = if !minn[1] then speed1 else minn[1];
    maxx = Max(speed1, maxx[1]);
} else if (close < trend and close[1] >= trend) {
    bullish = Max(bullish[1], (if !maxx[1] then c - o else maxx[1]));
    bearish = if !bearish[1] then c - o else bearish[1];
    bearish_recent = bearish_recent[1];
    bullish_recent = bullish_recent[1] + (if !maxx[1] then c - o else maxx[1]);
    xBear   = xBear[1];
    xBull   = xBull[1] + 1;
    speed1 = c - o;
    minn = if !minn[1] then speed1 else Min(minn[1], speed1);
    maxx = maxx[1];
} else {
    bearish = if !bearish[1] then c - o else bearish[1];
    bullish = if !bullish[1] then c - o else bullish[1];
    bearish_recent = bearish_recent[1];
    bullish_recent = bullish_recent[1];
    xBear = xBear[1];
    xBull = xBull[1];
    speed1 = speed[1];
    minn = if !minn[1] then speed1 else if close < trend then Min(minn[1], speed1) else minn[1];
    maxx = if close > trend then Max(maxx[1], speed1) else maxx[1];
}
speed = speed1 + c - o;

#Color
def min_speed = lowest(speed, CollectionPeriod);
def max_speed = highest(speed, CollectionPeriod);
def normalized_speed = (speed - min_speed) / (max_speed - min_speed);
def rDn = gradient_color(normalized_speed, 0, 0.5, 255, 0, 0, 249, 164, 164).r;
def gDn = gradient_color(normalized_speed, 0, 0.5, 255, 0, 0, 249, 164, 164).g;
def bDn = gradient_color(normalized_speed, 0, 0.5, 255, 0, 0, 249, 164, 164).b;
def rUp = gradient_color(normalized_speed, 0.5, 1, 156, 255, 207, 0, 255, 0).r;
def gUp = gradient_color(normalized_speed, 0.5, 1, 156, 255, 207, 0, 255, 0).g;
def bUp = gradient_color(normalized_speed, 0.5, 1, 156, 255, 207, 0, 255, 0).b;


# -- plot

plot DynamicEMA = if !last then dyn_ema else na;
DynamicEMA.SetLineWeight(2);
DynamicEMA.AssignValueColor(if speed < 0 then CreateColor(rDn, gDn, bDn) else CreateColor(rUp, gUp, bUp));

#-- Bar Color
AssignPriceColor(if !colorBars then Color.CURRENT else
                 if speed < 0 then CreateColor(rDn, gDn, bDn) else CreateColor(rUp, gUp, bUp));

#// ~~ Table {
#// Calculate stats
def bull_max = highest(bullish, 200);
def bear_max = lowest(bearish, 200);
def bull_avg = bullish_recent / xBull;
def bear_avg = bearish_recent / xBear;
#// Calculate wave size ratios for max and average wave heights
def wave_size_ratio_avg = bull_avg / AbsValue(bear_avg);
def wave_Round_avg = Round(wave_size_ratio_avg, 2);
def wave_size_ratio_max = bull_max / AbsValue(bear_max);
def wave_Round_max = Round(wave_size_ratio_max, 2);
#// Current wave calculations
def current_wave       = speed;
def current_ratio_avg = if current_wave > 0 then current_wave / bull_avg else current_wave / AbsValue(bear_avg);
def current_ratio_max = if current_wave > 0 then current_wave / bull_max else current_wave / AbsValue(bear_max);
def current_Round_avg = Round(current_ratio_avg, 2);
def current_Round_max = Round(current_ratio_max, 2);
#// Dominance calculation
def dominance_avg_value = bull_avg - AbsValue(bear_avg);
def dominance_max_value = bull_max - AbsValue(bear_max);

AddLabel(EnableTable, "Current Wave Ratio:", Color.WHITE);
AddLabel(EnableTable, "AvgWave(" + current_Round_avg + "x)", if current_ratio_avg > 0 then Color.GREEN else Color.RED);
AddLabel(EnableTable, "MaxWave(" + current_Round_max + "x)", if current_ratio_max > 0 then Color.GREEN else Color.RED);
AddLabel(EnableTable, "Dominance:", Color.WHITE);
AddLabel(EnableTable, "AvgWave(" + if dominance_avg_value > 0 then "Bullish +" + wave_Round_avg + "x" else
         "Bearish -" + Round(1 / wave_size_ratio_avg, 2) + "x)", if dominance_avg_value>0 then Color.GREEN else Color.RED);
AddLabel(EnableTable, "MaxWave(" + if dominance_max_value > 0 then "Bullish +" + wave_Round_max + "x" else
         "Bearish -" + Round(1 / wave_size_ratio_max, 2) + "x)", if dominance_max_value>0 then Color.GREEN else Color.RED);


#-- END of CODE

Lower Study:

CSS:
#// Indicator for TOS
#// © Zeiierman
#Hint MaximumLength: This parameter sets the upper limit for the number of bars considered in the dynamic moving average. A higher value smooths out the trend line, making it less reactive to minor fluctuations but slower to adapt to sudden price movements. Use higher values for long-term trend analysis and lower values for faster-moving markets.
#Hint AcceleratorMultiplier: Adjusts the responsiveness of the dynamic moving average to price changes. A larger value makes the trend more reactive but can introduce noise in choppy markets. Lower values create a smoother trend but may lag behind rapid price movements. This is particularly useful in volatile markets where precise sensitivity is needed.
#Hint CollectionPeriod: Defines the number of bars used to normalize trend speed values. A higher value includes a broader historical range, smoothing out the speed calculation. Lower values make the speed analysis more sensitive to recent price changes, ideal for short-term trading.
#indicator('Trend Speed Analyzer (Zeiierman)', overlay = false)
# Converted by Sam4Cok@Samer800    - 02/2025

declare lower;

input EnableTable          = yes;  # 'Enable Table'
input colorBars = yes;             # 'Enable Candles'
input source = close;
input MaximumLength = 50;          # 'Maximum Length'
input AcceleratorMultiplier = 5.0; # 'Accelerator Multiplier'
input CollectionPeriod = 100;      # 'Collection Period'

def na = Double.NaN;
def last = IsNaN(close);

#// ~~  Dynamic Average {
def max_abs_counts_diff = Highest(source, 200);
def counts_diff_norm    = (source + max_abs_counts_diff) / (2 * max_abs_counts_diff);
def dyn_length          = 5 + counts_diff_norm * (MaximumLength - 5);

##// ~~ Gradient Coloring {
Script gradient_color {
input src = close;
input minVal = 0;
input maxVal = 1;
input loR = 173;
input loG = 216;
input loB = 230;
input hiR = 41;
input hiG = 98;
input hiB = 255;
    def value = if isNaN(src) then 0 else src;
    def clamped_value = max(min(value, maxVal), minVal);
    def normalized_value = (clamped_value - minVal) / (maxVal - minVal);
    def re = floor(loR + (hiR - loR) * normalized_value);
    def gr = floor(loG + (hiG - loG) * normalized_value);
    def bl = floor(loB + (hiB - loB) * normalized_value);
    plot r = re;
    plot g = gr;
    plot b = bl;
}

Script calc_accel_factor {
input counts_diff = close;
input prev_counts_diff = close;
    def delta_counts_diff = AbsValue(counts_diff - prev_counts_diff);
    def max_delta = highest(delta_counts_diff, 200);
    def max_delta_counts_diff = if max_delta == 0 then 1 else max_delta;
    def accel_factor = delta_counts_diff / max_delta_counts_diff;
    plot out = accel_factor;
}
Script adjust_alpha {
input dyn_length = 1;
input accel_factor = 1;
input accel_multiplier = 5;
    def alpha_base = 2 / (dyn_length + 1);
    def alpha_ = alpha_base * (1 + accel_factor * accel_multiplier);
    def alpha = min(1, alpha_); #  // Ensure alpha does not exceed 1
    plot out = alpha;
}
#// ~~ Accelerator Factor
def accel_factor = calc_accel_factor(source, source[1]);
def alpha        = adjust_alpha(dyn_length, accel_factor, AcceleratorMultiplier);
#// ~~ Compute dynamic Ema
def dyn_ema = if isNaN(dyn_ema[1]) then close else if !dyn_ema[1] then close else alpha * close + (1 - alpha) * dyn_ema[1];

#// ~~ Trend Speed {
def trend = dyn_ema;
def c = WildersAverage(close, 10);
def o = WildersAverage(open, 10);

#// ~~ Trend direction {
def speed; def speed1; def xBear; def xBull;
def bullish; def bearish; def bearish_recent; def bullish_recent;
def maxx; def minn;
if  (close > trend and close[1] <= trend) {
    bearish = Min(if !bearish[1] then c - o else bearish[1], (if !minn[1] then c - o else minn[1]));
    bearish_recent = bearish_recent[1] + (if !minn[1] then c - o else minn[1]);
    bullish_recent = bullish_recent[1];
    bullish = bullish[1];
    xBear   = xBear[1] + 1;
    xBull   = xBull[1];
    speed1 = c - o;
    minn = if !minn[1] then speed1 else minn[1];
    maxx = Max(speed1, maxx[1]);
} else if (close < trend and close[1] >= trend) {
    bullish = Max(bullish[1], (if !maxx[1] then c - o else maxx[1]));
    bearish = if !bearish[1] then c - o else bearish[1];
    bearish_recent = bearish_recent[1];
    bullish_recent = bullish_recent[1] + (if !maxx[1] then c - o else maxx[1]);
    xBear   = xBear[1];
    xBull   = xBull[1] + 1;
    speed1 = c - o;
    minn = if !minn[1] then speed1 else Min(minn[1], speed1);
    maxx = maxx[1];
} else {
    bearish = if !bearish[1] then c - o else bearish[1];
    bullish = if !bullish[1] then c - o else bullish[1];
    bearish_recent = bearish_recent[1];
    bullish_recent = bullish_recent[1];
    xBear = xBear[1];
    xBull = xBull[1];
    speed1 = speed[1];
    minn = if !minn[1] then speed1 else if close < trend then Min(minn[1], speed1) else minn[1];
    maxx = if close > trend then Max(maxx[1], speed1) else maxx[1];
}
speed = speed1 + c - o;
def trendspeed = HullMovingAvg(speed, 5);

#Color
def min_speed = lowest(speed, CollectionPeriod);
def max_speed = highest(speed, CollectionPeriod);
def normalized_speed = (speed - min_speed) / (max_speed - min_speed);
def rDn = gradient_color(normalized_speed, 0, 0.5, 255, 0, 0, 249, 164, 164).r;
def gDn = gradient_color(normalized_speed, 0, 0.5, 255, 0, 0, 249, 164, 164).g;
def bDn = gradient_color(normalized_speed, 0, 0.5, 255, 0, 0, 249, 164, 164).b;
def rUp = gradient_color(normalized_speed, 0.5, 1, 156, 255, 207, 0, 255, 0).r;
def gUp = gradient_color(normalized_speed, 0.5, 1, 156, 255, 207, 0, 255, 0).g;
def bUp = gradient_color(normalized_speed, 0.5, 1, 156, 255, 207, 0, 255, 0).b;


# -- plot

plot DynamicEMA = if !last then trendspeed else na;
DynamicEMA.SetLineWeight(3);
DynamicEMA.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
DynamicEMA.AssignValueColor(if speed < 0 then CreateColor(rDn, gDn, bDn) else CreateColor(rUp, gUp, bUp));
AssignPriceColor(if !colorBars then Color.CURRENT else
                 if speed < 0 then CreateColor(rDn, gDn, bDn) else CreateColor(rUp, gUp, bUp));

#// ~~ Table {
#// Calculate stats
def bull_max = highest(bullish, 200);
def bear_max = lowest(bearish, 200);
def bull_avg = bullish_recent / xBull;
def bear_avg = bearish_recent / xBear;
#// Calculate wave size ratios for max and average wave heights
def wave_size_ratio_avg = bull_avg / AbsValue(bear_avg);
def wave_Round_avg = Round(wave_size_ratio_avg, 2);
def wave_size_ratio_max = bull_max / AbsValue(bear_max);
def wave_Round_max = Round(wave_size_ratio_max, 2);
#// Current wave calculations
def current_wave       = speed;
def current_ratio_avg = if current_wave > 0 then current_wave / bull_avg else current_wave / AbsValue(bear_avg);
def current_ratio_max = if current_wave > 0 then current_wave / bull_max else current_wave / AbsValue(bear_max);
def current_Round_avg = Round(current_ratio_avg, 2);
def current_Round_max = Round(current_ratio_max, 2);
#// Dominance calculation
def dominance_avg_value = bull_avg - AbsValue(bear_avg);
def dominance_max_value = bull_max - AbsValue(bear_max);

AddLabel(EnableTable, "Current Wave Ratio:", Color.WHITE);
AddLabel(EnableTable, "AvgWave(" + current_Round_avg + "x)", if current_ratio_avg > 0 then Color.GREEN else Color.RED);
AddLabel(EnableTable, "MaxWave(" + current_Round_max + "x)", if current_ratio_max > 0 then Color.GREEN else Color.RED);
AddLabel(EnableTable, "Dominance:", Color.WHITE);
AddLabel(EnableTable, "AvgWave(" + if dominance_avg_value > 0 then "Bullish +" + wave_Round_avg + "x" else
         "Bearish -" + Round(1 / wave_size_ratio_avg, 2) + "x)", if dominance_avg_value>0 then Color.GREEN else Color.RED);
AddLabel(EnableTable, "MaxWave(" + if dominance_max_value > 0 then "Bullish +" + wave_Round_max + "x" else
         "Bearish -" + Round(1 / wave_size_ratio_max, 2) + "x)", if dominance_max_value>0 then Color.GREEN else Color.RED);


#-- END of CODE
@samer800 , Thanks for the script, how to disable/remove ones in the attachment?
 

Attachments

  • Screenshot 2025-02-04 170652.jpg
    Screenshot 2025-02-04 170652.jpg
    22.1 KB · Views: 488
@samer800 , Thanks for the script, how to disable/remove ones in the attachment?

When you have a label that you don't want. You can comment it out by putting a hashtag # in front of it.
It appears that you don't want the "Current Wave Ratio:" or the last "MaxWave("

replace this code snippet:
AddLabel(EnableTable, "Current Wave Ratio:", Color.WHITE);
AddLabel(EnableTable, "AvgWave(" + current_Round_avg + "x)", if current_ratio_avg > 0 then Color.GREEN else Color.RED);
AddLabel(EnableTable, "MaxWave(" + current_Round_max + "x)", if current_ratio_max > 0 then Color.GREEN else Color.RED);
AddLabel(EnableTable, "Dominance:", Color.WHITE);
AddLabel(EnableTable, "AvgWave(" + if dominance_avg_value > 0 then "Bullish +" + wave_Round_avg + "x" else
"Bearish -" + Round(1 / wave_size_ratio_avg, 2) + "x)", if dominance_avg_value>0 then Color.GREEN else Color.RED);
AddLabel(EnableTable, "MaxWave(" + if dominance_max_value > 0 then "Bullish +" + wave_Round_max + "x" else
"Bearish -" + Round(1 / wave_size_ratio_max, 2) + "x)", if dominance_max_value>0 then Color.GREEN else Color.RED);

with this code snippet
#AddLabel(EnableTable, "Current Wave Ratio:", Color.WHITE);
AddLabel(EnableTable, "AvgWave(" + current_Round_avg + "x)", if current_ratio_avg > 0 then Color.GREEN else Color.RED);
AddLabel(EnableTable, "MaxWave(" + current_Round_max + "x)", if current_ratio_max > 0 then Color.GREEN else Color.RED);
AddLabel(EnableTable, "Dominance:", Color.WHITE);
AddLabel(EnableTable, "AvgWave(" + if dominance_avg_value > 0 then "Bullish +" + wave_Round_avg + "x" else
"Bearish -" + Round(1 / wave_size_ratio_avg, 2) + "x)", if dominance_avg_value>0 then Color.GREEN else Color.RED);
#AddLabel(EnableTable, "MaxWave(" + if dominance_max_value > 0 then "Bullish +" + wave_Round_max + "x" else
"Bearish -" + Round(1 / wave_size_ratio_max, 2) + "x)", if dominance_max_value>0 then Color.GREEN else Color.RED);
 
@useThinkScript I was able to remove "Current Wave ratio only", getting error for the remaining.

wanted to remove all these labels.
 

Attachments

  • Screenshot 2025-02-04 175055.jpg
    Screenshot 2025-02-04 175055.jpg
    64.3 KB · Views: 364
  • Screenshot 2025-02-04 175322.jpg
    Screenshot 2025-02-04 175322.jpg
    14.5 KB · Views: 323
R9YakGn.png


Author MEssage:

The Trend Speed Analyzer by Zeiierman is designed to measure the strength and speed of market trends, providing traders with actionable insights into momentum dynamics. By combining a dynamic moving average with wave and speed analysis, it visually highlights shifts in trend direction, market strength, and potential reversals. This tool is ideal for identifying breakout opportunities, gauging trend consistency, and understanding the dominance of bullish or bearish forces over various timeframes.

Upper Study:
CSS:
#// Indicator for TOS
#// © Zeiierman {
#Hint MaximumLength: This parameter sets the upper limit for the number of bars considered in the dynamic moving average. A higher value smooths out the trend line, making it less reactive to minor fluctuations but slower to adapt to sudden price movements. Use higher values for long-term trend analysis and lower values for faster-moving markets.
#Hint AcceleratorMultiplier: Adjusts the responsiveness of the dynamic moving average to price changes. A larger value makes the trend more reactive but can introduce noise in choppy markets. Lower values create a smoother trend but may lag behind rapid price movements. This is particularly useful in volatile markets where precise sensitivity is needed.
#Hint CollectionPeriod: Defines the number of bars used to normalize trend speed values. A higher value includes a broader historical range, smoothing out the speed calculation. Lower values make the speed analysis more sensitive to recent price changes, ideal for short-term trading.
#indicator('Trend Speed Analyzer (Zeiierman)', overlay = false)
# Converted by Sam4Cok@Samer800    - 02/2025

input EnableTable          = yes;  # 'Enable Table'
input colorBars = yes;             # 'Enable Candles'
input source = close;
input MaximumLength = 50;          # 'Maximum Length'
input AcceleratorMultiplier = 5.0; # 'Accelerator Multiplier'
input CollectionPeriod = 100;      # 'Collection Period'

def na = Double.NaN;
def last = IsNaN(close);

#// ~~  Dynamic Average {
def max_abs_counts_diff = Highest(source, 200);
def counts_diff_norm    = (source + max_abs_counts_diff) / (2 * max_abs_counts_diff);
def dyn_length          = 5 + counts_diff_norm * (MaximumLength - 5);

##// ~~ Gradient Coloring {
Script gradient_color {
input src = close;
input minVal = 0;
input maxVal = 1;
input loR = 173;
input loG = 216;
input loB = 230;
input hiR = 41;
input hiG = 98;
input hiB = 255;
    def value = if isNaN(src) then 0 else src;
    def clamped_value = max(min(value, maxVal), minVal);
    def normalized_value = (clamped_value - minVal) / (maxVal - minVal);
    def re = floor(loR + (hiR - loR) * normalized_value);
    def gr = floor(loG + (hiG - loG) * normalized_value);
    def bl = floor(loB + (hiB - loB) * normalized_value);
    plot r = re;
    plot g = gr;
    plot b = bl;
}

Script calc_accel_factor {
input counts_diff = close;
input prev_counts_diff = close;
    def delta_counts_diff = AbsValue(counts_diff - prev_counts_diff);
    def max_delta = highest(delta_counts_diff, 200);
    def max_delta_counts_diff = if max_delta == 0 then 1 else max_delta;
    def accel_factor = delta_counts_diff / max_delta_counts_diff;
    plot out = accel_factor;
}
Script adjust_alpha {
input dyn_length = 1;
input accel_factor = 1;
input accel_multiplier = 5;
    def alpha_base = 2 / (dyn_length + 1);
    def alpha_ = alpha_base * (1 + accel_factor * accel_multiplier);
    def alpha = min(1, alpha_); #  // Ensure alpha does not exceed 1
    plot out = alpha;
}
#// ~~ Accelerator Factor
def accel_factor = calc_accel_factor(source, source[1]);
def alpha        = adjust_alpha(dyn_length, accel_factor, AcceleratorMultiplier);
#// ~~ Compute dynamic Ema
def dyn_ema = if isNaN(dyn_ema[1]) then close else if !dyn_ema[1] then close else alpha * close + (1 - alpha) * dyn_ema[1];

#// ~~ Trend Speed {
def trend = dyn_ema;
def c = WildersAverage(close, 10);
def o = WildersAverage(open, 10);

#// ~~ Trend direction {
def speed; def speed1; def xBear; def xBull;
def bullish; def bearish; def bearish_recent; def bullish_recent;
def maxx; def minn;
if  (close > trend and close[1] <= trend) {
    bearish = Min(if !bearish[1] then c - o else bearish[1], (if !minn[1] then c - o else minn[1]));
    bearish_recent = bearish_recent[1] + (if !minn[1] then c - o else minn[1]);
    bullish_recent = bullish_recent[1];
    bullish = bullish[1];
    xBear   = xBear[1] + 1;
    xBull   = xBull[1];
    speed1 = c - o;
    minn = if !minn[1] then speed1 else minn[1];
    maxx = Max(speed1, maxx[1]);
} else if (close < trend and close[1] >= trend) {
    bullish = Max(bullish[1], (if !maxx[1] then c - o else maxx[1]));
    bearish = if !bearish[1] then c - o else bearish[1];
    bearish_recent = bearish_recent[1];
    bullish_recent = bullish_recent[1] + (if !maxx[1] then c - o else maxx[1]);
    xBear   = xBear[1];
    xBull   = xBull[1] + 1;
    speed1 = c - o;
    minn = if !minn[1] then speed1 else Min(minn[1], speed1);
    maxx = maxx[1];
} else {
    bearish = if !bearish[1] then c - o else bearish[1];
    bullish = if !bullish[1] then c - o else bullish[1];
    bearish_recent = bearish_recent[1];
    bullish_recent = bullish_recent[1];
    xBear = xBear[1];
    xBull = xBull[1];
    speed1 = speed[1];
    minn = if !minn[1] then speed1 else if close < trend then Min(minn[1], speed1) else minn[1];
    maxx = if close > trend then Max(maxx[1], speed1) else maxx[1];
}
speed = speed1 + c - o;

#Color
def min_speed = lowest(speed, CollectionPeriod);
def max_speed = highest(speed, CollectionPeriod);
def normalized_speed = (speed - min_speed) / (max_speed - min_speed);
def rDn = gradient_color(normalized_speed, 0, 0.5, 255, 0, 0, 249, 164, 164).r;
def gDn = gradient_color(normalized_speed, 0, 0.5, 255, 0, 0, 249, 164, 164).g;
def bDn = gradient_color(normalized_speed, 0, 0.5, 255, 0, 0, 249, 164, 164).b;
def rUp = gradient_color(normalized_speed, 0.5, 1, 156, 255, 207, 0, 255, 0).r;
def gUp = gradient_color(normalized_speed, 0.5, 1, 156, 255, 207, 0, 255, 0).g;
def bUp = gradient_color(normalized_speed, 0.5, 1, 156, 255, 207, 0, 255, 0).b;


# -- plot

plot DynamicEMA = if !last then dyn_ema else na;
DynamicEMA.SetLineWeight(2);
DynamicEMA.AssignValueColor(if speed < 0 then CreateColor(rDn, gDn, bDn) else CreateColor(rUp, gUp, bUp));

#-- Bar Color
AssignPriceColor(if !colorBars then Color.CURRENT else
                 if speed < 0 then CreateColor(rDn, gDn, bDn) else CreateColor(rUp, gUp, bUp));

#// ~~ Table {
#// Calculate stats
def bull_max = highest(bullish, 200);
def bear_max = lowest(bearish, 200);
def bull_avg = bullish_recent / xBull;
def bear_avg = bearish_recent / xBear;
#// Calculate wave size ratios for max and average wave heights
def wave_size_ratio_avg = bull_avg / AbsValue(bear_avg);
def wave_Round_avg = Round(wave_size_ratio_avg, 2);
def wave_size_ratio_max = bull_max / AbsValue(bear_max);
def wave_Round_max = Round(wave_size_ratio_max, 2);
#// Current wave calculations
def current_wave       = speed;
def current_ratio_avg = if current_wave > 0 then current_wave / bull_avg else current_wave / AbsValue(bear_avg);
def current_ratio_max = if current_wave > 0 then current_wave / bull_max else current_wave / AbsValue(bear_max);
def current_Round_avg = Round(current_ratio_avg, 2);
def current_Round_max = Round(current_ratio_max, 2);
#// Dominance calculation
def dominance_avg_value = bull_avg - AbsValue(bear_avg);
def dominance_max_value = bull_max - AbsValue(bear_max);

AddLabel(EnableTable, "Current Wave Ratio:", Color.WHITE);
AddLabel(EnableTable, "AvgWave(" + current_Round_avg + "x)", if current_ratio_avg > 0 then Color.GREEN else Color.RED);
AddLabel(EnableTable, "MaxWave(" + current_Round_max + "x)", if current_ratio_max > 0 then Color.GREEN else Color.RED);
AddLabel(EnableTable, "Dominance:", Color.WHITE);
AddLabel(EnableTable, "AvgWave(" + if dominance_avg_value > 0 then "Bullish +" + wave_Round_avg + "x" else
         "Bearish -" + Round(1 / wave_size_ratio_avg, 2) + "x)", if dominance_avg_value>0 then Color.GREEN else Color.RED);
AddLabel(EnableTable, "MaxWave(" + if dominance_max_value > 0 then "Bullish +" + wave_Round_max + "x" else
         "Bearish -" + Round(1 / wave_size_ratio_max, 2) + "x)", if dominance_max_value>0 then Color.GREEN else Color.RED);


#-- END of CODE

Lower Study:

CSS:
#// Indicator for TOS
#// © Zeiierman
#Hint MaximumLength: This parameter sets the upper limit for the number of bars considered in the dynamic moving average. A higher value smooths out the trend line, making it less reactive to minor fluctuations but slower to adapt to sudden price movements. Use higher values for long-term trend analysis and lower values for faster-moving markets.
#Hint AcceleratorMultiplier: Adjusts the responsiveness of the dynamic moving average to price changes. A larger value makes the trend more reactive but can introduce noise in choppy markets. Lower values create a smoother trend but may lag behind rapid price movements. This is particularly useful in volatile markets where precise sensitivity is needed.
#Hint CollectionPeriod: Defines the number of bars used to normalize trend speed values. A higher value includes a broader historical range, smoothing out the speed calculation. Lower values make the speed analysis more sensitive to recent price changes, ideal for short-term trading.
#indicator('Trend Speed Analyzer (Zeiierman)', overlay = false)
# Converted by Sam4Cok@Samer800    - 02/2025

declare lower;

input EnableTable          = yes;  # 'Enable Table'
input colorBars = yes;             # 'Enable Candles'
input source = close;
input MaximumLength = 50;          # 'Maximum Length'
input AcceleratorMultiplier = 5.0; # 'Accelerator Multiplier'
input CollectionPeriod = 100;      # 'Collection Period'

def na = Double.NaN;
def last = IsNaN(close);

#// ~~  Dynamic Average {
def max_abs_counts_diff = Highest(source, 200);
def counts_diff_norm    = (source + max_abs_counts_diff) / (2 * max_abs_counts_diff);
def dyn_length          = 5 + counts_diff_norm * (MaximumLength - 5);

##// ~~ Gradient Coloring {
Script gradient_color {
input src = close;
input minVal = 0;
input maxVal = 1;
input loR = 173;
input loG = 216;
input loB = 230;
input hiR = 41;
input hiG = 98;
input hiB = 255;
    def value = if isNaN(src) then 0 else src;
    def clamped_value = max(min(value, maxVal), minVal);
    def normalized_value = (clamped_value - minVal) / (maxVal - minVal);
    def re = floor(loR + (hiR - loR) * normalized_value);
    def gr = floor(loG + (hiG - loG) * normalized_value);
    def bl = floor(loB + (hiB - loB) * normalized_value);
    plot r = re;
    plot g = gr;
    plot b = bl;
}

Script calc_accel_factor {
input counts_diff = close;
input prev_counts_diff = close;
    def delta_counts_diff = AbsValue(counts_diff - prev_counts_diff);
    def max_delta = highest(delta_counts_diff, 200);
    def max_delta_counts_diff = if max_delta == 0 then 1 else max_delta;
    def accel_factor = delta_counts_diff / max_delta_counts_diff;
    plot out = accel_factor;
}
Script adjust_alpha {
input dyn_length = 1;
input accel_factor = 1;
input accel_multiplier = 5;
    def alpha_base = 2 / (dyn_length + 1);
    def alpha_ = alpha_base * (1 + accel_factor * accel_multiplier);
    def alpha = min(1, alpha_); #  // Ensure alpha does not exceed 1
    plot out = alpha;
}
#// ~~ Accelerator Factor
def accel_factor = calc_accel_factor(source, source[1]);
def alpha        = adjust_alpha(dyn_length, accel_factor, AcceleratorMultiplier);
#// ~~ Compute dynamic Ema
def dyn_ema = if isNaN(dyn_ema[1]) then close else if !dyn_ema[1] then close else alpha * close + (1 - alpha) * dyn_ema[1];

#// ~~ Trend Speed {
def trend = dyn_ema;
def c = WildersAverage(close, 10);
def o = WildersAverage(open, 10);

#// ~~ Trend direction {
def speed; def speed1; def xBear; def xBull;
def bullish; def bearish; def bearish_recent; def bullish_recent;
def maxx; def minn;
if  (close > trend and close[1] <= trend) {
    bearish = Min(if !bearish[1] then c - o else bearish[1], (if !minn[1] then c - o else minn[1]));
    bearish_recent = bearish_recent[1] + (if !minn[1] then c - o else minn[1]);
    bullish_recent = bullish_recent[1];
    bullish = bullish[1];
    xBear   = xBear[1] + 1;
    xBull   = xBull[1];
    speed1 = c - o;
    minn = if !minn[1] then speed1 else minn[1];
    maxx = Max(speed1, maxx[1]);
} else if (close < trend and close[1] >= trend) {
    bullish = Max(bullish[1], (if !maxx[1] then c - o else maxx[1]));
    bearish = if !bearish[1] then c - o else bearish[1];
    bearish_recent = bearish_recent[1];
    bullish_recent = bullish_recent[1] + (if !maxx[1] then c - o else maxx[1]);
    xBear   = xBear[1];
    xBull   = xBull[1] + 1;
    speed1 = c - o;
    minn = if !minn[1] then speed1 else Min(minn[1], speed1);
    maxx = maxx[1];
} else {
    bearish = if !bearish[1] then c - o else bearish[1];
    bullish = if !bullish[1] then c - o else bullish[1];
    bearish_recent = bearish_recent[1];
    bullish_recent = bullish_recent[1];
    xBear = xBear[1];
    xBull = xBull[1];
    speed1 = speed[1];
    minn = if !minn[1] then speed1 else if close < trend then Min(minn[1], speed1) else minn[1];
    maxx = if close > trend then Max(maxx[1], speed1) else maxx[1];
}
speed = speed1 + c - o;
def trendspeed = HullMovingAvg(speed, 5);

#Color
def min_speed = lowest(speed, CollectionPeriod);
def max_speed = highest(speed, CollectionPeriod);
def normalized_speed = (speed - min_speed) / (max_speed - min_speed);
def rDn = gradient_color(normalized_speed, 0, 0.5, 255, 0, 0, 249, 164, 164).r;
def gDn = gradient_color(normalized_speed, 0, 0.5, 255, 0, 0, 249, 164, 164).g;
def bDn = gradient_color(normalized_speed, 0, 0.5, 255, 0, 0, 249, 164, 164).b;
def rUp = gradient_color(normalized_speed, 0.5, 1, 156, 255, 207, 0, 255, 0).r;
def gUp = gradient_color(normalized_speed, 0.5, 1, 156, 255, 207, 0, 255, 0).g;
def bUp = gradient_color(normalized_speed, 0.5, 1, 156, 255, 207, 0, 255, 0).b;


# -- plot

plot DynamicEMA = if !last then trendspeed else na;
DynamicEMA.SetLineWeight(3);
DynamicEMA.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
DynamicEMA.AssignValueColor(if speed < 0 then CreateColor(rDn, gDn, bDn) else CreateColor(rUp, gUp, bUp));
AssignPriceColor(if !colorBars then Color.CURRENT else
                 if speed < 0 then CreateColor(rDn, gDn, bDn) else CreateColor(rUp, gUp, bUp));

#// ~~ Table {
#// Calculate stats
def bull_max = highest(bullish, 200);
def bear_max = lowest(bearish, 200);
def bull_avg = bullish_recent / xBull;
def bear_avg = bearish_recent / xBear;
#// Calculate wave size ratios for max and average wave heights
def wave_size_ratio_avg = bull_avg / AbsValue(bear_avg);
def wave_Round_avg = Round(wave_size_ratio_avg, 2);
def wave_size_ratio_max = bull_max / AbsValue(bear_max);
def wave_Round_max = Round(wave_size_ratio_max, 2);
#// Current wave calculations
def current_wave       = speed;
def current_ratio_avg = if current_wave > 0 then current_wave / bull_avg else current_wave / AbsValue(bear_avg);
def current_ratio_max = if current_wave > 0 then current_wave / bull_max else current_wave / AbsValue(bear_max);
def current_Round_avg = Round(current_ratio_avg, 2);
def current_Round_max = Round(current_ratio_max, 2);
#// Dominance calculation
def dominance_avg_value = bull_avg - AbsValue(bear_avg);
def dominance_max_value = bull_max - AbsValue(bear_max);

AddLabel(EnableTable, "Current Wave Ratio:", Color.WHITE);
AddLabel(EnableTable, "AvgWave(" + current_Round_avg + "x)", if current_ratio_avg > 0 then Color.GREEN else Color.RED);
AddLabel(EnableTable, "MaxWave(" + current_Round_max + "x)", if current_ratio_max > 0 then Color.GREEN else Color.RED);
AddLabel(EnableTable, "Dominance:", Color.WHITE);
AddLabel(EnableTable, "AvgWave(" + if dominance_avg_value > 0 then "Bullish +" + wave_Round_avg + "x" else
         "Bearish -" + Round(1 / wave_size_ratio_avg, 2) + "x)", if dominance_avg_value>0 then Color.GREEN else Color.RED);
AddLabel(EnableTable, "MaxWave(" + if dominance_max_value > 0 then "Bullish +" + wave_Round_max + "x" else
         "Bearish -" + Round(1 / wave_size_ratio_max, 2) + "x)", if dominance_max_value>0 then Color.GREEN else Color.RED);


#-- END of CODE
@samer800 Its possible add a sound when cros green to red and other red to green? thanks
 
Last edited by a moderator:
I placed the indicator on the chart. The upper part is fine, but in the lower part, the security price is plotted as a line together with the speed histogram.
Since the security price is much higher, the speed histogram is practically invisible and shown as dots on the bottom. Of course, the security price is not needed there and I want to get rid of it, but I don't see in the code where the security price is plotted.

Could someone please help?

Thank you very much
 

Attachments

  • Error.png
    Error.png
    163.1 KB · Views: 228
Hi, Can someone please convert this Trend Speed Analyzer by Zeiierman indicator to TOS. This looks good for catching the trends on any timeframe.

https://www.tradingview.com/script/YUAV6jit-Trend-Speed-Analyzer-Zeiierman/


Overview
The Trend Speed Analyzer by Zeiierman is designed to measure the strength and speed of market trends, providing traders with actionable insights into momentum dynamics. By combining a dynamic moving average with wave and speed analysis, it visually highlights shifts in trend direction, market strength, and potential reversals. This tool is ideal for identifying breakout opportunities, gauging trend consistency, and understanding the dominance of bullish or bearish forces over various timeframes.
snapshot


How It Works
The indicator employs a Dynamic Moving Average (DMA) enhanced with an Accelerator Factor, allowing it to adapt dynamically to market conditions. The DMA is responsive to price changes, making it suitable for both long-term trends and short-term momentum analysis.

Key components include:
  • Trend Speed Analysis: Measures the speed of market movements, highlighting momentum shifts with visual cues.
  • Wave Analysis: Tracks bullish and bearish wave sizes to determine market strength and bias.
  • Normalized Speed Values: Ensures consistency across different market conditions by adjusting for volatility.

⚪ Average Wave and Max Wave
These metrics analyze the size of bullish and bearish waves over a specified Lookback Period:
  • Average Wave: This represents the mean size of bullish and bearish movements, helping traders gauge overall market strength.
  • Max Wave: Highlights the largest movements within the period, identifying peak momentum during trend surges.

⚪Current Wave Ratio
This feature compares the current wave's size against historical data:
  • Average Wave Ratio: Indicates if the current momentum exceeds historical averages. A value above 1 suggests the trend is gaining strength.
  • Max Wave Ratio: Shows whether the current wave surpasses previous peak movements, signaling potential breakouts or trend accelerations.

⚪Dominance
Dominance metrics reveal whether bulls or bears have controlled the market during the Lookback Period:
  • Average Dominance: Compares the net difference between average bullish and bearish wave sizes.
  • Max Dominance: Highlights which side had the stronger individual waves, indicating key power shifts in market dynamics.
Positive values suggest bullish dominance, while negative values point to bearish control. This helps traders confirm trend direction or anticipate reversals.


How to Use
Identify Trends:
Leverage the color-coded candlesticks and dynamic trend line to assess the overall market direction with clarity.
snapshot

Monitor Momentum: Use the Trend Speed histogram to track changes in momentum, identifying periods of acceleration or deceleration.
snapshot

Analyze Waves: Compare the sizes of bullish and bearish waves to identify the prevailing market bias and detect potential shifts in sentiment. Additionally, fluctuations in Current Wave ratio values should be monitored as early indicators of possible trend reversals.
snapshot

Evaluate Dominance: Utilize dominance metrics to confirm the strength and direction of the current trend.
snapshot


Settings
  • Maximum Length: Sets the smoothing of the trend line.
  • Accelerator Multiplier: Adjusts sensitivity to price changes.
  • Lookback Period: Defines the range for wave calculations.
  • Enable Table: Displays statistical metrics for in-depth analysis.
  • Enable Candles: Activates color-coded candlesticks.
  • Collection Period: Normalizes trend speed values for better accuracy.
  • Start Date: Limits calculations to a specific timeframe.
  • Timer Option: Choose between using all available data or starting from a custom date.
 
Okay, here’s my attempt to convert this study. Disclaimer: I’m not an expert, but this should be a close approach.

Screenshot 2026-01-07 170755.png


Code: http://tos.mx/!nWgFcsWM

However, I want to point out that, in my opinion, Ehlers’ approach is a bit more efficient and less resource intensive.

Screenshot 2026-01-07 171002.png
 
Okay, here’s my attempt to convert this study. Disclaimer: I’m not an expert, but this should be a close approach.

View attachment 26723

Code: http://tos.mx/!nWgFcsWM

However, I want to point out that, in my opinion, Ehlers’ approach is a bit more efficient and less resource intensive.

View attachment 26724
Thanks Rewardiz. Appreciate your help.
1) Is it possible to create lower indicator too with histogram. I believe the histogram code is already in your code, it just need to draw in lower indicator.
2) Also can you please provide more info about the Ehlers’ approach you mentioned in your post.
 
Thanks Rewardiz. Appreciate your help.
1) Is it possible to create lower indicator too with histogram. I believe the histogram code is already in your code, it just need to draw in lower indicator.
2) Also can you please provide more info about the Ehlers’ approach you mentioned in your post.
These have been converted previously. The lower is below.
Code:
#indicator('Trend Speed Analyzer (Zeiierman)', overlay = false)
# Converted by Sam4Cok@Samer800    - 02/2025

declare lower;

input EnableTable          = yes;  # 'Enable Table'
input colorBars = yes;             # 'Enable Candles'
input source = close;
input MaximumLength = 50;          # 'Maximum Length'
input AcceleratorMultiplier = 5.0; # 'Accelerator Multiplier'
input CollectionPeriod = 100;      # 'Collection Period'

def na = Double.NaN;
def last = IsNaN(close);

#// ~~  Dynamic Average {
def max_abs_counts_diff = Highest(source, 200);
def counts_diff_norm    = (source + max_abs_counts_diff) / (2 * max_abs_counts_diff);
def dyn_length          = 5 + counts_diff_norm * (MaximumLength - 5);

##// ~~ Gradient Coloring {
Script gradient_color {
input src = close;
input minVal = 0;
input maxVal = 1;
input loR = 173;
input loG = 216;
input loB = 230;
input hiR = 41;
input hiG = 98;
input hiB = 255;
    def value = if isNaN(src) then 0 else src;
    def clamped_value = max(min(value, maxVal), minVal);
    def normalized_value = (clamped_value - minVal) / (maxVal - minVal);
    def re = floor(loR + (hiR - loR) * normalized_value);
    def gr = floor(loG + (hiG - loG) * normalized_value);
    def bl = floor(loB + (hiB - loB) * normalized_value);
    plot r = re;
    plot g = gr;
    plot b = bl;
}

Script calc_accel_factor {
input counts_diff = close;
input prev_counts_diff = close;
    def delta_counts_diff = AbsValue(counts_diff - prev_counts_diff);
    def max_delta = highest(delta_counts_diff, 200);
    def max_delta_counts_diff = if max_delta == 0 then 1 else max_delta;
    def accel_factor = delta_counts_diff / max_delta_counts_diff;
    plot out = accel_factor;
}
Script adjust_alpha {
input dyn_length = 1;
input accel_factor = 1;
input accel_multiplier = 5;
    def alpha_base = 2 / (dyn_length + 1);
    def alpha_ = alpha_base * (1 + accel_factor * accel_multiplier);
    def alpha = min(1, alpha_); #  // Ensure alpha does not exceed 1
    plot out = alpha;
}
#// ~~ Accelerator Factor
def accel_factor = calc_accel_factor(source, source[1]);
def alpha        = adjust_alpha(dyn_length, accel_factor, AcceleratorMultiplier);
#// ~~ Compute dynamic Ema
def dyn_ema = if isNaN(dyn_ema[1]) then close else if !dyn_ema[1] then close else alpha * close + (1 - alpha) * dyn_ema[1];

#// ~~ Trend Speed {
def trend = dyn_ema;
def c = WildersAverage(close, 10);
def o = WildersAverage(open, 10);

#// ~~ Trend direction {
def speed; def speed1; def xBear; def xBull;
def bullish; def bearish; def bearish_recent; def bullish_recent;
def maxx; def minn;
if  (close > trend and close[1] <= trend) {
    bearish = Min(if !bearish[1] then c - o else bearish[1], (if !minn[1] then c - o else minn[1]));
    bearish_recent = bearish_recent[1] + (if !minn[1] then c - o else minn[1]);
    bullish_recent = bullish_recent[1];
    bullish = bullish[1];
    xBear   = xBear[1] + 1;
    xBull   = xBull[1];
    speed1 = c - o;
    minn = if !minn[1] then speed1 else minn[1];
    maxx = Max(speed1, maxx[1]);
} else if (close < trend and close[1] >= trend) {
    bullish = Max(bullish[1], (if !maxx[1] then c - o else maxx[1]));
    bearish = if !bearish[1] then c - o else bearish[1];
    bearish_recent = bearish_recent[1];
    bullish_recent = bullish_recent[1] + (if !maxx[1] then c - o else maxx[1]);
    xBear   = xBear[1];
    xBull   = xBull[1] + 1;
    speed1 = c - o;
    minn = if !minn[1] then speed1 else Min(minn[1], speed1);
    maxx = maxx[1];
} else {
    bearish = if !bearish[1] then c - o else bearish[1];
    bullish = if !bullish[1] then c - o else bullish[1];
    bearish_recent = bearish_recent[1];
    bullish_recent = bullish_recent[1];
    xBear = xBear[1];
    xBull = xBull[1];
    speed1 = speed[1];
    minn = if !minn[1] then speed1 else if close < trend then Min(minn[1], speed1) else minn[1];
    maxx = if close > trend then Max(maxx[1], speed1) else maxx[1];
}
speed = speed1 + c - o;
def trendspeed = HullMovingAvg(speed, 5);

#Color
def min_speed = lowest(speed, CollectionPeriod);
def max_speed = highest(speed, CollectionPeriod);
def normalized_speed = (speed - min_speed) / (max_speed - min_speed);
def rDn = gradient_color(normalized_speed, 0, 0.5, 255, 0, 0, 249, 164, 164).r;
def gDn = gradient_color(normalized_speed, 0, 0.5, 255, 0, 0, 249, 164, 164).g;
def bDn = gradient_color(normalized_speed, 0, 0.5, 255, 0, 0, 249, 164, 164).b;
def rUp = gradient_color(normalized_speed, 0.5, 1, 156, 255, 207, 0, 255, 0).r;
def gUp = gradient_color(normalized_speed, 0.5, 1, 156, 255, 207, 0, 255, 0).g;
def bUp = gradient_color(normalized_speed, 0.5, 1, 156, 255, 207, 0, 255, 0).b;


# -- plot

plot DynamicEMA = if !last then trendspeed else na;
DynamicEMA.SetLineWeight(3);
DynamicEMA.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
DynamicEMA.AssignValueColor(if speed < 0 then CreateColor(rDn, gDn, bDn) else CreateColor(rUp, gUp, bUp));
AssignPriceColor(if !colorBars then Color.CURRENT else
                 if speed < 0 then CreateColor(rDn, gDn, bDn) else CreateColor(rUp, gUp, bUp));

#// ~~ Table {
#// Calculate stats
def bull_max = highest(bullish, 200);
def bear_max = lowest(bearish, 200);
def bull_avg = bullish_recent / xBull;
def bear_avg = bearish_recent / xBear;
#// Calculate wave size ratios for max and average wave heights
def wave_size_ratio_avg = bull_avg / AbsValue(bear_avg);
def wave_Round_avg = Round(wave_size_ratio_avg, 2);
def wave_size_ratio_max = bull_max / AbsValue(bear_max);
def wave_Round_max = Round(wave_size_ratio_max, 2);
#// Current wave calculations
def current_wave       = speed;
def current_ratio_avg = if current_wave > 0 then current_wave / bull_avg else current_wave / AbsValue(bear_avg);
def current_ratio_max = if current_wave > 0 then current_wave / bull_max else current_wave / AbsValue(bear_max);
def current_Round_avg = Round(current_ratio_avg, 2);
def current_Round_max = Round(current_ratio_max, 2);
#// Dominance calculation
def dominance_avg_value = bull_avg - AbsValue(bear_avg);
def dominance_max_value = bull_max - AbsValue(bear_max);

AddLabel(EnableTable, "Current Wave Ratio:", Color.WHITE);
AddLabel(EnableTable, "AvgWave(" + current_Round_avg + "x)", if current_ratio_avg > 0 then Color.GREEN else Color.RED);
AddLabel(EnableTable, "MaxWave(" + current_Round_max + "x)", if current_ratio_max > 0 then Color.GREEN else Color.RED);
AddLabel(EnableTable, "Dominance:", Color.WHITE);
AddLabel(EnableTable, "AvgWave(" + if dominance_avg_value > 0 then "Bullish +" + wave_Round_avg + "x" else
         "Bearish -" + Round(1 / wave_size_ratio_avg, 2) + "x)", if dominance_avg_value>0 then Color.GREEN else Color.RED);
AddLabel(EnableTable, "MaxWave(" + if dominance_max_value > 0 then "Bullish +" + wave_Round_max + "x" else
         "Bearish -" + Round(1 / wave_size_ratio_max, 2) + "x)", if dominance_max_value>0 then Color.GREEN else Color.RED);


#-- END of CODE
 
In Ehlers’ world, lagging is not acceptable. He started asking questions, “Why do we constantly use fixed lengths?” So he developed something called the Dominant Cycle Period (DCP). From there, he used it as a proxy to determine how far back your indicators should look. Based on that idea, I shared a concept that represents the DCP.

The gray “slow” MA represents the actual DCP, while the “fast” MA represents half of that period. Ehlers describes that, to measure how strong a trend is, we should measure the distance between the fast and slow MAs.

That’s where the idea came from to visualize it. Please keep in mind this was done simply to show how dynamic these MAs are and how they adjust to market changes. So, if you’re looking for a way to understand how strong the trend is within the current cycle, see below. 🍻

Read Here:
https://usethinkscript.com/threads/cycle-period-trend-and-strength.22009/
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
966 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

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.

How do I get started?

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.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top