The author states: Step Channel Momentum Trend [ChartPrime] is a momentum-based price filtering system that adapts to market structure using pivot levels and ATR volatility. It builds a dynamic channel around a stepwise midline derived from swing highs and lows. The system colors price candles based on whether price remains inside this channel (low momentum) or breaks out (strong directional flow). This allows traders to clearly distinguish ranging conditions from trending ones and take action accordingly.
This is a pinescript to thinkscript conversion by Kimi K2.6, it took 8 passes but looks good.
https://www.tradingview.com/script/AsD2fDh7-Step-Channel-Momentum-Trend-ChartPrime/
This is a pinescript to thinkscript conversion by Kimi K2.6, it took 8 passes but looks good.
https://www.tradingview.com/script/AsD2fDh7-Step-Channel-Momentum-Trend-ChartPrime/
Code:
# Step Channel Momentum Trend [ChartPrime] is a momentum-based price filtering system that adapts to market structure using pivot levels and ATR volatility. It builds a dynamic channel around a stepwise midline derived from swing highs and lows. The system colors price candles based on whether price remains inside this channel (low momentum) or breaks out (strong directional flow). This allows traders to clearly distinguish ranging conditions from trending ones and take action accordingly.
# Step Channel Momentum Trend
# Converted from PineScript v6
#
declare upper;
input length = 3;
input multiplier = 0.6;
# --------------------------------------------------------------------------------------------------------------------
# Pivot Detection (detected at the pivot bar using future confirmation — no shift)
# --------------------------------------------------------------------------------------------------------------------
def leftHighs = fold i1 = 1 to length + 1 with v1 = Double.NEGATIVE_INFINITY do Max(v1, GetValue(high, i1));
def rightHighs = fold i2 = 1 to length + 1 with v2 = Double.NEGATIVE_INFINITY do Max(v2, GetValue(high, -i2));
def ph = if high >= leftHighs and high >= rightHighs then high else Double.NaN;
def leftLows = fold i3 = 1 to length + 1 with v3 = Double.POSITIVE_INFINITY do Min(v3, GetValue(low, i3));
def rightLows = fold i4 = 1 to length + 1 with v4 = Double.POSITIVE_INFINITY do Min(v4, GetValue(low, -i4));
def pl = if low <= leftLows and low <= rightLows then low else Double.NaN;
# --------------------------------------------------------------------------------------------------------------------
# Persistent Pivot Values
# --------------------------------------------------------------------------------------------------------------------
def p_h = if !IsNaN(ph) then ph else p_h[1];
def p_l = if !IsNaN(pl) then pl else p_l[1];
# --------------------------------------------------------------------------------------------------------------------
# Channel Calculations
# --------------------------------------------------------------------------------------------------------------------
def avg = (p_h + p_l) / 2;
def atr = ATR(200) * multiplier;
def upper = avg + atr;
def lower = avg - atr;
def hl2 = (high + low) / 2;
# --------------------------------------------------------------------------------------------------------------------
# Trend State (1 = up, -1 = down, 0 = range/neutral)
# --------------------------------------------------------------------------------------------------------------------
def trend = if hl2 > upper then 1 else if hl2 < lower then -1 else 0;
# --------------------------------------------------------------------------------------------------------------------
# Plots
# --------------------------------------------------------------------------------------------------------------------
plot midLine = avg;
midLine.AssignValueColor(if trend == 1 then CreateColor(26, 190, 127) else if trend == -1 then CreateColor(202, 38, 65) else Color.ORANGE);
midLine.SetLineWeight(3);
midLine.SetPaintingStrategy(PaintingStrategy.LINE);
plot upperBand = upper;
upperBand.SetDefaultColor(Color.GRAY);
upperBand.SetPaintingStrategy(PaintingStrategy.LINE);
plot lowerBand = lower;
lowerBand.SetDefaultColor(Color.GRAY);
lowerBand.SetPaintingStrategy(PaintingStrategy.LINE);
# --------------------------------------------------------------------------------------------------------------------
# Candle Coloring
# --------------------------------------------------------------------------------------------------------------------
AssignPriceColor(if trend == 1 then CreateColor(26, 190, 127) else if trend == -1 then CreateColor(202, 38, 65) else Color.ORANGE);
# --------------------------------------------------------------------------------------------------------------------
# Pivot Markers (offset above highs / below lows)
# --------------------------------------------------------------------------------------------------------------------
def markerOffset = ATR(14) * 0.15;
plot phMarker = if !IsNaN(ph) then ph + markerOffset else Double.NaN;
phMarker.SetPaintingStrategy(PaintingStrategy.POINTS);
phMarker.SetDefaultColor(Color.RED);
phMarker.SetLineWeight(3);
plot plMarker = if !IsNaN(pl) then pl - markerOffset else Double.NaN;
plMarker.SetPaintingStrategy(PaintingStrategy.POINTS);
plMarker.SetDefaultColor(Color.GREEN);
plMarker.SetLineWeight(3);
# --------------------------------------------------------------------------------------------------------------------
# Market State Label
# --------------------------------------------------------------------------------------------------------------------
AddLabel(yes, if trend == 1 then "Momentum Up" else if trend == -1 then "Momentum Down" else "Range", if trend == 1 then CreateColor(26, 190, 127) else if trend == -1 then CreateColor(202, 38, 65) else Color.ORANGE);
Last edited by a moderator: