JustUncleL

Price Action Doji Harami v0.2 by JustUncleL

This is an updated and final version of this indicator. This version distinguishes between the true Harami and the other Doji candlestick patterns as used with the Heikin Ashi candle charts. These candle patterns indicate a potential trend reversal or pullback.
The patterns identified are:
- Bearish Harami (Red Highlight above Bar):
One to three (default 3) large body Bull (green) candles followed by a small (red)
or no body candle (less than 0.5pip) with wicks top and bottom that are at least 60% of candle.
- Bullish Harami (Green Highlight below Bar):
One to three (default 3) large body Bear (red) candles followed by a small (green)
or no body candle (less than 0.5pip) with wicks top and bottom that are at least 60% of candle.
- Bearish Doji (Fuchsia Highlight above Bar):
One to three (default 3) large body Bull (green) candles followed by a small (green)
with wicks top and bottom that are at least 60% of candle.
- Bullish Doji (Aqua Highlight below Bar):
One to three (default 3) large body Bear (red) candles followed by a small (red)
with wicks top and bottom that are at least 60% of candle.

You can optionally specify how large the candles prior to Harami/Doji are in pips, default is 0 pip.
If you set this to zero then it will have no candle size consideration. You can also specify how many look back candles (1-3) are used in Harami/Doji calculations (default 3).

Included option to perform Calculations purely on Heikin Ashi candles, this helps when you want to see the HA Doji/Harami bars with the normal candle stick chart.

Also can optionally set an alert condition for when Harami/Doji found, this also displays a circle on the bottom of the screen when alert is triggered.

JustUncleL
Open-source script

In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in a publication is governed by House Rules. You can favorite it to use it on a chart.

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.

Want to use this script on a chart?
//@version=2
//
// Name: Price Action Doji Harami v0.2 by JustUncleL
// By: JustUncleL
// Date: 4-Sep-2016
// Version: v0.2
//
// Description:
//   Identifies the Harami + Doji candlestick patterns as used with the
//   Heikin Ashi candles. These candles indicates a potential trend reversal.
//   The patterns identified are:
//   - Bearish Harami (Red Highlight above Bar): 
//       Three(3) large body Bull (green) candles followed by a small (red) 
//       or no body candle with wicks top and bottom that are at least 60% of candle.
//   - Bullish Harami (Green Highlight below Bar): 
//       Three(3) large body Bear (red) candles followed by a small (green) 
//       or no body candle with wicks top and bottom that are at least 60% of candle.
//   - Bearish Doji (Fuchsia Highlight above Bar): 
//       Three(3) large body Bull (green) candles followed by a small (green) 
//       with wicks top and bottom that are at least 60% of candle.
//   - Bullish Doji (Aqua Highlight below Bar): 
//       Three(3) large body Bear (red) candles followed by a small (red)
//       with wicks top and bottom that are at least 60% of candle.
//
//   You can optionally specify large candle in pips previous to Doji, default is 1 pip.
//   If you set this to zero then it will have no candle size consideration.
//   Included option to perform Calculations purely on Heikin Ashi candles, this helps
//   when you want to still see the HA Doji/Harami with the normal candle chart.
//
// references:
//  - Price Action Candles v0.3 by JustUncleL
//  
// modifications:
//  0.2 Modified Doji caculations to seperate true Harami patterns. 
//      Included option to show/alert all Doji's patterns.
//      Included option to Calculate Doji/Harami patterns only on Heikin Ashi candles.
//      Included option to specify how many candles (1 to 3) to look back to test Doji/Harami pattern.
//  0.1 Original Beta version.
//
study(title = "Price Action Doji Harami v0.2 by JustUncleL", shorttitle="PACDOJI v0.2 by JustUncleL", overlay = true, max_bars_back=3000)
//

pctDw = input(60,minval=0,maxval=90,title="Doji, Min % of Range of Candle for Wicks")
pipMin= input(0,minval=0,title="Doji, Previous Candle Min Pip Body Size")
sname=input(true,title="Show Price Action Bar Names")
cbar = input(false,title="Highlight Harami & Doji Bars")
sHm    = input(false,title="Show Only Harami Style Doji's")
setalm = input(true, title="Generate Alert for Harami & Doji Bars")
uha   =input(true, title="Use Heikin Ashi Candles for Calculations")
bars = input(3,minval=1,maxval=3,step=1,type=integer, title="Doji, Number of Lookback Bars")
//
// Use only Heikinashi Candles for all calculations
srcclose = uha ? security(heikinashi(tickerid), period, close) : close
srcopen = uha ? security(heikinashi(tickerid), period, open) : open
srchigh = uha ? security(heikinashi(tickerid), period, high) : high
srclow = uha ?security(heikinashi(tickerid), period, low) : low

//
pip = syminfo.mintick
range = srchigh - srclow


// Calculate Doji/Harami Candles
pctCDw = (pctDw/2) * 0.01
pctCDb = (100-pctDw) * 0.01

//Lookback Candles for bulls or bears
lbBull = bars==1? srcopen[1]>srcclose[1]: bars==2? (srcopen[1]>srcclose[1] and srcopen[2]>srcclose[2]): bars==3?(srcopen[1]>srcclose[1] and srcopen[2]>srcclose[2] and srcopen[3]>srcclose[3]):false
lbBear = bars==1? srcopen[1]<srcclose[1]: bars==2? (srcopen[1]<srcclose[1] and srcopen[2]<srcclose[2]): bars==3?(srcopen[1]<srcclose[1] and srcopen[2]<srcclose[2] and srcopen[3]<srcclose[3]):false

//Lookback Candle Size only if mininum size is > 0
lbSize = pipMin==0? true : bars==1 ? (abs(srcopen[1]-srcclose[1])>pipMin*pip) :
  bars==2 ? (abs(srcopen[1]-srcclose[1])>pipMin*pip and abs(srcopen[2]-srcclose[2])>pipMin*pip) :
  bars==3 ? (abs(srcopen[1]-srcclose[1])>pipMin*pip and abs(srcopen[2]-srcclose[2])>pipMin*pip and abs(srcopen[3]-srcclose[3])>pipMin*pip) :
  false

dojiBu = (srcopen[1] >= max(srcclose,srcopen) and srcclose[1]<=min(srcclose,srcopen)) and lbSize and
  (abs(srcclose-srcopen)<range*pctCDb and (srchigh-max(srcclose,srcopen))>(pctCDw*range) and (min(srcclose,srcopen)-srclow)>(pctCDw*range))? 1 : 0

dojiBe = (srcclose[1] >= max(srcclose,srcopen) and srcopen[1]<=min(srcclose,srcopen)) and lbSize and
  (abs(srcclose-srcopen)<range*pctCDb and (srchigh-max(srcclose,srcopen))>(pctCDw*range) and (min(srcclose,srcopen)-srclow)>(pctCDw*range))? 1 : 0
  
haramiBull = (srcopen<=srcclose or (max(srcclose,srcopen)-min(srcclose,srcopen))<pip*0.5) and lbBull and dojiBu
haramiBear = (srcopen>=srcclose or (max(srcclose,srcopen)-min(srcclose,srcopen))<pip*0.5) and lbBear and dojiBe

dojiBull = not sHm and not haramiBull and not haramiBear and lbBull and dojiBu
dojiBear = not sHm and not haramiBull and not haramiBear and lbBear and dojiBe

//
plotshape(haramiBear and sname?srchigh:na,title="Bearish Harami",text='Bearish\nHarami',color=red, style=shape.arrowdown,location=location.abovebar)
plotshape(haramiBear and cbar?max(srcopen,srcclose):na,title="Bear Colour Harami",color=red, style=shape.circle,location=location.absolute,size=size.normal)
//
plotshape(haramiBull and sname?srclow:na,title="Bullish Harami",text='Bullish\nHarami',color=green, style=shape.arrowup,location=location.belowbar)
plotshape(haramiBull and cbar?max(srcopen,srcclose):na,title="Bull Colour Harami",color=green, style=shape.circle,location=location.absolute,size=size.normal)
//
plotshape(dojiBear and sname?srchigh:na,title="Bearish Doji",text='Bearish\nDoji',color=fuchsia, style=shape.arrowdown,location=location.abovebar)
plotshape(dojiBear and cbar?max(srcopen,srcclose):na,title="Bear Colour Doji",color=fuchsia, style=shape.circle,location=location.absolute,size=size.normal)
//
plotshape(dojiBull and sname?srclow:na,title="Bullish Doji",text='Bullish\nDoji',color=aqua, style=shape.arrowup,location=location.belowbar)
plotshape(dojiBull and cbar?max(srcopen,srcclose):na,title="Bull Colour Doji",color=aqua, style=shape.circle,location=location.absolute,size=size.normal)

// Only Alert harami Doji's
bcolor = haramiBull ? 1 : haramiBear ? 2 : dojiBull ? 3 : dojiBear ? 4 : 0
baralert = setalm and bcolor>0
alertcondition(baralert,title="PACDOJI Alert",message="PACDOJI Alert")

//
plotshape(na(baralert[1])?na:baralert[1], transp=0,style=shape.circle,location=location.bottom, offset=-1,title="Bar Alert Confirmed", 
  color=bcolor[1]==1 ? green : bcolor[1]==2? red : bcolor[1]==3? aqua : bcolor[1]==4? fuchsia : na)

//EOF