The Engulfing Box indicator is a custom script designed to visually highlight and track bullish and bearish engulfing candlestick patterns on a price chart. These patterns are often used to identify potential reversal points, making them valuable for technical analysis. The script dynamically draws colored boxes around these patterns, helping users easily spot them in the price action.
Key Features:
Bullish Engulfing Pattern: When a candlestick fully engulfs the previous bearish candle (i.e., the close of the current candle is higher than the open of the previous candle, and the open is lower than the close of the previous candle), the script draws a green box around the bullish engulfing candle. This box is drawn from the open of the previous candle to the low of the previous candle.
Bearish Engulfing Pattern: When a candlestick fully engulfs the previous bullish candle (i.e., the close of the current candle is lower than the open of the previous candle, and the open is higher than the close of the previous candle), a red box is drawn around the bearish engulfing candle. This box is drawn from the open of the previous candle to the high of the previous candle.
Dynamic Box Management: Once an engulfing pattern is detected, a box is drawn with the following attributes:
Bullish Engulfing Box: Green, with a transparent background.
Bearish Engulfing Box: Red, with a transparent background.
The box will adjust its color to gray if the price moves past certain thresholds, indicating that the engulfing pattern may no longer be as relevant.
Max Pattern Tracking: The script limits the number of engulfing boxes tracked on the chart to prevent clutter. The maximum number of bullish and bearish engulfing patterns shown is customizable (set to 500 by default), and once this limit is exceeded, older boxes are deleted to maintain a clean chart.
Pattern Expiry: Boxes are deleted if price action moves beyond the pattern’s range, ensuring that outdated signals are removed. If the low price falls below the bottom of the bullish engulfing box, or the high price rises above the top of the bearish engulfing box, the respective box is removed. Additionally, if the low price moves below the top of the bullish box or the high price exceeds the bottom of the bearish box, the box's color is changed to a more neutral tone.
How it Works:
Pattern Detection: The script compares the current price data with the previous candlestick to detect the bullish or bearish engulfing patterns.
Box Creation: If a pattern is detected, a colored box is drawn around the candle to visually highlight the pattern.
Pattern Expiry and Cleanup: The script continuously monitors past boxes. If the price moves too far from the box’s range, the box is either deleted or altered to reflect the reduced significance of the pattern.
Box Count Limit: To avoid clutter, the script ensures that no more than 500 bullish or bearish engulfing boxes are shown at any time.
Customization:
The number of previous bars to scan for engulfing patterns can be adjusted (maxBarsback).
The maximum number of patterns displayed at any time can be modified.