Repaints Step Channel Momentum Trend [ChartPrime] For ThinkOrSwim

Repaints

Typegod

New member
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.
UwFbbH2.png



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:

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
1182 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