Market Structure Trend Matrix [BigBeluga] for ThinkOrSwim

chewie76

Well-known member
VIP
VIP Enthusiast
Market Structure Trend Matrix [BigBeluga] is a comprehensive technical analysis framework engineered for traders who demand precision in identifying market regimes and trend expansions. By integrating automated Market Structure (MS) detection with volatility-adjusted risk parameters, this indicator provides a systematic roadmap for navigating complex price action.

NOTE: I CHANGED THE TARGET LEVELS FROM THE ORIGINAL INDICATOR. TOS DOESN'T CONVERT THE ORIGINAL TARGETS.

In the below picture of META on 4 hr chart, price hit the T3 target three times.

1777990153748.png


The tool focuses on the Change of Character (ChoCh)—the critical moment when a previous trend structure breaks and a new directional bias begins.

🔵 ARCHITECTURE & CORE LOGIC
  • Automated Structure Mapping: The engine uses a sophisticated pivot-detection algorithm (MS Length) to scan for institutional-grade swing highs and lows. It ignores minor retail noise, drawing structural lines only when significant supply or demand zones are breached.
  • The ChoCh Engine: When price crosses a recent pivot high or low, the indicator prints a "ChoCh" label. This represents a fundamental shift in market sentiment, signaling that the current trend has likely terminated and a new cycle has begun.
Volatility-Anchored Trailing Stop: To ensure professional-grade risk management, the indicator plots a dynamic ATR Trailing Stop. This line acts as a "ratchet" mechanism—it moves closer to price during the trend expansion but stays firm during minor pullbacks, providing a clear exit point if the trend truly fails.

🔵 CONCLUSION
Market Structure Trend Matrix [BigBeluga]
is more than a signal tool; it is a visual framework for objective decision-making. By anchoring your trading to structural pivots and volatility-based targets, you remove the guesswork from trend following. Whether you are looking for a clean "ChoCh" entry or a systematic way to trail your profits during a massive expansion, the Trend Matrix provides the data and clarity required to trade like a professional.


Code:
# Market_Structure_Trend_Matrix
# Converted from "Market Structure Trend Matrix [BigBeluga]": https://www.tradingview.com/script/EdtttXPC-Market-Structure-Trend-Matrix-BigBeluga/
# Converted by Chewie 5/5/2026

# ═══════════════════════════════════════════════════════
# INPUTS
# ═══════════════════════════════════════════════════════

input msLen          = 10;
input atrLength      = 14;
input atrMult        = 4.0;
input TatrMult       = 2.0;
input targetStepMult = 2.0;
input showStop       = yes;
input bubble         = yes;
input alerts         = yes;

# Colors — defined as defs using CreateColor so they can be reused anywhere
# Bull = green (52, 230, 126) | Bear = magenta (255, 82, 241)
DefineGlobalColor("Bull", CreateColor(52, 230, 126));
DefineGlobalColor("Bear", CreateColor(255, 82, 241));

# ═══════════════════════════════════════════════════════
# PIVOT DETECTION
# ═══════════════════════════════════════════════════════

def ph = if high[msLen] == Highest(high, 2 * msLen + 1)[msLen] then high[msLen] else Double.NaN;
def pl = if low[msLen]  == Lowest(low,   2 * msLen + 1)[msLen] then low[msLen]  else Double.NaN;

def phVal = if !IsNaN(ph) then ph else phVal[1];
def plVal = if !IsNaN(pl) then pl else plVal[1];

# ═══════════════════════════════════════════════════════
# ATR
# ═══════════════════════════════════════════════════════

def atr = Average(TrueRange(high, close, low), atrLength);

# ═══════════════════════════════════════════════════════
# DIRECTION & STRUCTURE BREAKS (ChoCh)
# ═══════════════════════════════════════════════════════

def bullBreak = close crosses above phVal;
def bearBreak = close crosses below plVal;

def direction;
def entryPrice;

if bullBreak and !direction[1] {
    direction  = 1;
    entryPrice = phVal;
} else if bearBreak and direction[1] {
    direction  = 0;
    entryPrice = plVal;
} else {
    direction  = direction[1];
    entryPrice = entryPrice[1];
}

def directionChanged = direction != direction[1];

# ═══════════════════════════════════════════════════════
# ATR TRAILING STOP
# Bull: ratchet up  → max(prev, close - atr*mult)
# Bear: ratchet down → min(prev, close + atr*mult)
# ═══════════════════════════════════════════════════════

def atrTS;
if bullBreak and !direction[1] {
    atrTS = close - atr * atrMult;
} else if bearBreak and direction[1] {
    atrTS = close + atr * atrMult;
} else if direction {
    atrTS = Max(CompoundValue(1, atrTS[1], close - atr * atrMult),
                close - atr * atrMult);
} else {
    atrTS = Min(CompoundValue(1, atrTS[1], close + atr * atrMult),
                close + atr * atrMult);
}



# ═══════════════════════════════════════════════════════
# PLOTS — TRAILING STOP
# ═══════════════════════════════════════════════════════

plot TrailingStop = if showStop and !directionChanged then atrTS else Double.NaN;
TrailingStop.SetLineWeight(2);
TrailingStop.AssignValueColor(if direction then GlobalColor("Bull") else GlobalColor("Bear"));

plot PriceLine = if showStop then close else Double.NaN;
PriceLine.Hide();

AddCloud(PriceLine, TrailingStop, GlobalColor("Bull"), GlobalColor("Bear"));

# ═══════════════════════════════════════════════════════
# TARGET LEVELS
# Projected from entryPrice at atrMult * targetStepMult increments.
# Held until the next direction change clears them.
# ═══════════════════════════════════════════════════════

def targetStep = atr * TatrMult * targetStepMult;

def t1;
def t2;
def t3;

if directionChanged {
    t1 = if direction then entryPrice + 1 * targetStep
                      else entryPrice - 1 * targetStep;
    t2 = if direction then entryPrice + 2 * targetStep
                      else entryPrice - 2 * targetStep;
    t3 = if direction then entryPrice + 3 * targetStep
                      else entryPrice - 3 * targetStep;
} else {
    t1 = CompoundValue(1, t1[1], Double.NaN);
    t2 = CompoundValue(1, t2[1], Double.NaN);
    t3 = CompoundValue(1, t3[1], Double.NaN);
}

plot Target1 = t1;
plot Target2 = t2;
plot Target3 = t3;

Target1.SetStyle(Curve.SHORT_DASH);
Target2.SetStyle(Curve.SHORT_DASH);
Target3.SetStyle(Curve.SHORT_DASH);

Target1.SetLineWeight(1);
Target2.SetLineWeight(1);
Target3.SetLineWeight(2);

Target1.AssignValueColor(if direction then GlobalColor("Bull") else GlobalColor("Bear"));
Target2.AssignValueColor(if direction then GlobalColor("Bull") else GlobalColor("Bear"));
Target3.AssignValueColor(if direction then GlobalColor("Bull") else GlobalColor("Bear"));

AddChartBubble(directionChanged, if direction then t1 else t1, "T1", Color.WHITE, direction);
AddChartBubble(directionChanged, if direction then t2 else t2, "T2", Color.WHITE, direction);
AddChartBubble(directionChanged, if direction then t3 else t3, "T3", Color.WHITE, direction);

# ═══════════════════════════════════════════════════════
# PLOTS — ChoCh SIGNALS
# ═══════════════════════════════════════════════════════

plot ChoCh_Bull = if bullBreak and !direction[1] then low  else Double.NaN;
ChoCh_Bull.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
ChoCh_Bull.SetDefaultColor(GlobalColor("Bull"));
ChoCh_Bull.SetLineWeight(3);

plot ChoCh_Bear = if bearBreak and direction[1] then high else Double.NaN;
ChoCh_Bear.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
ChoCh_Bear.SetDefaultColor(GlobalColor("Bear"));
ChoCh_Bear.SetLineWeight(3);

AddChartBubble(bubble and bullBreak and !direction[1], low,  "ChoChUP", GlobalColor("Bull"), no);
AddChartBubble(bubble and bearBreak and direction[1],  high, "ChoChDN", GlobalColor("Bear"), yes);

# ═══════════════════════════════════════════════════════
# ALERTS
# ═══════════════════════════════════════════════════════

Alert(alerts and bullBreak and !direction[1], "ChoCh Up - Bullish Structure Break",  Alert.BAR, Sound.Chimes);
Alert(alerts and bearBreak and direction[1],  "ChoCh Down - Bearish Structure Break", Alert.BAR, Sound.Bell);
 

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