Indicator · Pine Script v5 · On the chart

Harami Bullish/Bearish Pattern (Candlestick Pattern)

by augustoerni

This indicator marks bullish and bearish harami candlestick patterns on the price chart.

View on GitHub

GitHub stars3on the repository
Pine versionv5runs as is
Lines of code39
Settings6inputs
LicenceNone statedfile: MPL-2.0
Last update2 years ago9 Aug 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

39 lines of Pine Script v5 from candlesticks/harami.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

harami.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © AugustoErni

//@version=5
indicator("Harami Bullish/Bearish Pattern (Candlestick Pattern)", overlay=true)

import AugustoErni/uptrend_downtrend_loopback_candle_identification_lib/3 as upAndDownTrendsCandleIdentification

showBullishHarami = input.bool(title="Show Bullish Harami", defval=true)
showBearishHarami = input.bool(title="Show Bearish Harami", defval=true)
lookbackPeriod = input.int(defval=5, title="Lookback Period", minval=1, step=1, tooltip="Loopback period to identify uptrend/downtrend analysis from candles.")
bodyThreshold = input.float(0.4, title="Body Threshold (percentage of candle range (0.4 = 40%))", step=0.01, tooltip="To identify long candle body.")
dojiThreshold = input.float(0.1, title="Doji Threshold (0.1 = 10%)", step=0.01, tooltip="To identify doji candle.")
weakCandleThreshold = input.float(0.2, title="Weak Candle Threshold (0.2 = 20%)", step=0.01, tooltip="To identify possible weak and/or small candle.")

isBullishCandle = close > open
isBearishCandle = open > close

isLongCandle = math.abs(open - close) >= (high - low) * bodyThreshold
isDoji = math.abs(close - open) <= (high - low) * dojiThreshold
isWeakCandle = math.abs(close - open) <= (high - low) * weakCandleThreshold

isLookbackUptrendCandle = upAndDownTrendsCandleIdentification.uptrendLoopbackCandleIdentification(lookbackPeriod)
isLookbackDowntrendCandle = upAndDownTrendsCandleIdentification.downtrendLoopbackCandleIdentification(lookbackPeriod)

isFirstCandleCondition = isLongCandle
isCurrentCandleCondition = isDoji or isWeakCandle

isBullishHarami = isFirstCandleCondition[1] and isCurrentCandleCondition and isLookbackDowntrendCandle
isBearishHarami = isFirstCandleCondition[1] and isCurrentCandleCondition and isLookbackUptrendCandle

barcolor(isBullishHarami and isBullishCandle ? color.white : isBullishHarami and isBearishCandle ? color.black : na)
barcolor(isBullishHarami and isBullishCandle[1] ? color.rgb(213, 213, 213) : isBullishHarami and isBearishCandle[1] ? color.rgb(90, 90, 90) : na, offset=-1)

barcolor(isBearishHarami and isBullishCandle ? color.white : isBearishHarami and isBearishCandle ? color.black : na)
barcolor(isBearishHarami and isBullishCandle[1] ? color.rgb(213, 213, 213) : isBearishHarami and isBearishCandle[1] ? color.rgb(90, 90, 90) : na, offset=-1)

plotshape(isBullishHarami and showBullishHarami, title="Bullish Harami", style=shape.arrowup, location=location.belowbar, color=color.rgb(255, 255, 255), text="Bullish Harami", textcolor=color.green)
plotshape(isBearishHarami and showBearishHarami, title="Bearish Harami", style=shape.arrowdown, location=location.abovebar, color=color.rgb(0, 0, 0), text="Bearish Harami", textcolor=color.red)

Overview

The prior candle must have a long body, and the current candle must be a doji or a weak, small candle. A bullish signal also requires a lookback downtrend, while a bearish signal requires a lookback uptrend, both from an imported library. It recolors the two candles and plots labeled arrows above or below the signal bar. Toggles and thresholds control which patterns appear, the lookback length, and body, doji, and weak-candle size. It does not place trades or set exits.

Details

Published by

augustoerni on GitHub

Type

Indicator, Pine Script v5

Draws

On the price chart

Category

Candlestick patterns, 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
Show Bullish HaramibooltrueshowBullishHarami
Show Bearish HaramibooltrueshowBearishHarami
Lookback Periodint5lookbackPeriod
Body Threshold (percentage of candle range (0.4 = 40%))float0.4bodyThreshold
Doji Threshold (0.1 = 10%)float0.1dojiThreshold
Weak Candle Threshold (0.2 = 20%)float0.2weakCandleThreshold
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

All Candlestick Patterns

by shunjizhan
292 stars

All Candlestick Patterns detects and highlights a wide range of bullish, bearish, and neutral candlestick patterns directly on the price chart. It features optional trend filtering using either a 50-period simple moving average or a combination of 50-period an

Indicator v4 Candlestick patternsTrend
Updated 3 years ago · None stated GitHub repository of All Candlestick Patterns
257 stars

This indicator detects a large set of classic candlestick patterns and plots colored labels on the price chart. Trend context uses a 50-period simple moving average, or the 50 and 200 averages stacked together, and can be switched off. Users filter bullish, be

Indicator v4 Candlestick patternsTrend
Updated 6 weeks ago · None stated GitHub repository of Snag - All Candlestick Patterns

Five-in-one Strategy

by capissimo
114 stars

Five-in-one Strategy combines five analytical tools into a single price chart overlay: the Dual Thrust Trading Algorithm (DTTA), Semafore, HalfTrend, Nick Rypock Trailing Reverse, and Tweezer or Kangaroo Tail candlestick patterns. It generates trade signals us

Indicator v4 TrendBreakout Repaints
Updated 1 year ago · None stated GitHub repository of Five-in-one Strategy

HA: Heikin-Ashi

by mihakralj
99 stars

This indicator calculates and plots Heikin-Ashi smoothed candlesticks directly on the price chart. It derives the smoothed close from standard price averages and recursively computes the open, high, and low values. The script does not issue trade signals or al

Indicator v6 Candlestick patternsTrend
Updated 4 weeks ago · Apache-2.0 GitHub repository of HA: Heikin-Ashi
55 stars

This indicator overlays on the price chart and provides trend and momentum analysis. It calculates and plots three exponential moving averages with fixed periods of 20, 50, and 200 using yellow, orange, and blue colors respectively. The script also computes th

Indicator v6 TrendOscillators & momentum
Updated 6 months ago · Apache-2.0 GitHub repository of Trend & Momentum Analysis

Confluence Suite

by TamaraKGreen
46 stars

The Confluence Suite indicator draws multiple trading signals and tools directly on the price chart. It generates entry and exit signals based on selected modes and filters, with an AI signal classifier rating quality from 1-4. Additional features include smar

Indicator v5 TrendSMC / ICT / price action
Updated 7 weeks ago · None stated GitHub repository of Confluence Suite

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