OPEN-SOURCE SCRIPT
Updated Faytterro Market Structure - ROC Momentum

Faytterro Market Structure - ROC Momentum
A special thanks to faytterro for the original Market Structure Break (MSB) indicator that forms the foundation of this tool.
What This Indicator Does:
This enhanced version combines Faytterro's powerful MSB (Market Structure Break) detection with ROC (Rate of Change) momentum filtering to provide higher-quality trade signals.
Key Features:
Market Structure Breaks (MSB) - The original MSB logic identifies key structural breakpoints in price action, drawing trend lines and displaying distance percentages to recent highs and lows.
ROC Momentum Filter - A 3-period ROC (Rate of Change) momentum indicator acts as a trend filter. It confirms bullish momentum when ROC is positive and bearish momentum when negative, helping to avoid false MSB signals during choppy or ranging markets.
Smart Signal Generation - Buy signals are generated when:
MSB crosses below zero (original MSB buy condition)
ROC momentum confirms bullish trend
Sell signals are generated when:
MSB crosses above zero (original MSB sell condition)
ROC momentum confirms bearish trend
Take Profit Management - Optional automatic TP levels can be set as a percentage from entry, with visual flags marking when TP targets are hit.
Complete Alert System - Built-in alerts for:
Momentum-confirmed Buy/Sell signals
Take Profit completions
Visual Features:
Trend background coloring (green for bullish, red for bearish)
MSB structure lines on the chart
ROC momentum display in a separate pane
Information panel showing ROC values and current trend state
How to Use:
Enable/disable the trend filter as needed
Adjust ROC period and threshold values to match your trading style
Use the take profit feature for automated exit management
Set alerts to never miss a signal
This indicator is ideal for traders who want to combine market structure analysis with momentum confirmation for higher-probability entries.
A special thanks to faytterro for the original Market Structure Break (MSB) indicator that forms the foundation of this tool.
What This Indicator Does:
This enhanced version combines Faytterro's powerful MSB (Market Structure Break) detection with ROC (Rate of Change) momentum filtering to provide higher-quality trade signals.
Key Features:
Market Structure Breaks (MSB) - The original MSB logic identifies key structural breakpoints in price action, drawing trend lines and displaying distance percentages to recent highs and lows.
ROC Momentum Filter - A 3-period ROC (Rate of Change) momentum indicator acts as a trend filter. It confirms bullish momentum when ROC is positive and bearish momentum when negative, helping to avoid false MSB signals during choppy or ranging markets.
Smart Signal Generation - Buy signals are generated when:
MSB crosses below zero (original MSB buy condition)
ROC momentum confirms bullish trend
Sell signals are generated when:
MSB crosses above zero (original MSB sell condition)
ROC momentum confirms bearish trend
Take Profit Management - Optional automatic TP levels can be set as a percentage from entry, with visual flags marking when TP targets are hit.
Complete Alert System - Built-in alerts for:
Momentum-confirmed Buy/Sell signals
Take Profit completions
Visual Features:
Trend background coloring (green for bullish, red for bearish)
MSB structure lines on the chart
ROC momentum display in a separate pane
Information panel showing ROC values and current trend state
How to Use:
Enable/disable the trend filter as needed
Adjust ROC period and threshold values to match your trading style
Use the take profit feature for automated exit management
Set alerts to never miss a signal
This indicator is ideal for traders who want to combine market structure analysis with momentum confirmation for higher-probability entries.
Release Notes
Take Profit System Changes & Trend Filter Interaction1. Take Profit System Overhaul
Previous Problem:
TP was checked continuously (high >= buyTPPrice) which caused the TP condition to remain true for multiple bars as long as price stayed above the TP level
This resulted in dozens of duplicate TP signals, labels, and alarms for a single trade
New Event-Based System:
The TP system has been completely redesigned using a Finite State Machine (FSM) approach with event-based triggers:
pinescript
// Events are reset at the beginning of each bar
buyTPEvent := false
sellTPEvent := false
// TP is checked only ONCE when triggered
if position == "LONG" and high >= tpPrice
buyTPEvent := true // Only true for this single bar
position := "FLAT" // Position closes immediately
entryPrice := na
tpPrice := na
Key Improvements:
TP is now an event, not a state
Each TP triggers exactly ONCE (single bar)
Position closes immediately upon TP hit
No duplicate signals, labels, or alarms
Same-direction signals are ignored while position is open
State Machine Logic:
text
FLAT → BUY → LONG (entry & TP locked)
LONG → BUY → IGNORED (entry unchanged)
LONG → TP hit → FLAT (single event, then reset)
LONG → SELL → SHORT (reverse position)
FLAT → SELL → SHORT (entry & TP locked)
SHORT → SELL → IGNORED (entry unchanged)
SHORT → TP hit → FLAT (single event, then reset)
SHORT → BUY → LONG (reverse position)
2. Trend Filter & TP System Interaction
Important: The Trend Filter must be turned OFF when using this indicator with the TP system.
Why?
Signal Reliability:
When the Trend Filter is OFF (useTrendFilter = false), both bullFilter and bearFilter are set to true
This allows ALL MSB signals (both buy and sell) to pass through unfiltered
The TP system receives every valid MSB signal for proper position management
When Trend Filter is ON:
pinescript
if useTrendFilter
bullFilter := bullMomentum // Only allows bullish momentum signals
bearFilter := bearMomentum // Only allows bearish momentum signals
else
bullFilter := true // All buy signals pass
bearFilter := true // All sell signals pass
Impact on TP System:
With Filter ON: Only momentum-confirmed signals generate entries. This can cause:
Missed MSB signals that don't have momentum confirmation
Positions may not close properly via TP
Inconsistent position states
TP events may not trigger as expected
With Filter OFF: All MSB signals are processed:
Every MSB structure break generates a signal
TP system receives all signals for proper position management
Entries and TP levels are consistent
State machine works flawlessly
Why Filter Should Be OFF:
MSB signals are already structural break signals
Adding momentum filtering can delay or prevent TP triggers
The FSM requires ALL signals to maintain correct position states
Filtering can cause the state machine to get "stuck" in wrong states
Recommended Settings:
text
✅ Trend Filter: OFF (useTrendFilter = false)
✅ Take Profit: ON (useTP = true)
✅ TP %: Set according to your risk management
Visual Confirmation:
When Trend Filter is OFF, the background color will show as transparent (no green/red tint)
All MSB labels appear regardless of momentum
TP system processes all signals consistently
Summary
Feature Previous System New System
TP Trigger State (continuous) Event (single bar)
Duplicate TP Yes (many) No (once)
Alarm Repetition Yes (unlimited) No (single)
Position States Manual tracking FSM (FLAT/LONG/SHORT)
Same-direction signals Overwrites entry Ignored
Opposite signals Conflicts Clean reverse
Trend Filter Optional but causes issues MUST BE OFF
The new TP system is designed to work as a professional trading strategy with proper position management, event-based triggers, and zero duplicate signals. For optimal performance, keep the Trend Filter turned OFF to ensure all MSB signals are processed correctly by the state machine.
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.