Indicator · Pine Script v5 · On the chart

Fractal Enculfing Caldles

by fiji-solutions· code credited to cmoutafidis

This indicator identifies bullish and bearish engulfing candlestick patterns directly on the price chart.

View on GitHub

GitHub stars1on the repository
Pine versionv5runs as is
Lines of code48
Settings6inputs
LicenceNone statedfile: MPL-2.0
Last update2 years ago3 Oct 2024

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

48 lines of Pine Script v5 from 05. Candlestick Patterns/10. Candlestick Pattern Filters.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

10. Candlestick Pattern Filters.pine
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © cmoutafidis

//@version=5
indicator(title="Fractal enculfing Caldles", overlay = true)

// Constants
var ATR_GROUP = "ATR Filter"
var EMA_GROUP = "EMA Filter"
var HIGH_LOW_GROUP = "High/Low Filter"  

// Get user input
maxAtrSize = input.float(title = "Max Candle Size", defval = 1.0, tooltip = "The script devides the candle size by ATR and compares it to this", group = ATR_GROUP)
useAtrFilter = input.bool(title = "Use ATR Filter?", defval = false, tooltip = "Turns on/off the ATR filter", group = ATR_GROUP)

emaLength = input.int(title = "EMA Length", defval = 50, tooltip = "Length of the EMA Filter", group = EMA_GROUP)
useEmaFilter = input.bool(title = "Use EMA Filter?", defval = false, tooltip = "Turns on/off the EMA filter", group = EMA_GROUP)

lookback = input.int(title = "Swing High/Low lookback", defval = 10, tooltip = "How many bars to look back for swing high/low", group = HIGH_LOW_GROUP)
useHighLowFilter = input.bool(title = "Use Swing High/Low Filter?", defval = false, tooltip = "Turns on/off the swing high/low filter", group = HIGH_LOW_GROUP)

// Get ATR Filter
atr = ta.atr(14)
candleSize = high - low
atrFilter = not useAtrFilter or candleSize / atr < maxAtrSize

// Gets swing high/low filter
swingHighFilter = not useHighLowFilter or (high == ta.highest(high, lookback) or high[1] == ta.highest(high, lookback))
swingLowFilter  = not useHighLowFilter or (low == ta.lowest(low, lookback) or low[1] == ta.lowest(low, lookback))

// Get EMA Filter
ema = ta.ema(close, emaLength)
emaFilterLong = not useEmaFilter or close > ema
emaFilterShort = not useEmaFilter or close < ema

// Detect candlestick pattern
bullEc = close[1] < open[1] and open <= close[1] and close >= open[1] and swingLowFilter and atrFilter and emaFilterLong
bearEc = close[1] > open[1] and open >= close[1] and close <= open[1] and swingHighFilter and atrFilter and emaFilterShort


// Draw signals and data
plotshape(bullEc, style = shape.triangleup, location = location.belowbar, color = color.green, size = size.small)
plotshape(bearEc, style = shape.triangledown, location = location.abovebar, color = color.red, size = size.small)
plot(useEmaFilter ? ema : na, color = emaFilterLong ? color.green : color.red, title = "EMA")

// Generate alerts
alertcondition(condition = bullEc, title = "Bullish EC ", message = "Bullish engulfing candle detected on {{ticket}}")
alertcondition(condition = bearEc, title = "Bearish EC ", message = "Bearish engulfing candle detected on {{ticket}}")

Overview

To refine signal quality, it provides three optional filters: an ATR filter to cap maximum candle size relative to volatility, a swing high or low filter over a configurable lookback window, and an EMA filter to ensure trades align with the trend direction. Detected bullish and bearish signals are drawn with green upward or red downward triangles on the chart, along with an optional EMA line.

Details

Published by

fiji-solutions on GitHub

Code credit

cmoutafidis, as written in the script's header

Type

Indicator, Pine Script v5

Draws

On the price chart

Category

Candlestick patterns, Moving averages, Volatility & bands, Trend

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Max Candle Sizefloat1.0maxAtrSize
Use ATR Filter?boolfalseuseAtrFilter
EMA Lengthint50emaLength
Use EMA Filter?boolfalseuseEmaFilter
Swing High/Low lookbackint10lookback
Use Swing High/Low Filter?boolfalseuseHighLowFilter
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

15 stars

This indicator plots Bollinger Bands and smoothed HAMA candles on the price chart. It builds each candle from separate moving averages of open, high, low and close, using selectable EMA, SMA or WMA lengths. A simple moving average forms the band basis, and an

Indicator v5 Candlestick patternsMoving averages
Updated 4 months ago · Apache-2.0 GitHub repository of NSDT HAMA Candles with Bollinger Bands

Calculates adaptive arithmetic candles by blending price data with Kaufman Efficiency Ratio smoothing and a linear regression anchor. It measures trend health using a zero-to-hundred Quality Score derived from market efficiency, regression slope, and normalize

Indicator v6 TrendCandlestick patterns
Updated yesterday · MIT GitHub repository of Adaptive Arithmetic Candles + Quality Score [WavesUnchained]
318 stars

This indicator plots four customizable moving averages directly on the main price chart using default lengths of 3, 8, 21, and 50 periods. It fills the space between adjacent averages in green or maroon depending on trend alignment. Additionally, it computes B

Indicator v5 Moving averagesTrend
Updated 2 months ago · MIT GitHub repository of Multiple Moving Averages

NVDA Trend Ribbon

by longsurf-ai
277 stars

This indicator plots three exponential moving averages and ATR volatility envelopes on the price chart. It compares the fast and slow EMAs to shade a trend ribbon and marks confirmed upward and downward crossovers with triangle labels. Settings change the thre

Indicator v6 TrendMoving averages
Updated yesterday · MIT GitHub repository of NVDA Trend Ribbon

Bollinger Bands Force

by harryguiacorn
219 stars

This indicator modifies standard Bollinger Bands to measure directional trend force based on line alignment. It calculates a simple moving average basis along with upper and lower volatility bands. When all three lines move upward or downward simultaneously, i

Indicator v5 Volatility & bandsTrend
Updated 1 year ago · None stated GitHub repository of Bollinger Bands Force

More indicators

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers