OPEN-SOURCE SCRIPT

QIFM SMC Market Structure

1 100
QIFM SMC Market Structure — 2CR/2CG, BOS, CHoCH, FVG & OB

OVERVIEW

QIFM SMC Market Structure is a rule-based charting indicator designed to identify and display developing market structure using a custom Two-Candle Retracement framework.

The indicator combines:

• Two-Candle Retracement confirmation: 2CR and 2CG
• Developing and confirmed Break of Structure levels
• Pending and confirmed Change of Character levels
• Dual CHoCH identification
• Structure-based Fibonacci retracement levels
• Structure-leg Fair Value Gaps
• Order Blocks associated with accepted FVG patterns
• Previous Day High and Low
• Previous Week High and Low
• Optional candle classification and live OHLC analysis

This is a market-structure analysis tool. It does not place trades, calculate position size, or provide guaranteed buy and sell signals.

ORIGINALITY AND PURPOSE

The central feature of this indicator is its custom structure-confirmation sequence.

Instead of defining every local high or low as market structure, the script waits for a specific two-candle retracement condition before establishing a pending BOS level. Confirmed BOS and CHoCH events are then used to control where the indicator searches for FVG and Order Block zones.

The main original component is the sequencing of:

Impulse extreme → 2CR/2CG confirmation → pending BOS → confirmed BOS → protected CHoCH point → confirmed CHoCH → structure-leg FVG and OB filtering.

This structure-based filtering is intended to reduce the number of randomly marked gaps and blocks that are not connected to a confirmed market-structure event.

1. TWO-CANDLE RETRACEMENT: 2CR AND 2CG

The indicator uses two types of retracement confirmation.

2CR — Two-Candle Red Retracement

During a developing bullish structure:

• The script records a bearish candle as the first retracement candle.
• The next bearish candle must close below the low of the first bearish candle.
• When this condition is completed, the pattern is marked as 2CR.
• The highest price reached before the confirmed retracement becomes the pending bullish BOS level.

2CG — Two-Candle Green Retracement

During a developing bearish structure:

• The script records a bullish candle as the first retracement candle.
• The next bullish candle must close above the high of the first bullish candle.
• When this condition is completed, the pattern is marked as 2CG.
• The lowest price reached before the confirmed retracement becomes the pending bearish BOS level.

Inside-range behavior is also evaluated while the pattern is developing. A candle contained within the tracked range does not automatically confirm the retracement.

2. PENDING AND CONFIRMED BREAK OF STRUCTURE

After a valid 2CR or 2CG pattern, the script creates a waiting BOS line.

Bullish BOS:

• A 2CR confirms the retracement.
• The preceding bullish extreme becomes the pending BOS level.
• A bullish BOS is confirmed when a candle closes above that level.

Bearish BOS:

• A 2CG confirms the retracement.
• The preceding bearish extreme becomes the pending BOS level.
• A bearish BOS is confirmed when a candle closes below that level.

The waiting BOS line and the confirmed BOS line have separate style, width, and color controls.

A wick through the BOS level is not sufficient. BOS confirmation is based on the candle close.

3. PENDING CHoCH POINT

After a confirmed bullish BOS, the lowest point of the confirmed retracement becomes the bearish protected structure level.

After a confirmed bearish BOS, the highest point of the confirmed retracement becomes the bullish protected structure level.

This protected level is displayed as:

P.CHoCH — Pending Change of Character

The active pending CHoCH line represents the level that must be broken to confirm a potential change in the current market structure.

Users can separately display:

• The current pending CHoCH level
• Previous pending CHoCH levels

4. CONFIRMED CHANGE OF CHARACTER

A CHoCH requires two consecutive candle closes beyond the active protected level.

Bearish CHoCH:

• The current structure is bullish.
• Two consecutive candles close below the active bearish P.CHoCH level.
• The script marks a confirmed bearish CHoCH.
• The internal trend state changes from bullish to bearish.

Bullish CHoCH:

• The current structure is bearish.
• Two consecutive candles close above the active bullish P.CHoCH level.
• The script marks a confirmed bullish CHoCH.
• The internal trend state changes from bearish to bullish.

The candle colors are not used for CHoCH confirmation. Only the two consecutive closing prices relative to the protected level are evaluated.

5. DUAL CHoCH

The Dual CHoCH feature tracks an additional structural reference following a confirmed change in direction.

It is intended to highlight a secondary two-close break beyond the previous structural extreme. This can help users distinguish an initial change of character from a more developed structural transition.

Dual CHoCH lines, labels, colors, widths, and styles can be customized separately.

6. STRUCTURE-BASED FIBONACCI LEVELS

When a valid 2CR or 2CG creates a pending BOS setup, the indicator calculates Fibonacci levels across the relevant structure range.

The visible default levels are:

• 0.50
• 0.618
• 0.70
• 1.00

The script can display:

• The current structure Fibonacci
• A selected number of previous Fibonacci structures
• Individual Fibonacci level labels
• Custom colors, widths, and line styles

The 0.50-to-1.00 portion of the calculated range is also used internally as a location filter for qualifying FVG and Order Block zones.

In bullish structure, this generally represents the deeper or discount side of the measured range.

In bearish structure, this generally represents the deeper or premium side of the measured range.

Fibonacci levels are reference locations only. They are not automatic trade-entry signals.

7. FAIR VALUE GAP LOGIC

The script does not search for FVGs across every candle on the chart.

It searches for FVGs only inside confirmed BOS and CHoCH displacement legs.

Bullish FVG requirements include:

• A three-candle bullish wick imbalance
• The third candle’s low is above the first candle’s high
• The third candle closes above the second candle’s high
• Additional inside-candle checks reject compressed or fully contained formations
• The FVG and its associated Order Block must be positioned within the active Fibonacci filtering band

Bearish FVG requirements include:

• A three-candle bearish wick imbalance
• The third candle’s high is below the first candle’s low
• The third candle closes below the second candle’s low
• Additional inside-candle checks reject compressed or fully contained formations
• The FVG and its associated Order Block must be positioned within the active Fibonacci filtering band

Only qualifying structure-leg FVGs are displayed.

8. ORDER BLOCK LOGIC

For each accepted FVG pattern, the script defines the full high-to-low range of the first candle in the three-candle FVG formation as the associated Order Block.

The OB is therefore directly connected to:

• A confirmed BOS or CHoCH leg
• An accepted three-candle FVG pattern
• The active Fibonacci location filter

Bullish and bearish Order Blocks have separate visibility and color settings.

The OB zones are analytical reference areas. They should not be treated as guaranteed reversal or entry locations.

9. FVG AND OB MITIGATION

Users can choose between two FVG mitigation methods.

First Touch:

The zone is considered mitigated when price first enters the FVG boundary.

Full Fill:

The zone remains active until price reaches the opposite boundary of the FVG.

When mitigation occurs, users can choose to:

• Keep the zone as faded historical information
• Hide the completed zone

The associated OB is updated together with its corresponding FVG.

Historical zones show where a valid structure-leg imbalance previously existed. They do not indicate that the zone remains tradable.

10. PREVIOUS DAY AND PREVIOUS WEEK LEVELS

The indicator can display:

• PDH — Previous Day High
• PDL — Previous Day Low
• PWH — Previous Week High
• PWL — Previous Week Low

These values are taken from completed daily and weekly periods.

PDH and PDL alert conditions are included. An alert can be triggered when price touches the active Previous Day High or Previous Day Low for the first time relative to the preceding chart bar.

The levels are contextual liquidity references and are not independent buy or sell signals.

11. OPTIONAL CANDLE ANALYSIS

The optional live candle-analysis panel displays:

• Candle status: live or closed
• Bullish, bearish, or doji classification
• Open, high, low, and close
• Candle-body percentage
• Upper and lower wick sizes
• Full-range or body-inside classification
• Direct 2CR or 2CG close test

Users can also enable candle coloring based on the same classifications.

The panel is intended for studying the conditions used by the structure engine. It is not an order-execution panel.

HOW TO USE THE INDICATOR

1. Use a standard candlestick chart.

2. Select the symbol and timeframe appropriate for your analysis.

3. Observe whether the script is tracking a bullish or bearish structural sequence.

4. Wait for a confirmed 2CR or 2CG marker.

5. Observe the waiting BOS line created at the preceding impulse extreme.

6. Wait for a candle close beyond the waiting BOS line to confirm BOS.

7. After BOS, monitor the newly created P.CHoCH level.

8. A CHoCH is confirmed only after two consecutive closes beyond the protected level.

9. Use structure-leg FVG, OB, Fibonacci, PDH, PDL, PWH, and PWL zones as additional context.

10. Apply independent risk management and entry confirmation before making any trading decision.

The indicator is best used as a chart-organization and market-structure tool rather than as a standalone trading system.

IMPORTANT SETTINGS

2CR / 2CG Settings:

Control retracement labels, zone visibility, colors, and the maximum number of displayed zones.

BOS Settings:

Control waiting BOS lines, confirmed BOS lines, labels, colors, widths, and styles.

CHoCH Settings:

Control confirmed and pending CHoCH levels, previous protected levels, labels, colors, widths, and styles.

Dual CHoCH Settings:

Control secondary CHoCH lines and labels.

BOS Fib Settings:

Control the current Fibonacci structure, previous structures, visible retracement levels, labels, colors, widths, and styles.

FVG Settings:

Control bullish and bearish FVG visibility, mitigation method, active zones, historical zones, scan distance, colors, and maximum stored zones.

Order Block Settings:

Control bullish and bearish OB visibility, active zones, historical zones, text, borders, and colors.

Previous Day / Week Levels:

Control PDH, PDL, PWH, and PWL visibility and PDH/PDL alerts.

Candle Analysis:

Control the live OHLC panel and optional candle classification colors.

REAL-TIME BEHAVIOR

The current candle’s high, low, close, classification, developing structure, and panel values can change while the candle is still open.

Close-dependent conditions such as:

• 2CR confirmation
• 2CG confirmation
• BOS confirmation
• CHoCH confirmation
• FVG body confirmation

should be evaluated after the relevant candle has closed.

Confirmed historical calculations do not intentionally use future candles. Previous-day and previous-week levels are taken from completed reference periods.

LIMITATIONS

• The script begins with an internal bullish structure state and then adapts as confirmed structure events occur.

• Market structure depends on the selected symbol, timeframe, data feed, and available chart history.

• Lower timeframes may produce more structural changes and visual noise.

• A confirmed BOS or CHoCH does not guarantee continuation or reversal.

• FVG, OB, Fibonacci, PDH, PDL, PWH, and PWL levels can be crossed without producing a reaction.

• The script does not account for spread, commission, slippage, economic news, liquidity conditions, or position sizing.

• The number of displayed historical objects is limited by the selected settings and TradingView’s drawing-object limits.

• Results can differ between brokers or exchanges because their OHLC data may differ.

ALERTS

The current version includes alert conditions for:

• Previous Day High touched
• Previous Day Low touched

Users should create alerts from TradingView’s alert menu after adding the indicator to a chart.

EDUCATIONAL DISCLAIMER

This indicator is provided for technical-analysis, educational, and informational purposes only.

It is not investment advice, financial advice, or a recommendation to buy or sell any financial instrument. No market-structure event, FVG, Order Block, Fibonacci level, or previous-period level can guarantee a profitable outcome.

Trading and investing involve substantial risk. Users are responsible for independently evaluating all information, testing the indicator, managing their risk, and making their own trading decisions. Past market behavior does not guarantee future results.

إخلاء المسؤولية

لا يُقصد بالمعلومات والمنشورات أن تكون، أو تشكل، أي نصيحة مالية أو استثمارية أو تجارية أو أنواع أخرى من النصائح أو التوصيات المقدمة أو المعتمدة من TradingView. اقرأ المزيد في شروط الاستخدام.