OPEN-SOURCE SCRIPT

Engulfing Zone Finder (Box) by vinafx

779
Engulfing Zone (EG) Finder is an overlay indicator that automatically detects and draws boxes for two types of momentum-based price action patterns: Engulfing Zones and Outside Bar Zones.

[h2]🔷 Engulfing Zone (EG)[/h2]

An Engulfing Zone forms when a sequence of candles results in a breakout candle (BO) that closes beyond the high or low of an origin candle. Unlike the traditional 2-candle engulfing pattern, this indicator allows intermediate candles between the origin and the breakout candle, capturing a broader range of momentum shifts.

Bullish Engulfing Zone
  • The origin candle is a bearish candle.
  • A subsequent bullish candle closes above the high of the origin candle — this is the breakout (BO) candle.
  • A box is drawn from the origin candle to the BO candle, with the top and bottom set to the high and low of the origin candle.
  • The box is drawn with a green border by default.


Bearish Engulfing Zone
  • The origin candle is a bullish candle.
  • A subsequent bearish candle closes below the low of the origin candle — this is the breakout (BO) candle.
  • A box is drawn from the origin candle to the BO candle, with the top and bottom set to the high and low of the origin candle.
  • The box is drawn with a red border by default.


Smart filtering logic built in:
  • Origin Shift: If a new candle of the same type sweeps the wick of the current origin candle, it automatically replaces the origin. For example, if a new bearish candle has a higher high than the existing bearish origin, the new candle becomes the origin.
  • Opposite Break Invalidation: If price closes beyond the opposite side of the origin candle before a valid breakout occurs, the origin is discarded.
  • Nested Zone Filtering: If a smaller EG zone exists inside a larger one (same type), the indicator keeps the smaller zone and removes the larger one, reducing visual clutter.
  • Max Candle Duration: A configurable limit (default: 5) controls the maximum total number of candles from origin to BO (inclusive). This prevents excessively long zones.


[h2]🔶 Outside Bar Zone (OB)[/h2]

An Outside Bar Zone is a 2-candle pattern where the second candle completely engulfs the first candle's range (higher high AND lower low), and both candles share the same direction.

Bullish Outside Bar Zone
  • Two consecutive bullish candles.
  • The second candle has a higher high and a lower low than the first.
  • The second candle's close is above the high of the first candle.
  • A box is drawn covering the first candle, with a green border by default.


Bearish Outside Bar Zone
  • Two consecutive bearish candles.
  • The second candle has a higher high and a lower low than the first.
  • The second candle's close is below the low of the first candle.
  • A box is drawn covering the first candle, with a red border by default.


[h2]⚙️ Settings[/h2]

Engulfing Zone Settings (Bullish / Bearish)
  • Show/Hide: Toggle visibility for each zone type independently.
  • Border Color: Customize the box border color.
  • Background Color: Customize the box fill color and transparency.


Outside Bar Zone Settings
  • Show/Hide: Toggle visibility for Bullish and Bearish OB Zones independently.
  • Border Color / Background Color: Fully customizable for each type.


Performance & Limits
  • Max Total Candles (Origin to BO): Controls how many candles (including origin and BO) are allowed to form an EG zone. Default is 5. Set to 0 for no limit.
  • Max Pending Origin Candles: Limits the number of origin candles tracked simultaneously. Default is 100.
  • Max Total Boxes Displayed: Limits the total number of boxes drawn on the chart across all zone types. The quota is shared flexibly — if one type produces fewer boxes, the remaining capacity is available for other types. Default is 200. TradingView maximum is 500.


[h2]📝 Notes[/h2]

  • This indicator is an overlay and draws directly on the price chart.
  • It works on all timeframes and all instruments (stocks, forex, crypto, futures, etc.).
  • Doji candles (where close equals open) are included in the detection logic. A Doji is treated as both bearish and bullish, so it can serve as an origin candle, a breakout candle, or part of an Outside Bar pattern.
  • The indicator uses open-source Pine Script v5. No external data requests or repainting techniques are used.

Wyłączenie odpowiedzialności

Informacje i publikacje nie stanowią i nie powinny być traktowane jako porady finansowe, inwestycyjne, tradingowe ani jakiekolwiek inne rekomendacje dostarczane lub zatwierdzone przez TradingView. Więcej informacji znajduje się w Warunkach użytkowania.