PINE LIBRARY
Updated 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
Release Notes
v2Release Notes
v3Release Notes
v4已添加:
scanLegacyFVGState(sourceTimeframe, displacementFactor)
Parameters:
sourceTimeframe (string)
displacementFactor (float)
Release Notes
v5Pine library
In true TradingView spirit, the author has published this Pine code as an open-source library so that other Pine programmers from our community can reuse it. Cheers to the author! You may use this library privately or in other open-source publications, but reuse of this code in publications is governed by House Rules.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.
Pine library
In true TradingView spirit, the author has published this Pine code as an open-source library so that other Pine programmers from our community can reuse it. Cheers to the author! You may use this library privately or in other open-source publications, but reuse of this code in publications is governed by House Rules.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.