OPEN-SOURCE SCRIPT

MTF OB & FVG detector w/ Alerts v2

68
# MTF Order Blocks & Fair Value Gaps Detector with Alerts v2

## Overview

This indicator combines **Multi-Timeframe Order Blocks (OB)** and **Fair Value Gaps (FVG)** detection with integrated bounce alerts. It displays Order Blocks and Fair Value Gaps across multiple timeframes simultaneously and generates real-time alerts when price bounces from these critical zones.

## Key Features

### 🎯 Multi-Timeframe Order Blocks Detection
- **Volumetric Analysis**: Each Order Block displays total volume and dominant side percentage
- **Multiple Timeframes**: Supports 1min, 3min, 5min, 15min, and 60min timeframes
- **Smart Combining**: Automatically merges overlapping Order Blocks from different timeframes into powerful confluence zones
- **Dynamic Extension**: Order Blocks extend until broken, providing clear visual guidance
- **Volume Distribution**: Shows bullish vs bearish volume breakdown with percentage

### 📊 Fair Value Gaps (FVG) Detection
- **Lightweight Processing**: Works on current chart timeframe only for optimal performance
- **Volume Metrics**: Displays FVG volume and dominant side percentage
- **Mitigation Tracking**: Automatically tracks when FVGs are filled or broken
- **Customizable Mitigation Source**: Choose between close price or high/low wicks

### 🔔 Comprehensive Alert System
- **Bounce Alerts**: Get notified when price bounces from OB or FVG zones
- **New Formation Alerts**: Alerts when new Order Blocks or Fair Value Gaps form
- **Combined Zone Alerts**: Special alerts when multiple Order Blocks merge into strong confluence zones
- **Customizable Thresholds**: Set minimum number of combined OBs required for strong zone alerts

### 🎨 Visual Customization
- **Inverted Color Schemes**: Optional inverted colors for both OB and FVG
- OB: Choose between traditional (Bullish=Blue, Bearish=Red) or inverted (Bullish=Red, Bearish=Blue)
- FVG: Choose between Bullish=Orange/Bearish=Aqua or inverted
- **Clean Labels**: Shows timeframe, zone type, volume, and dominant percentage
- **Combined Tags**: Optional [Combined] labels for merged zones
- **Adjustable Extension**: Control how far zones extend into the future

## How It Works

### Order Blocks
Order Blocks identify institutional trading zones where large players have placed significant orders. The indicator:
1. Detects swing highs/lows using configurable swing length
2. Identifies the last opposing candle before a strong move
3. Analyzes volume distribution (bullish vs bearish)
4. Tracks zone validity until price breaks through
5. Combines overlapping zones from multiple timeframes

### Fair Value Gaps
Fair Value Gaps represent price imbalances that often get filled. The indicator:
1. Identifies 3-candle patterns with gaps between candles
2. Filters gaps by size percentile to show only significant ones
3. Calculates volume distribution within the gap
4. Tracks mitigation when price returns to fill the gap
5. Extends gaps dynamically until filled

### Bounce Detection
The indicator detects bounces using a two-step process:
1. **Touch Phase**: Tracks when price enters a zone (touchedInside flag)
2. **Bounce Phase**: Confirms bounce when price exits the zone in the expected direction
- Bullish zones: Price closes above top after touching inside
- Bearish zones: Price closes below bottom after touching inside

## Settings Guide

### General Configuration
- **Show Historic Zones**: Display invalidated/broken zones
- **Zone Invalidation**: Choose between wick or close for break detection
- **Combine Overlapping Order Blocks**: Merge OBs from different timeframes
- **Swing Length**: Controls sensitivity (smaller = more OBs, larger = fewer OBs)
- **Zone Count**: Choose from High/Medium/Low/One per timeframe
- **Invert Colors OB**: Swap bullish/bearish color scheme

### Alert Settings
- **Enable Alerts**: Master switch for all alerts
- **Alert on Bullish/Bearish Bounce**: Choose which bounce directions to monitor
- **Alert on New OB Formation**: Get notified when new Order Blocks form
- **Alert on Combined OBs**: Alerts for strong confluence zones
- **Min OBs for Strong Zone Alert**: Threshold for combined zone alerts (default: 2)

### Fair Value Gaps
- **Show Fair Value Gaps**: Toggle FVG display
- **FVG Mitigation Source**: Choose close or high/low for mitigation detection
- **Bullish/Bearish FVG**: Enable/disable each type
- **Invert FVG Colors**: Swap FVG color scheme

### Multi-Timeframe
- **Show Lower Timeframes**: Display OBs from timeframes lower than chart
- **Individual Timeframe Toggles**: Enable/disable 1min, 3min, 5min, 15min, 60min

### Style
- **Text Color**: Customize label text color
- **Extend Zones**: Set extension length in bars (default: 40)
- **Show [Combined] Tag**: Display combined indicator in merged zone labels

## Usage Tips

### For Day Trading
- Enable 1min, 3min, and 5min timeframes
- Use "High" zone count for more trading opportunities
- Watch for bounces from combined zones (highest probability)

### For Swing Trading
- Enable 15min, 60min, and higher timeframes
- Use "Medium" or "Low" zone count for major zones only
- Focus on combined zones with 3+ timeframes

### For Scalping
- Use current timeframe only (disable MTF)
- Enable both OB and FVG
- Set up alerts for quick bounce notifications

### Alert Setup
1. Click "Create Alert" in TradingView
2. Choose from available alert conditions:
- **Bullish Bounce (OB/FVG)**: Long entry opportunities
- **Bearish Bounce (OB/FVG)**: Short entry opportunities
- **New OB Formation**: Early zone identification
- **Strong Combined Zone**: High-probability confluence areas
3. Set alert frequency to "Once Per Bar Close" to avoid false signals

## Technical Details

### Performance Optimizations
- Maximum 100 boxes/labels for efficient rendering
- Lightweight FVG processing on current timeframe only
- Dynamic memory management with array size limits
- Selective rendering of active zones only

### Calculations
- **ATR Multiplier**: Zones exceeding 3.5x ATR are filtered out
- **Volume Percentage**: `max(bullVol, bearVol) / totalVolume × 100`
- **FVG Size Filter**: Uses 100th percentile of last 1000 gaps
- **Overlap Detection**: Uses intersection/union ratio for combining zones

## Credits & License

This indicator combines and enhances concepts from:
- "Volumized Order Blocks" methodology
- "Volumatic Fair Value Gaps" approach

**License**: Mozilla Public License 2.0 (MPL-2.0)

## Disclaimer

This indicator is provided for **educational and informational purposes only**. Trading involves substantial risk of loss and is not suitable for every investor. Past performance is not indicative of future results. Always do your own research and consult with a licensed financial advisor before making trading decisions.

## Version History

**v2 (Current)**
- Combined OB and FVG into single indicator
- Added comprehensive alert system
- Improved performance with lightweight FVG processing
- Enhanced bounce detection with touch-inside logic
- Added volume metrics to zone labels
- Implemented dynamic zone extension until broken
- Added combined zone detection with configurable thresholds

---

### Chart Examples

The indicator displays:
- **Red Zones** (Inverted): Bullish Order Blocks / Bearish FVGs
- **Blue Zones** (Inverted): Bearish Order Blocks / Bullish FVGs
- **Orange Zones** (Inverted): Bullish Fair Value Gaps
- **Aqua Zones** (Inverted): Bearish Fair Value Gaps

Each zone shows:
- Timeframe label (e.g., "5m", "15m", "1H")
- Zone type (OB or FVG)
- Total volume in millions (e.g., "12.5M")
- Dominant side percentage (e.g., "85%")

**Example Label**: `[Combined] 5m & 15m OB 45.2M (78%)`
- Combined zone from 5min and 15min timeframes
- Order Block type
- 45.2 million total volume
- 78% volume on dominant side

---

## Support & Updates

For issues, suggestions, or questions, please leave a comment on the indicator page.

**Author**: © rasukaru666

**Compatible with**: TradingView Pine Script v6

Feragatname

Bilgiler ve yayınlar, TradingView tarafından sağlanan veya onaylanan finansal, yatırım, alım satım veya diğer türden tavsiye veya öneriler anlamına gelmez ve teşkil etmez. Kullanım Koşulları bölümünde daha fazlasını okuyun.