Bullish Engulfing: Identified when a candle closes higher than it opens, and it completely engulfs the previous candle (previous close is lower than the current open, and previous high is lower than the current close).
Bearish Engulfing: Identified when a candle closes lower than it opens, and it completely engulfs the previous candle (previous close is higher than the current open, and previous low is higher than the current close).
Bar Coloring: These patterns are highlighted with a customizable color (light gray by default) to make them easily identifiable.
The Average True Range (ATR) is used to measure market volatility, and this script checks if the current candle’s range (difference between high and low) exceeds a defined multiple of the ATR, indicating a possible imbalance.
Imbalance Detection: If the current candle’s range is greater than ATR * imbalance multiplier (default multiplier: 1.5), it is marked as an ATR imbalance.
Bar Coloring: Candles with a significant imbalance (greater range than the ATR-based threshold) are highlighted in yellow, indicating an outlier or extreme price movement.
When both a Bullish Engulfing pattern and an ATR Imbalance are detected, a green triangle up is plotted below the bar, signaling a potential bullish reversal.
Conversely, when both a Bearish Engulfing pattern and an ATR Imbalance occur, a red triangle down is plotted above the bar, signaling a potential bearish reversal.
Engulfing Plot: Enable or disable the plotting of Engulfing Candles.
ATR Length: Set the period used to calculate the ATR (default is 5).
Imbalance Multiplier: Adjust the multiplier to define the threshold for ATR imbalance detection (default is 1.5).
Bar Colors: Customizable color for both Engulfing candles and Imbalance candles.
Engulfing & Imbalance Plot: Enable or disable plotting of the combined conditions (Engulfing + ATR Imbalance) with arrows.
I added an input option where the user can choose between two types of engulfing candles: Standard or Sweep.
input.string('Standard', 'Engulfing Type', options=['Standard', 'Sweep']) allows the user to select either "Standard" or "Sweep."
Standard Engulfing Conditions:
A bullish engulfing happens when the current candle closes higher than it opens, and the previous candle is fully engulfed by the current one.
A bearish engulfing happens when the current candle closes lower than it opens, and the previous candle is fully engulfed by the current one.
The Sweep engulfing condition includes the standard conditions plus additional checks:
For bullish engulfing (Sweep), the current candle's low must be lower than the previous candle's low.
For bearish engulfing (Sweep), the current candle's high must be higher than the previous candle's high.
Depending on the user's choice (Standard or Sweep), the script dynamically selects the appropriate conditions for bullish and bearish engulfing.
If the user selects Standard, the script uses the basic engulfing conditions.
If the user selects Sweep, the script adds the additional low/high sweep conditions.
The script colors the engulfing candles white (color_white) when they match the selected conditions (based on the user's choice).
It also checks for imbalance conditions (large price moves relative to ATR) and colors those candles yellow (color_yellow).
The script plots shapes (arrows) when both engulfing and imbalance conditions are met:
Green arrow for bullish engulfing with imbalance.
Red arrow for bearish engulfing with imbalance.
An alert is triggered if an engulfing candle (bullish or bearish) occurs along with an imbalance condition (price move is larger than ATR times a multiplier).
This allows users to be notified when both conditions happen at the same time.
This code lets the user choose between two types of engulfing candles: Standard and Sweep. The Sweep type adds an extra condition that compares the current candle’s low or high to the previous candle’s low or high.
The script then colors and visualizes these candles accordingly, plots arrows for both engulfing and imbalance conditions, and provides an alert when both occur together.