PROTECTED SOURCE SCRIPT

Structure Indicator Ment-Fx

21
## What this indicator does
This tool maps the active market range by programmatically tracking swing highs and swing lows on any timeframe, then draws those bounds as live-updating lines/channels. It is designed to help traders read trend context, locate the most recent “impulse range,” and plan continuation/invalidations around those levels.

## How it works (high‑level algorithm)
1. Determine directional bias (range state):
- We maintain a Bullish state when the most recent confirmed break in structure (BOS) was up (i.e., a candle body exceeded a prior structural high).
- We maintain a Bearish state when the most recent confirmed BOS was down (i.e., a candle body fell below a prior structural low).

2. Define candidate swings:
- A swing high requires a lower high on both its left and right.
- A swing low requires a higher low on both its left and right.
- Swing lookback is user‑configurable (see Inputs).

3. Range update rules (body‑based confirmations):
- Bullish state:
- The high line is allowed to step up as higher swing highs print.
- The low line is protected from wick violations. Only a body (open or close) closing below the low triggers a state check and potential range reset.
- Bearish state:
- The low line is allowed to step down as lower swing lows print.
- The high line is protected from wick violations. Only a body (open or close) closing above the high triggers a state check and potential range reset.

4. Range reset (sell‑before‑buy / buy‑before‑sell logic):
- When a Bullish range loses protection (body closes below the low), we:
1) Switch to Bearish state,
2) Search forward from the most recent body‑confirmed lower‑low event to locate the highest high formed after that event,
3) Assign that highest high as the new range high, then continue to let the low step down via subsequent swing lows until a swing low confirms.
- Conversely, when a Bearish range loses protection (body closes above the high), we:
1) Switch to Bullish state,
2) Search forward from the most recent body‑confirmed higher‑high event to locate the lowest low formed after that event,
3) Assign that lowest low as the new range low, then continue to let the high step up via subsequent swing highs until a swing high confirms.

5. Live updates:
- On each new bar, the indicator re‑evaluates the current state, confirms new swings if present, and updates the plotted range lines accordingly. Lines are extended in real time and will only “lock” upon swing confirmation per the rules above.

## What gets plotted
- Range High / Range Low lines: solid lines for current active bounds (color/width configurable).
- Prior confirmed bounds: optional historical channels for context.
- State label (optional): “Bullish” or “Bearish.”
- BOS markers (optional): markers when a body‑confirmed break flips state.

## Inputs
- Swing Left/Right Bars — lookback size for confirming a swing (default: 2/2).
- Use Body for Breaks — when enabled, only body (open/close) confirms BOS (default: ON).
- Plot Prior Channels — show historical confirmed ranges (default: ON).
- Extend Current Bounds — keep current high/low extended into the right (default: ON).
- Colors/Widths/Styles — customize lines, fills, and markers.
- Alert on State Flip — fire alerts when Bullish↔Bearish flips (default: OFF).

## How to use
1. Context first: Identify the active state (Bullish/Bearish) from the label and the most recent BOS marker.
2. Plan around bounds: In Bullish state, the low acts as invalidation; in Bearish state, the high acts as invalidation—per the body‑based rules.
3. Continuations: Expect continuation toward the range extreme until invalidation or a new opposite swing confirms.
4. Multi‑timeframe confluence: Overlay a higher‑timeframe instance to frame context, and a lower‑timeframe instance to refine timing.
5. Alerts: Enable Alert on State Flip to be notified when structure changes.

## Assumptions, limitations, and repainting policy
- No reverse‑engineering claim: This is an original implementation based on public swing/BOS concepts; it does not claim to replicate any third‑party closed‑source script.
- Body‑based confirmation: Because BOS requires body confirmation, intra‑bar wicks can probe beyond a bound without flipping state. Final decisions occur on bar close (or when an intrabar body crosses, if you run on lower‑timeframe data).
- Swing confirmation delay: Swing highs/lows require surrounding bars; confirmation is by definition delayed by your chosen lookback.
- Repainting: The indicator does not rewrite confirmed levels retroactively. The active (unconfirmed) swing can refine until confirmation, which is expected behavior for swing‑based tools.
- Not a signal generator: It maps structure; trade entries/exits remain the user’s responsibility.

## Alerts (suggested)
- State Flip Up: Trigger when a body closes above protected high.
- State Flip Down: Trigger when a body closes below protected low.

## Best practices
- Pair with volume/OBV or a momentum filter to avoid chasing late moves.
- Backtest your timeframe/asset to calibrate Swing Left/Right Bars for noise vs responsiveness.
- Use higher‑timeframe bounds as “primary map” and trade in their direction on lower timeframes.

## Credits & originality
- Inspired by broadly known swing‑structure and BOS ideas used in technical analysis.
- All logic presented here is our own implementation. We make no claims about equivalence to any other indicator.

---

Support & licensing: This is a closed‑source release. For integration questions or licensing, please DM: “I have a specific use case for the code of this script.”

Exención de responsabilidad

La información y las publicaciones que ofrecemos, no implican ni constituyen un asesoramiento financiero, ni de inversión, trading o cualquier otro tipo de consejo o recomendación emitida o respaldada por TradingView. Puede obtener información adicional en las Condiciones de uso.