OPEN-SOURCE SCRIPT

Smart VWAP FVG System

83
Smart VWAP FVG System - Professional Multi-Filter Trading Indicator
📊 OVERVIEW
The Smart VWAP FVG System is an advanced multi-layered trading indicator that combines institutional volume analysis, multi-timeframe VWAP trend confirmation, and Fair Value Gap detection to identify high-probability trade entries. This indicator uses a sophisticated filtering mechanism where signals appear only when multiple independent confirmation criteria align simultaneously.
Recommended Timeframe: 5-minute (M5) or higher. The indicator works best on M5, M15, and M30 charts for intraday trading.

🎯 ORIGINALITY & PURPOSE
This indicator is original because it combines three distinct analytical methods into a unified decision-making system:

Market Profile Volume Analysis - Identifies institutional accumulation/distribution zones
Dual VWAP Filtering - Confirms trend direction using two independent VWAP calculations
Fair Value Gap Detection - Validates institutional interest through price inefficiency zones

The key innovation is the directional filter system: the primary Market Profile generates BUY-ONLY or SELL-ONLY states based on higher timeframe value area reversals, which then controls which signals from the main system are displayed. This creates a multi-timeframe confluence that significantly reduces false signals.
Unlike simple indicator mashups, each component serves a specific purpose:

Market Profile → Direction bias (trend filter)
Primary VWAP (Session) → Short-term trend confirmation
Secondary VWAP (Week) → Medium-term trend confirmation
FVG Detection → Institutional activity validation


🔧 HOW IT WORKS
1. Primary Market Profile Filter (Higher Timeframe)
The indicator calculates Market Profile on a higher timeframe (default: 1 hour) to determine the overall market structure:

Value Area High (VAH): Top 70% of volume distribution
Value Area Low (VAL): Bottom 70% of volume distribution
Point of Control (POC): Price level with highest volume

When price reaches VAH and reverses down → SELL-ONLY mode activated
When price reaches VAL and reverses up → BUY-ONLY mode activated
This higher timeframe filter ensures you're trading in the direction of institutional flow.
2. Dual VWAP System
Two independent VWAP calculations provide multi-timeframe trend confirmation:

Primary VWAP (Session-based): Resets daily, tracks intraday momentum
Secondary VWAP (Week-based): Resets weekly, confirms longer-term trend

Filter Logic:

BUY signals require: Price > Primary VWAP AND Price > Secondary VWAP
SELL signals require: Price < Primary VWAP AND Price < Secondary VWAP

This dual confirmation prevents counter-trend trades during ranging conditions.
3. Fair Value Gap (FVG) Detection
FVG zones identify price inefficiencies where institutional orders were executed rapidly:

Bullish FVG: Gap between candle[3].high and candle[1].low (upward imbalance)
Bearish FVG: Gap between candle[1].high and candle[3].low (downward imbalance)

The indicator monitors recent FVG formation (lookback: 50 bars) and requires:

Bullish FVG present for BUY signals
Bearish FVG present for SELL signals

FVG zones are displayed as colored boxes and automatically marked as "mitigated" when price fills the gap.
4. Main Trading Signal Logic
The secondary Market Profile (default: 1 hour) generates the actual trading signals:
BUY Signal Conditions:

Price reaches Value Area Low
Reversal pattern confirmed (minimum 1 bar)
Price > Primary VWAP
Price > Secondary VWAP (if filter enabled)
Recent Bullish FVG detected (if filter enabled)
Primary MP Filter = BUY-ONLY or NEUTRAL

SELL Signal Conditions:

Price reaches Value Area High
Reversal pattern confirmed (minimum 1 bar)
Price < Primary VWAP
Price < Secondary VWAP (if filter enabled)
Recent Bearish FVG detected (if filter enabled)
Primary MP Filter = SELL-ONLY or NEUTRAL

All conditions must be TRUE simultaneously for a signal to appear.

📈 VISUAL ELEMENTS
On Chart:

🟢 Green Triangle (▲) = BUY Signal
🔴 Red Triangle (▼) = SELL Signal
🟦 Blue horizontal lines = Value Area zones
🟡 Yellow line = Point of Control (POC)
🟩 Green boxes = Bullish FVG zones
🟥 Red boxes = Bearish FVG zones
🔵 Blue line = Primary VWAP (Session)
⚪ White line = Secondary VWAP (Week)

Info Panel (Top Right):
Real-time status display showing:

Filter Direction (BUY ONLY / SELL ONLY / NEUTRAL)
Active timeframes for both MP filters
FVG filter status and count
VWAP positions (ABOVE/BELOW)
Signal enablement status
Alert status


⚙️ KEY SETTINGS
MP/TPO Filter Settings (Primary Indicator)

MP Filter Time Frame: 60 minutes (controls directional bias)
Filter Value Area %: 70% (standard Market Profile calculation)
Filter Alert Distance: 1 bar
Filter Min Bars for Reversal: 1 bar
Filter Alert Zone Margin: 0.01 (1%)

FVG Filter Settings

Use FVG Filter: Enabled (toggle on/off)
FVG Timeframe: 60 minutes (1 hour)
FVG Filter Mode: Both (require bullish FVG for BUY, bearish for SELL)
FVG Lookback Period: 50 bars (how far back to search)
Show FVG Formation Signals: Optional visual markers
Max FVG on Chart: 50 zones
Show Mitigated FVG: Display filled gaps

Market Profile Settings

Higher Time Frame: 60 minutes (for main signals)
Percent for Value Area: 70%
Show POC Line: Enabled
Keep Old MPs: Enabled (maintain historical profiles)

Primary VWAP Filter

Use Primary VWAP Filter: Enabled
Primary VWAP Anchor Period: Session (resets daily)
Primary VWAP Source: HLC3 (typical price)

Secondary VWAP Filter

Use Secondary VWAP Filter: Enabled
Secondary VWAP Anchor Period: Week (resets weekly)
Secondary VWAP Filter Mode: Both
Secondary VWAP Line Color: White

Trading Signals

Show Trading Signals on Chart: Enabled
Show SELL Signals: Enabled
Show BUY Signals: Enabled
Alert Distance: 1 bar
Min Bars for Reversal: 1 bar
Alert Zone Margin: 0.01 (1%)
Retest Search Period: 20 bars
Min Bars Between Retests: 5 bars
Show Only Retests: Disabled

Alert Settings

Enable Trading Notifications: Enabled
VAH Reversal Alert: Enabled (SELL signals)
VAL Reversal Alert: Enabled (BUY signals)

Time Filter Settings

Filter Alerts By Time: Optional (exclude specific hours)


⚠️ IMPORTANT WARNINGS & LIMITATIONS
1. Repainting Behavior
CRITICAL: This indicator uses lookahead=barmerge.lookahead_on to access higher timeframe data immediately for FVG detection. This is necessary to provide real-time FVG zone visualization but has the following implications:

FVG zones may shift slightly until the higher timeframe candle closes
FVG detection signals are preliminary until HTF bar confirmation
The main trading signals (triangles) appear on confirmed bars and do not repaint

Best Practice: Always wait for the current timeframe bar to close before acting on signals. The filter status and FVG zones are informational but may adjust as new data arrives.
2. Minimum Timeframe

Do NOT use on timeframes below 5 minutes (M5)
Recommended: M5, M15, M30 for intraday trading
Higher timeframes (H1, H4) can also be used but will generate fewer signals

3. Multiple Filters Can Block Signals
By design, this indicator is conservative. When all filters are enabled:

Signals appear ONLY when all conditions align
You may see extended periods with no signals
This is intentional to reduce false positives

If you see no signals:

Check the Info Panel to see which filters are failing
Consider adjusting FVG lookback period
Temporarily disable FVG filter to test
Verify VWAP filters match current market trend

4. Market Profile Limitations

Market Profile requires sufficient volume data
Low-volume instruments may produce unreliable profiles
Value Areas update only on higher timeframe bar close
Works best on liquid markets (major forex pairs, indices, crypto)


📖 HOW TO USE
Step 1: Add to Chart

Apply indicator to M5 or higher timeframe chart
Ensure chart shows volume data
Use standard candles (NOT Heikin Ashi, Renko, etc.)

Step 2: Configure Settings

Primary MP Filter TF: Set to 60 (1 hour) minimum, or 240 (4 hour) for swing trading
Main MP TF: Set to 60 (1 hour) for intraday signals
FVG Timeframe: Match or exceed main MP timeframe
Leave other settings at default initially

Step 3: Understand the Info Panel
Monitor the top-right panel:

FILTER STATUS: Shows current directional bias

NEUTRAL = Both signals allowed
BUY ONLY = Only green triangles will appear
SELL ONLY = Only red triangles will appear


FVG Filter: Shows if bullish/bearish gaps detected recently
VWAP positions: Confirms trend alignment

Step 4: Take Signals
For BUY Signal (Green Triangle ▲):

Wait for green triangle to appear
Check Info Panel shows ✓ for BUY signals
Confirm current bar has closed
Enter long position
Stop loss: Below recent VAL or swing low
Target: Previous Value Area High or 1.5-2× risk

For SELL Signal (Red Triangle ▼):

Wait for red triangle to appear
Check Info Panel shows ✓ for SELL signals
Confirm current bar has closed
Enter short position
Stop loss: Above recent VAH or swing high
Target: Previous Value Area Low or 1.5-2× risk

Step 5: Risk Management

Risk per trade: Maximum 1-2% of account equity
Position sizing: Adjust based on stop loss distance
Avoid trading: During major news events or time filter periods
Multiple confirmations: Look for confluence with price action (support/resistance, trendlines)


🎓 UNDERLYING CONCEPTS
Market Profile Theory
Developed by J. Peter Steidlmayer in the 1980s, Market Profile organizes price and volume data to identify:

Value Areas: Where 70% of trading activity occurred
POC: Price level with highest acceptance (most volume)
Imbalances: When price moves away from value quickly

This indicator uses TPO (Time Price Opportunity) calculation method to build the volume profile distribution.
VWAP (Volume Weighted Average Price)
VWAP represents the average price weighted by volume, showing where institutional traders are positioned:

Price above VWAP = Bullish (institutions accumulated lower)
Price below VWAP = Bearish (institutions distributed higher)

Using dual VWAP (Session + Week) creates multi-timeframe trend alignment.
Fair Value Gaps (FVG)
Also known as "imbalance" or "inefficiency," FVG occurs when:

Price moves so rapidly that a gap forms in the candlestick structure
Indicates institutional order flow (large market orders)
Price often returns to "fill" these gaps (rebalance)

The 3-candle FVG pattern (gap between candle[3] and candle[1]) is widely used in ICT (Inner Circle Trader) methodology and Smart Money Concepts.

🔍 CREDITS & CODE ATTRIBUTION
This indicator builds upon established technical analysis concepts and combines multiple methodologies:
1. Market Profile / TPO Calculation

Concept Origin: J. Peter Steidlmayer (Chicago Board of Trade, 1980s)
Code Inspiration: TradingView's public domain Market Profile examples
Modifications: Custom filtering logic for directional bias, dual timeframe implementation

2. VWAP Calculation

Concept Origin: Standard financial instrument (widely used since 1980s)
Code Base: TradingView built-in ta.vwap() function (public domain)
Modifications: Dual VWAP system with independent anchor periods, custom filtering modes

3. Fair Value Gap Detection

Concept Origin: Inner Circle Trader (ICT) / Smart Money Concepts methodology
Code Implementation: Original implementation based on 3-candle gap pattern
Features: Multi-timeframe detection, automatic mitigation tracking, visual zone display

4. Pine Script Framework

Language: Pine Script v6 (TradingView)
Built-in Functions Used:

ta.vwap() - Volume weighted average price
request.security() - Higher timeframe data access
ta.change() - Period detection
ta.cum() - Cumulative volume
time() - Timestamp functions



Note: All code is original implementation. While concepts are based on established trading methodologies, the combination, filtering logic, and execution are unique to this indicator.

📊 RECOMMENDED INSTRUMENTS
Best Performance:

Major Forex Pairs (EURUSD, GBPUSD, USDJPY)
Stock Indices (ES, NQ, SPX, DAX)
Major Cryptocurrencies (BTCUSD, ETHUSD)
Liquid Stocks (high daily volume)

Avoid:

Low-volume altcoins
Illiquid stocks
Exotic forex pairs with wide spreads


⚡ PERFORMANCE TIPS

Start Conservative: Enable all filters initially
Reduce Filters Gradually: If too few signals, disable Secondary VWAP filter first
Match Timeframes: Keep MP Filter TF and FVG TF at same value
Backtest First: Review historical performance on your preferred instrument/timeframe
Combine with Price Action: Look for support/resistance confluence
Use Time Filter: Avoid low-liquidity hours (optional setting)


🚫 WHAT THIS INDICATOR DOES NOT DO

Does not guarantee profits - No trading system is 100% accurate
Does not predict the future - Based on historical patterns
Does not replace risk management - Always use stop losses
Does not work on all instruments - Requires volume data and liquidity
Does not provide exact entry/exit prices - Signals are zones, not precise levels
Does not account for fundamentals - Purely technical analysis


📜 DISCLAIMER
This indicator is provided for educational and informational purposes only. It is not financial advice, and past performance does not guarantee future results.
Trading Risk Warning:

All trading involves risk of loss
You can lose more than your initial investment (leverage products)
Only trade with capital you can afford to lose
Always use appropriate position sizing and risk management
Consider seeking advice from a licensed financial advisor

Technical Limitations:

Indicator may repaint FVG zones until HTF bar closes
Signals are based on historical patterns that may not repeat
Market conditions change and no system works in all environments
Volume data quality varies by exchange/broker

By using this indicator, you acknowledge these risks and agree that the author bears no responsibility for trading losses.

📞 SUPPORT & UPDATES

Questions? Comment on this publication
Issues? Describe the problem with chart screenshot
Feature Requests? Suggest improvements in comments
Updates: Will be published as new versions using TradingView's update feature


📝 VERSION HISTORY
Version 1.0 (Current)

Initial public release
Multi-filter system: MP + Dual VWAP + FVG
Directional bias filter
Real-time info panel
Comprehensive alert system
Time-based filtering


Thank you for using Smart VWAP FVG System!
Happy Trading! 📈

Thông báo miễn trừ trách nhiệm

Thông tin và ấn phẩm không có nghĩa là và không cấu thành, tài chính, đầu tư, kinh doanh, hoặc các loại lời khuyên hoặc khuyến nghị khác được cung cấp hoặc xác nhận bởi TradingView. Đọc thêm trong Điều khoản sử dụng.