PINE LIBRARY
Cập nhật MaidongFVGLibrary

## Title
`Maidong FVG Library`
## Short Description
Reusable Pine library for detecting and optionally rendering multi-timeframe imbalance zones with midpoint mitigation and pressure overlays.
## Full Description
This library provides a compact API for working with multi-timeframe imbalance zones inside other TradingView indicators.
Core capabilities:
- Detects bullish and bearish imbalance zones from a selectable source timeframe
- Applies a displacement filter using the relationship between candle body size and a smoothed body baseline
- Uses confirmed source-timeframe data for stable MTF evaluation
- Optionally draws active zones directly from the library
- Supports midpoint or full-fill mitigation logic
- Can render midpoint guides and directional pressure slices inside each active zone
- Returns the latest active bullish and bearish zone levels for downstream logic
The library is intended for indicator authors who want reusable imbalance-zone logic without embedding a full standalone chart tool in every script.
## Exported Function
### `scanImbalanceZones(...)`
```pine
import username/MaidongFVGLibrary/1 as iz
[newBullish, bullishStartTime, bullishUpper, bullishLower, bullishMidpoint,
newBearish, bearishStartTime, bearishUpper, bearishLower, bearishMidpoint,
bullishActiveCount, bearishActiveCount] =
iz.scanImbalanceZones(
sourceTimeframe,
displacementFactor,
mitigateAtMidpoint,
projectionBars,
drawBullish,
drawBearish,
drawMidpoint,
drawPressure,
bullishPressureColor,
bearishPressureColor,
zoneColor)
```
## Parameters
- `sourceTimeframe`: Timeframe used to evaluate imbalance conditions. Use `""` to use the chart timeframe.
- `displacementFactor`: Minimum body-strength multiplier relative to the smoothed body baseline.
- `mitigateAtMidpoint`: When `true`, a zone is cleared after price reaches its midpoint. When `false`, full fill is required.
- `projectionBars`: Number of chart bars used to project the rendered zone forward in time.
- `drawBullish`: Draw bullish zones.
- `drawBearish`: Draw bearish zones.
- `drawMidpoint`: Draw a dashed midpoint line inside each rendered zone.
- `drawPressure`: Draw directional pressure slices inside each rendered zone.
- `bullishPressureColor`: Color used for the upper demand slice.
- `bearishPressureColor`: Color used for the lower supply slice.
- `zoneColor`: Base fill and border color for the full zone.
## Return Values
The function returns 12 values:
1. `newBullish`
2. `bullishStartTime`
3. `bullishUpper`
4. `bullishLower`
5. `bullishMidpoint`
6. `newBearish`
7. `bearishStartTime`
8. `bearishUpper`
9. `bearishLower`
10. `bearishMidpoint`
11. `bullishActiveCount`
12. `bearishActiveCount`
These values let the caller build alerts, filters, dashboards, or custom drawings without reimplementing the zone engine.
## Detection Model
Bullish zone:
- current low is above the high from two source bars back
- current close remains above that earlier high
- body size is at least `displacementFactor` times the smoothed body baseline
- evaluation uses confirmed source-timeframe bars
Bearish zone:
- current high is below the low from two source bars back
- current close remains below that earlier low
- body size is at least `displacementFactor` times the smoothed body baseline
- evaluation uses confirmed source-timeframe bars
## Publishing Notes
- Publish as a `Library`
- Add enough `max_boxes_count` and `max_lines_count` in consuming scripts
- If your published script uses the drawing options, mention that the library manages visual objects internally
## Suggested Release Notes
`v1`
- Initial public release
- Added reusable multi-timeframe imbalance-zone scanning
- Added optional midpoint and pressure rendering
- Added active-zone return values for downstream indicators
`Maidong FVG Library`
## Short Description
Reusable Pine library for detecting and optionally rendering multi-timeframe imbalance zones with midpoint mitigation and pressure overlays.
## Full Description
This library provides a compact API for working with multi-timeframe imbalance zones inside other TradingView indicators.
Core capabilities:
- Detects bullish and bearish imbalance zones from a selectable source timeframe
- Applies a displacement filter using the relationship between candle body size and a smoothed body baseline
- Uses confirmed source-timeframe data for stable MTF evaluation
- Optionally draws active zones directly from the library
- Supports midpoint or full-fill mitigation logic
- Can render midpoint guides and directional pressure slices inside each active zone
- Returns the latest active bullish and bearish zone levels for downstream logic
The library is intended for indicator authors who want reusable imbalance-zone logic without embedding a full standalone chart tool in every script.
## Exported Function
### `scanImbalanceZones(...)`
```pine
import username/MaidongFVGLibrary/1 as iz
[newBullish, bullishStartTime, bullishUpper, bullishLower, bullishMidpoint,
newBearish, bearishStartTime, bearishUpper, bearishLower, bearishMidpoint,
bullishActiveCount, bearishActiveCount] =
iz.scanImbalanceZones(
sourceTimeframe,
displacementFactor,
mitigateAtMidpoint,
projectionBars,
drawBullish,
drawBearish,
drawMidpoint,
drawPressure,
bullishPressureColor,
bearishPressureColor,
zoneColor)
```
## Parameters
- `sourceTimeframe`: Timeframe used to evaluate imbalance conditions. Use `""` to use the chart timeframe.
- `displacementFactor`: Minimum body-strength multiplier relative to the smoothed body baseline.
- `mitigateAtMidpoint`: When `true`, a zone is cleared after price reaches its midpoint. When `false`, full fill is required.
- `projectionBars`: Number of chart bars used to project the rendered zone forward in time.
- `drawBullish`: Draw bullish zones.
- `drawBearish`: Draw bearish zones.
- `drawMidpoint`: Draw a dashed midpoint line inside each rendered zone.
- `drawPressure`: Draw directional pressure slices inside each rendered zone.
- `bullishPressureColor`: Color used for the upper demand slice.
- `bearishPressureColor`: Color used for the lower supply slice.
- `zoneColor`: Base fill and border color for the full zone.
## Return Values
The function returns 12 values:
1. `newBullish`
2. `bullishStartTime`
3. `bullishUpper`
4. `bullishLower`
5. `bullishMidpoint`
6. `newBearish`
7. `bearishStartTime`
8. `bearishUpper`
9. `bearishLower`
10. `bearishMidpoint`
11. `bullishActiveCount`
12. `bearishActiveCount`
These values let the caller build alerts, filters, dashboards, or custom drawings without reimplementing the zone engine.
## Detection Model
Bullish zone:
- current low is above the high from two source bars back
- current close remains above that earlier high
- body size is at least `displacementFactor` times the smoothed body baseline
- evaluation uses confirmed source-timeframe bars
Bearish zone:
- current high is below the low from two source bars back
- current close remains below that earlier low
- body size is at least `displacementFactor` times the smoothed body baseline
- evaluation uses confirmed source-timeframe bars
## Publishing Notes
- Publish as a `Library`
- Add enough `max_boxes_count` and `max_lines_count` in consuming scripts
- If your published script uses the drawing options, mention that the library manages visual objects internally
## Suggested Release Notes
`v1`
- Initial public release
- Added reusable multi-timeframe imbalance-zone scanning
- Added optional midpoint and pressure rendering
- Added active-zone return values for downstream indicators
Phát hành các Ghi chú
v2Phát hành các Ghi chú
v3Phát hành các Ghi chú
v4已添加:
scanLegacyFVGState(sourceTimeframe, displacementFactor)
Parameters:
sourceTimeframe (string)
displacementFactor (float)
Phát hành các Ghi chú
v5Thư viện Pine
Theo đúng tinh thần TradingView, tác giả đã công bố mã Pine này như một thư viện mã nguồn mở để các lập trình viên Pine khác trong cộng đồng có thể tái sử dụng. Chúc mừng tác giả! Bạn có thể sử dụng thư viện này cho mục đích cá nhân hoặc trong các ấn phẩm mã nguồn mở khác, nhưng việc tái sử dụng mã này trong các ấn phẩm phải tuân theo Nội Quy.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.
Thư viện Pine
Theo đúng tinh thần TradingView, tác giả đã công bố mã Pine này như một thư viện mã nguồn mở để các lập trình viên Pine khác trong cộng đồng có thể tái sử dụng. Chúc mừng tác giả! Bạn có thể sử dụng thư viện này cho mục đích cá nhân hoặc trong các ấn phẩm mã nguồn mở khác, nhưng việc tái sử dụng mã này trong các ấn phẩm phải tuân theo Nội Quy.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.