Strategy · Pine Script v6 · On the chart

Candlestick Patterns

by pineforge-4pass· code credited to PineForge contributors 2026

This strategy detects bullish and bearish engulfing candles, hammers, shooting stars, and morning stars from current and prior bar bodies.

View on GitHub

Repaints

GitHub stars1on the repository
Pine versionv6current
Lines of code60
Settings1inputs
LicenceApache-2.0
Last update5 days ago23 Oct 2026

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 strategy, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart. The trades and results appear in the Strategy Tester tab; adjust the settings with the gear icon.

Source Code

60 lines of Pine Script v6 from validation/ta-engulfing-candle-pattern-01/strategy.pine, published under Apache-2.0. Keep the author's credit and licence lines when you reuse it.

strategy.pine
// This Pine Script® code is licensed under Apache-2.0
// SPDX-License-Identifier: Apache-2.0
// © PineForge contributors 2026
//
// PF probe 22 — bullish/bearish engulfing candle-pattern detection
// Purpose: parity test for inter-bar pattern recognition using `close[1]` /
// `open[1]` history references and `math.abs/min/max` on body & wick sizes,
// gated by a trend-MA filter.
//
//@version=6
strategy("Candlestick Patterns", overlay=true, initial_capital=1000000, process_orders_on_close=false, pyramiding=1, commission_type=strategy.commission.percent, commission_value=0, slippage=0, default_qty_type=strategy.fixed, default_qty_value=1)

// === Inputs ===
trendLen = input.int(20, "Trend MA Length", minval=5)

// === Trend filter ===
trendMA = ta.sma(close, trendLen)
upTrend = close > trendMA
dnTrend = close < trendMA

// === Candle body and wick calculations ===
bodySize  = math.abs(close - open)
upperWick = high - math.max(open, close)
lowerWick = math.min(open, close) - low
totalRange = high - low

// === Pattern: Bullish Engulfing ===
bullEngulf = close > open and close[1] < open[1] and close > open[1] and open < close[1]

// === Pattern: Bearish Engulfing ===
bearEngulf = close < open and close[1] > open[1] and close < open[1] and open > close[1]

// === Pattern: Hammer (bullish) ===
hammer = lowerWick > bodySize * 2 and upperWick < bodySize * 0.5 and bodySize > 0

// === Pattern: Shooting Star (bearish) ===
shootStar = upperWick > bodySize * 2 and lowerWick < bodySize * 0.5 and bodySize > 0

// === Pattern: Doji ===
doji = bodySize < totalRange * 0.1 and totalRange > 0

// === Pattern: Morning Star (3-bar bullish reversal) ===
morningStar = close[2] < open[2] and bodySize[1] < bodySize[2] * 0.3 and close > open and close > (open[2] + close[2]) / 2

// === Entry Signals ===
bullSignal = (bullEngulf or hammer or morningStar) and dnTrend
bearSignal = (bearEngulf or shootStar) and upTrend

if bullSignal
    strategy.entry("Long", strategy.long)
if bearSignal
    strategy.entry("Short", strategy.short)

// === Exit ===
if strategy.position_size > 0 and bearSignal
    strategy.close("Long")
if strategy.position_size < 0 and bullSignal
    strategy.close("Short")

plot(trendMA, "Trend MA", color=color.gray)

Overview

Candlestick Patterns enters long when a bullish pattern occurs while price is below a simple moving average, and short when a bearish pattern occurs while price is above that average. A doji condition is calculated but does not trigger trades. Opposite signals close the open position. There is no stop loss or take profit. The trend moving-average length is the only input. The average is plotted on the price chart. Signals use the forming bar and can change before it closes.

Details

Published by

pineforge-4pass on GitHub

Code credit

PineForge contributors 2026, as written in the script's header

Type

Strategy, Pine Script v6

Draws

On the price chart

Category

Candlestick patterns, Trend, Moving averages, Mean reversion

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

  • Signals can change on the live bar or after it closes (repainting)
  • The strategy enters trades without a stop loss

Topics

algorithmic-tradingbacktestingparitypine-scriptpinescriptquantitative-financetest-corpustradingview

Settings

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

SettingTypeDefaultVariable
Trend MA Lengthint20trendLen
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

This mean-reversion strategy plots Bollinger Bands and a long-term moving average directly on the price chart. It enters trades when price candles penetrate the outer Bollinger Bands beyond a user-defined body percentage, anticipating a price reversal. Entries

Strategy v5 Mean reversionVolatility & bands
Updated 2 months ago · None stated GitHub repository of Bollinger Bands Winner PRO [Alorse]
285 stars

Mean Reversion Strategy is an overlay strategy that identifies pullbacks using a long-term EMA, RSI, and candlestick patterns. It generates long signals when a bullish engulfing candle forms below the EMA while RSI is oversold, and short signals when a bearish

Strategy v4 Mean reversionCandlestick patterns
Updated 3 years ago · None stated GitHub repository of Mean Reversion Strategy
257 stars

This overlay strategy marks short-term turning points on the price chart and enters SPY option-style trades from them. It plots simple moving averages of highs and lows, draws up and down reversal arrows, and colors bars when a short-term extreme coincides wit

Strategy v5 TrendMoving averages Repaints
Updated 6 weeks ago · None stated GitHub repository of SPY Options Trading - Alert

8 Day Run

by hasnocool
106 stars

Inspired by Linda Raschke's strategy for T-note futures, this script identifies extended trends where price remains on one side of a 5-period SMA for more than eight consecutive bars. It enters long on the first pullback below the SMA following an eight-bar bu

Strategy v4 TrendMoving averages
Updated 2 years ago · GPL-3.0 GitHub repository of 8 Day Run

Bollinger Bands Strategy

by cklose2000
105 stars

This strategy generates buy and sell signals based on Bollinger Band crossovers combined with a simple moving average trend filter. It enters a long position when price crosses above the lower band while trading above the SMA filter line, and enters a short po

Strategy v5 Volatility & bandsMoving averages
Updated 1 year ago · None stated GitHub repository of Bollinger Bands Strategy
53 stars

This strategy identifies long entry opportunities based on short-term price pullbacks below a major trend filter. It enters long when three consecutive lower closes occur below the 200-period simple moving average, followed by the current bar closing back abov

Strategy v6 TrendMoving averages
Updated 2 months ago · MPL-2.0 GitHub repository of Ivan Scherman Pattern - TP/SL

More strategys

Trade Your Charts With a Regulated Broker

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

Compare brokers