OPEN-SOURCE SCRIPT
Mbedaiwi - Market Structure and Price Action

mbedaiwi - Market Structure & Price Action [v5.4]
Overview
This Pine Script v6 overlay brings market structure, liquidity events, order blocks, volume estimates, price imbalances, and chart-pattern candidates into one configurable workspace. It helps users examine where price has broken structure, where earlier zones remain active, and how several observations align on the same chart.
The indicator is intended for discretionary analysis and chart study. It is not an automated execution system or a backtested TradingView strategy.
Purpose and benefits
The integration follows a practical sequence: establish structure, locate relevant areas, observe price interaction, and optionally evaluate a rule-based setup. The components provide context for one another; agreement between them does not establish a probability of success.
1. Market structure
Internal and swing structure can be configured separately. The script supports SMC leg-transition detection and symmetric pivot detection, with adjustable lengths.
Each structure selector offers All, BOS, CHoCH (All), CHoCH, CHoCH+, and None. CHoCH (All) includes both ordinary and supported changes; CHoCH and CHoCH+ select their respective classifications. The separate Show BOS and Show CHoCH switches also affect visibility.
Historical and Present display modes, candle coloring, label sizes, and colored or monochrome themes provide additional control.
2. Order blocks and volume display
The script includes independent swing-break, volume-pivot, and legacy structure-break order-block engines. Available controls include zone boundaries, mitigation rules, retained-zone counts, overlap suppression, midlines, and breaker display.
Volume information can appear on the price-chart overlay, in a right-side chart, or in both locations. Users can choose the volume accumulation interval, including the interval between a broken pivot and its break, an origin window, or an origin-based interval.
How to read the volume numbers
The displayed volume belongs to the selected calculation interval. The percentage is that block's share of the summed volume of currently displayed non-breaker blocks. Changing visible blocks, filters, or retention settings can therefore change the percentages. They are not win rates or percentages of the instrument's entire trading volume.
Internal buy/sell activity is an OHLCV-based estimate. Close-location mode allocates volume according to the close's position within each candle's range; candle-direction mode allocates it according to candle direction. These estimates do not measure actual bid/ask transactions, institutional orders, or order-book liquidity. Volume-dependent outputs rely on the data supplied for the symbol.
3. Liquidity tools
Equal Highs and Equal Lows use an adjustable ATR-based tolerance. Liquidity Grabs identify excursions beyond tracked levels followed by a return inside those levels, subject to the detection rules.
Grabs are displayed as hollow frames around the relevant candle wick: blue for bullish lower-wick grabs and red for bearish upper-wick grabs by default. Optional text can be enabled. Detection sensitivity and retained history are adjustable.
Live previews can change or disappear before the candle closes. Liquidity Grab alerts require a confirmed bar. Separate trendline tools and trendline-break alerts are also available.
4. Price imbalances
The imbalance selector displays one of five types:
Controls include source timeframe, volatility threshold, extension, mitigation method, and maximum retained zones. The imbalance timeframe must be the chart timeframe or higher. Higher-timeframe imbalance detection uses completed source candles, so it becomes available after source-bar confirmation.
To hide only the FVG/type text while retaining the shaded zones, disable Show Imbalance Type on Zones. Re-enable it at any time from Inputs.
5. Premium, equilibrium, and discount
Optional bands divide a selected Swing, Internal, or Impulse range into upper, middle, and lower reference areas. Band width and colors are adjustable. These areas describe relative position within the selected range; they do not measure fundamental fair value or guarantee a reversal.
6. Chart-pattern candidates
The pattern module classifies recent pivot geometry and can display pattern boundaries, shaded zones, and a Detected Pattern table. Candidate types include triangles, wedges, broadening wedges, double tops/bottoms, and head-and-shoulders formations.
Pattern drawings are separate from the trendline module. Detection depends on pivot length, available history, and tolerance settings. In this release, a displayed pattern can remain after price has moved outside its boundaries until the detection state updates. Treat the pattern name as a geometric candidate, not confirmation that a formation remains valid or that a breakout will succeed.
7. Additional context and optional setup planning
Optional Fibonacci retracements, an OTE region, extension levels, and previous daily/weekly/monthly/quarterly highs and lows provide additional reference points.
The optional setup layer combines structural events with configurable checks such as liquidity sweeps, order-block or imbalance interaction, displacement, higher-timeframe direction, EMA alignment, volume, and RSI. Score and Strict modes control how these conditions are evaluated.
When enabled, the trade layer can display a hypothetical entry, stop, and up to three targets using configurable zone, structure, ATR, or risk-multiple methods. These are rule-based planning levels, not executed orders or verified performance results. The default mbedaiwi profile suppresses the trade layer.
How to use
Reading entries, stops, targets, and exits
Use the indicator as a sequence of observations: structural direction, an area to monitor, confirmation, and a predefined risk/target plan. A BOS, CHoCH, or Liquidity Grab on its own is not an automatic instruction to buy or sell.
Step 1 - Read the structural context
Start with Swing Structure for the broader context, then use Internal Structure to examine shorter movements. Higher highs and higher lows describe an upward structure; lower highs and lower lows describe a downward structure. A bullish BOS is classified as continuation, while a bullish CHoCH marks a potential change from the preceding bearish structure. CHoCH+ adds the script's supporting pivot-sequence condition; it does not guarantee a reversal.
An internal bullish change can occur while swing structure remains bearish. Always identify which structure level produced the label. Pivot confirmations can arrive after the turning point and be drawn back at the earlier pivot bar.
Step 2 - Identify an area to monitor
A bullish order block, bullish FVG, discount band, previous low, or Equal Lows can provide a reference area for studying a possible bullish reaction. Price entering an area only establishes an interaction; it does not confirm that a rebound has started. Order-block volume percentages are calculated volume shares, not probabilities that the area will hold.
Step 3 - Observe confirmation
The following is an illustrative manual reading sequence, not the mandatory algorithm behind every setup generated by the script:
A retest may never occur, and confirmation can still fail. Do not assume that a marker anchored to an earlier candle was available in real time on that candle.
Step 4 - Understand the optional planning layer
The planning layer displays hypothetical levels when its setup conditions are satisfied:
These are chart calculations. They do not send orders to a broker, establish actual fills, or move a real stop order.
To make this layer available, choose a profile such as Custom, enable Show trade layer (entry / SL / TP), and disable Structure only. The default mbedaiwi profile suppresses the trade layer. Enabling the display does not guarantee that levels appear immediately: the selected signal conditions and filters must also be satisfied.
Step 5 - Read risk multiples: a numerical example
Consider a hypothetical entry at 100 and a stop at 98. The distance between them is 2 per share, so 1R equals 2. In Risk multiple target mode:
This example explains arithmetic only. It is not a trade recommendation, a prediction, or a result produced by a backtest. It excludes fees and slippage. A real fill can differ from the plotted reference, and an actual exit can differ from the stop price. If the hypothetical breakeven option is enabled, a qualifying TP1 event changes the plotted stop reference to 100; this does not guarantee a cost-free exit in actual trading.
Step 6 - Interpret exits and changes in structure
A TP reached alert means that the script's target condition has been met. A Stop-loss reached alert means that its stop condition has been met. Neither confirms that a broker executed an order.
A bearish CHoCH during an upward move provides information about a structural change. It does not automatically mean that the planning layer closed a position, nor that every internal change requires the same response. Target exits, invalidation exits, and any discretionary response to opposing structure should be defined before acting on a setup. The script does not automatically carry out partial sales or discretionary exits described by a user's plan.
Manual analysis versus calculated setups
The manual sequence above explains how the visual components can be read together. The optional planning layer instead evaluates its configured rules, filters, and calculation methods. It does not necessarily require that exact sequence. Neither workflow supplies verified profitability or guarantees that a displayed setup will succeed.
Alerts
Available conditions cover internal and swing BOS/CHoCH/CHoCH+, liquidity grabs and sweeps, equal highs/lows, imbalance formation, zone interactions, order-block breaks, trendline breaks, detected patterns, and optional setup/target/stop events.
Select this indicator in TradingView's Create Alert dialog, then choose the event. Use Once Per Bar Close when you want close-confirmed notifications. General CHoCH alerts also include supported changes; separate CHoCH+ conditions are available. Some touch conditions can remain true across consecutive bars, so they should not be interpreted as one notification per zone for its entire lifetime.
Timing, historical drawings, and limitations
Source acknowledgment
The hierarchical pivot-detection logic used in the Liquidity Grabs module is adapted from LuxAlgo's open-source "Pure Price Action Liquidity Sweeps", licensed under CC BY-NC-SA 4.0. Modifications include wick-frame rendering, display controls, and alert handling. Credit for the adapted source logic belongs to LuxAlgo.
This acknowledgment concerns the identified open-source component and does not imply access to LuxAlgo's closed-source Price Action Concepts indicator. This publication is not affiliated with or endorsed by LuxAlgo.
Intended use
For educational chart analysis and discretionary decision support. Users remain responsible for validating the settings, interpreting signals, and managing risk. No displayed zone, pattern, or setup guarantees a particular market outcome.
Overview
This Pine Script v6 overlay brings market structure, liquidity events, order blocks, volume estimates, price imbalances, and chart-pattern candidates into one configurable workspace. It helps users examine where price has broken structure, where earlier zones remain active, and how several observations align on the same chart.
The indicator is intended for discretionary analysis and chart study. It is not an automated execution system or a backtested TradingView strategy.
Purpose and benefits
- Compare short-term internal structure with broader swing structure.
- Organize potential reaction areas using order blocks, imbalances, liquidity levels, and range bands.
- Compare the volume associated with visible order blocks through an overlay or a separate right-side display.
- Select the modules and labels needed for a particular workflow, reducing chart clutter.
- Use alerts to monitor defined events without continuously watching the chart.
The integration follows a practical sequence: establish structure, locate relevant areas, observe price interaction, and optionally evaluate a rule-based setup. The components provide context for one another; agreement between them does not establish a probability of success.
1. Market structure
Internal and swing structure can be configured separately. The script supports SMC leg-transition detection and symmetric pivot detection, with adjustable lengths.
- BOS: a break classified as continuation of the current structural direction.
- CHoCH: a break against the previous structural direction.
- CHoCH+: a CHoCH supported by an intervening higher low for a bullish change, or lower high for a bearish change, under this script's pivot and sequence rules.
- HH, HL, LH, and LL: higher highs, higher lows, lower highs, and lower lows.
- Strong/Weak High-Low: structural classifications based on the current directional state, not forecasts of whether a level will hold.
Each structure selector offers All, BOS, CHoCH (All), CHoCH, CHoCH+, and None. CHoCH (All) includes both ordinary and supported changes; CHoCH and CHoCH+ select their respective classifications. The separate Show BOS and Show CHoCH switches also affect visibility.
Historical and Present display modes, candle coloring, label sizes, and colored or monochrome themes provide additional control.
2. Order blocks and volume display
The script includes independent swing-break, volume-pivot, and legacy structure-break order-block engines. Available controls include zone boundaries, mitigation rules, retained-zone counts, overlap suppression, midlines, and breaker display.
Volume information can appear on the price-chart overlay, in a right-side chart, or in both locations. Users can choose the volume accumulation interval, including the interval between a broken pivot and its break, an origin window, or an origin-based interval.
How to read the volume numbers
The displayed volume belongs to the selected calculation interval. The percentage is that block's share of the summed volume of currently displayed non-breaker blocks. Changing visible blocks, filters, or retention settings can therefore change the percentages. They are not win rates or percentages of the instrument's entire trading volume.
Internal buy/sell activity is an OHLCV-based estimate. Close-location mode allocates volume according to the close's position within each candle's range; candle-direction mode allocates it according to candle direction. These estimates do not measure actual bid/ask transactions, institutional orders, or order-book liquidity. Volume-dependent outputs rely on the data supplied for the symbol.
3. Liquidity tools
Equal Highs and Equal Lows use an adjustable ATR-based tolerance. Liquidity Grabs identify excursions beyond tracked levels followed by a return inside those levels, subject to the detection rules.
Grabs are displayed as hollow frames around the relevant candle wick: blue for bullish lower-wick grabs and red for bearish upper-wick grabs by default. Optional text can be enabled. Detection sensitivity and retained history are adjustable.
Live previews can change or disappear before the candle closes. Liquidity Grab alerts require a confirmed bar. Separate trendline tools and trendline-break alerts are also available.
4. Price imbalances
The imbalance selector displays one of five types:
- FVG: a three-candle gap between the first and third candles' price ranges.
- Inverse FVG: a tracked FVG that is breached and reclassified in the opposite direction.
- Double FVG: an overlapping area between a new FVG and a tracked opposite-direction FVG.
- Volume Imbalance: a gap between adjacent candle bodies while their wick ranges overlap. Despite the name, this detection is price-based.
- Opening Gap: a gap between adjacent candle ranges.
Controls include source timeframe, volatility threshold, extension, mitigation method, and maximum retained zones. The imbalance timeframe must be the chart timeframe or higher. Higher-timeframe imbalance detection uses completed source candles, so it becomes available after source-bar confirmation.
To hide only the FVG/type text while retaining the shaded zones, disable Show Imbalance Type on Zones. Re-enable it at any time from Inputs.
5. Premium, equilibrium, and discount
Optional bands divide a selected Swing, Internal, or Impulse range into upper, middle, and lower reference areas. Band width and colors are adjustable. These areas describe relative position within the selected range; they do not measure fundamental fair value or guarantee a reversal.
6. Chart-pattern candidates
The pattern module classifies recent pivot geometry and can display pattern boundaries, shaded zones, and a Detected Pattern table. Candidate types include triangles, wedges, broadening wedges, double tops/bottoms, and head-and-shoulders formations.
Pattern drawings are separate from the trendline module. Detection depends on pivot length, available history, and tolerance settings. In this release, a displayed pattern can remain after price has moved outside its boundaries until the detection state updates. Treat the pattern name as a geometric candidate, not confirmation that a formation remains valid or that a breakout will succeed.
7. Additional context and optional setup planning
Optional Fibonacci retracements, an OTE region, extension levels, and previous daily/weekly/monthly/quarterly highs and lows provide additional reference points.
The optional setup layer combines structural events with configurable checks such as liquidity sweeps, order-block or imbalance interaction, displacement, higher-timeframe direction, EMA alignment, volume, and RSI. Score and Strict modes control how these conditions are evaluated.
When enabled, the trade layer can display a hypothetical entry, stop, and up to three targets using configurable zone, structure, ATR, or risk-multiple methods. These are rule-based planning levels, not executed orders or verified performance results. The default mbedaiwi profile suppresses the trade layer.
How to use
- Add the indicator to a standard candlestick chart and choose an analysis profile. The default mbedaiwi profile uses internal length 5, swing length 50, and close-based structural breaks. Select Custom or enable Override profile lengths when you want the manual lengths to take effect.
- Choose the internal and swing events you want to see. Start with structure and a small number of zones before enabling additional modules.
- Enable order-block metrics if you want volume comparisons. Select the accumulation method and overlay/side-chart layout appropriate for your analysis.
- Enable Liquidity Grabs and select detection sensitivity. Distinguish a live preview from a completed event.
- Choose an imbalance type and its mitigation method. Add premium/discount bands or prior-period levels if they help define context.
- Enable Patterns only when studying pivot-based formations, and check the actual candles against the displayed boundaries.
- Use Clean chart mode, individual visibility switches, label sizes, and zone-count controls to manage clutter. The Show tables switch controls on-chart tables.
- If using the optional setup layer, choose a compatible profile, review all filters and risk settings, and evaluate its behavior before relying on the planning levels.
Reading entries, stops, targets, and exits
Use the indicator as a sequence of observations: structural direction, an area to monitor, confirmation, and a predefined risk/target plan. A BOS, CHoCH, or Liquidity Grab on its own is not an automatic instruction to buy or sell.
Step 1 - Read the structural context
Start with Swing Structure for the broader context, then use Internal Structure to examine shorter movements. Higher highs and higher lows describe an upward structure; lower highs and lower lows describe a downward structure. A bullish BOS is classified as continuation, while a bullish CHoCH marks a potential change from the preceding bearish structure. CHoCH+ adds the script's supporting pivot-sequence condition; it does not guarantee a reversal.
An internal bullish change can occur while swing structure remains bearish. Always identify which structure level produced the label. Pivot confirmations can arrive after the turning point and be drawn back at the earlier pivot bar.
Step 2 - Identify an area to monitor
A bullish order block, bullish FVG, discount band, previous low, or Equal Lows can provide a reference area for studying a possible bullish reaction. Price entering an area only establishes an interaction; it does not confirm that a rebound has started. Order-block volume percentages are calculated volume shares, not probabilities that the area will hold.
Step 3 - Observe confirmation
The following is an illustrative manual reading sequence, not the mandatory algorithm behind every setup generated by the script:
- Price reaches a previously identified reference area.
- Price moves below a tracked low and closes back above it, producing a confirmed bullish Liquidity Grab if the detection conditions are met.
- Price subsequently breaks an internal structural level upward, producing a bullish CHoCH or CHoCH+ under the script's rules.
- The user evaluates the completed confirmation candle or a later retest of the broken level, together with the broader structure and the planned invalidation level.
A retest may never occur, and confirmation can still fail. Do not assume that a marker anchored to an earlier candle was available in real time on that candle.
Step 4 - Understand the optional planning layer
The planning layer displays hypothetical levels when its setup conditions are satisfied:
- Entry method: Market, Fibonacci, or Zone determines the entry-reference calculation.
- Stop method: Structure, ATR, or Zone determines the stop-reference calculation. The selected invalidation level defines where the planned idea no longer applies.
- Target method: Risk multiple, Smart money, or Hybrid determines how target references are calculated.
- TP1, TP2, and TP3: up to three target references, according to the selected method.
- Move stop to breakeven after TP1: updates the hypothetical stop to the entry reference after the first-target condition is met.
These are chart calculations. They do not send orders to a broker, establish actual fills, or move a real stop order.
To make this layer available, choose a profile such as Custom, enable Show trade layer (entry / SL / TP), and disable Structure only. The default mbedaiwi profile suppresses the trade layer. Enabling the display does not guarantee that levels appear immediately: the selected signal conditions and filters must also be satisfied.
Step 5 - Read risk multiples: a numerical example
Consider a hypothetical entry at 100 and a stop at 98. The distance between them is 2 per share, so 1R equals 2. In Risk multiple target mode:
- Entry reference: 100.
- Stop reference: 98.
- 1R target: 102.
- 2R target: 104.
- 3R target: 106.
This example explains arithmetic only. It is not a trade recommendation, a prediction, or a result produced by a backtest. It excludes fees and slippage. A real fill can differ from the plotted reference, and an actual exit can differ from the stop price. If the hypothetical breakeven option is enabled, a qualifying TP1 event changes the plotted stop reference to 100; this does not guarantee a cost-free exit in actual trading.
Step 6 - Interpret exits and changes in structure
A TP reached alert means that the script's target condition has been met. A Stop-loss reached alert means that its stop condition has been met. Neither confirms that a broker executed an order.
A bearish CHoCH during an upward move provides information about a structural change. It does not automatically mean that the planning layer closed a position, nor that every internal change requires the same response. Target exits, invalidation exits, and any discretionary response to opposing structure should be defined before acting on a setup. The script does not automatically carry out partial sales or discretionary exits described by a user's plan.
Manual analysis versus calculated setups
The manual sequence above explains how the visual components can be read together. The optional planning layer instead evaluates its configured rules, filters, and calculation methods. It does not necessarily require that exact sequence. Neither workflow supplies verified profitability or guarantees that a displayed setup will succeed.
Alerts
Available conditions cover internal and swing BOS/CHoCH/CHoCH+, liquidity grabs and sweeps, equal highs/lows, imbalance formation, zone interactions, order-block breaks, trendline breaks, detected patterns, and optional setup/target/stop events.
Select this indicator in TradingView's Create Alert dialog, then choose the event. Use Once Per Bar Close when you want close-confirmed notifications. General CHoCH alerts also include supported changes; separate CHoCH+ conditions are available. Some touch conditions can remain true across consecutive bars, so they should not be interpreted as one notification per zone for its entire lifetime.
Timing, historical drawings, and limitations
- Pivot-based features require later bars to confirm earlier turning points. Labels and zones may be anchored back to those earlier bars, although the information was not available at that time.
- Live candles and enabled previews can change before close. This indicator is not presented as universally non-repainting.
- Zone removal depends on mitigation, age, overlap, and retention settings. Older drawings can disappear as new observations replace them.
- Results depend on the symbol, timeframe, session, available history, and settings. Different indicators can use different definitions and produce different results.
- The confluence score is a rule-based score, not a calibrated probability. Volume percentages and Strong/Weak labels are not measures of signal accuracy.
- The planning layer does not provide a broker execution model, Strategy Tester results, or verified profitability. No accuracy, return, or future-performance claim is made.
Source acknowledgment
The hierarchical pivot-detection logic used in the Liquidity Grabs module is adapted from LuxAlgo's open-source "Pure Price Action Liquidity Sweeps", licensed under CC BY-NC-SA 4.0. Modifications include wick-frame rendering, display controls, and alert handling. Credit for the adapted source logic belongs to LuxAlgo.
This acknowledgment concerns the identified open-source component and does not imply access to LuxAlgo's closed-source Price Action Concepts indicator. This publication is not affiliated with or endorsed by LuxAlgo.
Intended use
For educational chart analysis and discretionary decision support. Users remain responsible for validating the settings, interpreting signals, and managing risk. No displayed zone, pattern, or setup guarantees a particular market outcome.
オープンソーススクリプト
TradingViewの精神に則り、このスクリプトの作者はコードをオープンソースとして公開してくれました。トレーダーが内容を確認・検証できるようにという配慮です。作者に拍手を送りましょう!無料で利用できますが、コードの再公開はハウスルールに従う必要があります。
免責事項
これらの情報および投稿は、TradingViewが提供または承認する金融、投資、取引、またはその他の種類の助言もしくは推奨であることを意図したものではなく、またこれらに該当するものでもありません。詳細は利用規約をご覧ください。
オープンソーススクリプト
TradingViewの精神に則り、このスクリプトの作者はコードをオープンソースとして公開してくれました。トレーダーが内容を確認・検証できるようにという配慮です。作者に拍手を送りましょう!無料で利用できますが、コードの再公開はハウスルールに従う必要があります。
免責事項
これらの情報および投稿は、TradingViewが提供または承認する金融、投資、取引、またはその他の種類の助言もしくは推奨であることを意図したものではなく、またこれらに該当するものでもありません。詳細は利用規約をご覧ください。