Candlestick Trend Indicator v0.4 by JustUncleL

In this updated and final version release of this indicator, apart from some small corrections, I have added two more useful options:

- Added optional coloured Circle dots at bottom of screen to indicate when alert condition is set, only after bar closed. This is handy for when you don't want to use the alarm system, as you quickly see where potential entries are indicated.

- Added optional MACD filtering on the alert condition, saves cross-checking alert against MACD histogram.
Remove from Favorite Scripts Add to Favorite Scripts
// Name: Candlestick Trend Indicator v0.4 by JustUncleL
// By: JustUncleL
// Date: 12-Aug-2016
// Version: v0.4
// Description:
//   This is a trend following indicator+stategy for Binary Options
//   based on Candlestick patterns and trend line - 
//   NOTE: original system was a forex trading system.
//   This code combines a number of indicators to create an overall
//   trading strategy.
//   The indicator recognises and displays some useful candle patterns.
//   In version 0.2 added price action candles from ChrisMoody,
//   Four(4) price action patterns:
//   Yellow = Inside Bar - breakout/continuance 
//   Orange = Outside Bar - breakout/continuance
//   Aqua/Fuschia = Up/Down Shaved Bars - Buying/Selling pressure
//   Red/Green = Possible reversal PinBars - Reverse Down / reverse Up.
//   The PA bars can be doubled up with the named bars.
//   The highlighted candles (maroon and darker green) are the
//   other patterns that are following the current 
//   trend direction that is indicated by the Zero Lag EMA(20) line,
//   this also generates an alert condition for alarm setting.
//   The fractal upper/lower break lines are also draw, if the last
//   fractal break line is broken by a highlighted bar then this
//   indicates a stronger trend conformation.
//   Confirm entry via MACD DEUTER 2 colour(5,15,1), the MACD histogram
//   same colour as hightlighted bar - needs "MACD DEUTER 2 colour" indicator.
//   This multi-indicator set up is suitable for 1hr, 4hr and daily charts 
//   with 1-4 candle expiry.
// references:
//   - [RS]Fractal Levels  by RicardoSantos
//   - Almost Zero Lag EMA [LazyBear]
//   - Candlestick Patterns With EMA by rmwaddelljr
//   - CM_Price-Action-Bars by ChrisMoody
//   - http://www.forexstrategiesresources.com/candlestick-forex-strategies/1-candlestick-trend/
// Modifications:
//  0.4 - Corrected input double up on Reversal Pin Bars.
//        Added optional coloured Circle dots at bottom of screen to indicate when
//        alert condition is set, only after bar closed.
//        Added optional MACD filtering on alert condition, saves checking alert against
//        MACD histogram.
//  0.3 - Corrected PinBar calculation for trend direction support.
//        Modified Engulfing and Harami candles calculatios to be more accurately identified.
//        Added optional reversal pin bars (red/green bars), so possible change in 
//        direction can be identified, this not part of the original alert though.
//        Added option to show only bar patterns that are supporting current trend.
//        Added option to enable Price action bars individually.
//        Returned Dark Cloud Cover, Piecing Line and Pin Bars back into the named
//        candle patterns.
//  0.2 - Removed all candle patterns except Harami and Engulfing candle patterns.
//        Added and highlighted price action candles from CM for extra indication.
//        Changed default ZEMA length from 15 to 20.
//        Bug fixes. (14-Aug-2016)
//  0.1 - original beta release.
study(title="Candlestick Trend Indicator v0.4 by JustUncleL", shorttitle="CDLTRD v0.4 by JustUncleL", overlay=true, scale=scale.right)
// this section based on Almost Zero Lag EMA [LazyBear]
length = input(20,minval=2,title="Length ZeroLagEMA")
ema1=ema(src, length)
ema2=ema(ema1, length)
col =  zlema > zlema[1] ? green : red
up = zlema > zlema[1] ? 1 : 0
down = zlema < zlema[1] ? 1 : 0
plot(zlema,color=col, style=line, linewidth=4, transp=0)

// Find all Fractals.
// This section based on [RS]Fractal Levels  by RicardoSantos
hidefractals = input(false)
hidelevels = input(false)
topfractal = high[2] > high[1] and high[2] > high and high[2] > high[3] and high[2] > high[4]
botfractal = low[2] < low[1] and low[2] < low and low[2] < low[3] and low[2] < low[4]

plotshape(hidefractals ? na : topfractal, color=green, transp=0, style=shape.triangleup, location=location.abovebar, offset=-2, size=size.tiny)
plotshape(hidefractals ? na : botfractal, color=red, transp=0, style=shape.triangledown, location=location.belowbar, offset=-2, size=size.tiny)

topfractals = topfractal ? high[2] : topfractals[1]
botfractals = botfractal ? low[2] : botfractals[1]

topfcolor = topfractals != topfractals[1] ? na : green
botfcolor = botfractals != botfractals[1] ? na : red

plot(hidelevels ? na : topfractals, color=topfcolor, transp=0, linewidth=2)
plot(hidelevels ? na : botfractals, color=botfcolor, transp=0, linewidth=2)

// This section based on Candlestick Patterns With EMA by rmwaddelljr
uhb = input(true, title="Use Candlestick Trend Bars")

// This section based on CM_Price-Action-Bars by ChrisMoody
// Change the pin bar calculation, so can be used for market direction.
pctP = input(66, minval=1, maxval=99, title="Directional PBars, % of Range of Candle the Long Wick Has To Be")
pctS = input(5, minval=1, maxval=99, title="Shaved Bars, % of Range it Has To Close On The Lows or Highs")
upb = input(false, title="Use Price Action Pin Bars")
usb = input(false, title="Use Price Action Shaved Bars")
uob = input(false, title="Use Price Action Outside Bars")
uib = input(false, title="Use Price Action Inside Bars")
pctRP = input(72, minval=1, maxval=99, title="Reversal PBars, % of Range of Candle the Long Wick Has To Be")
pblb =input(6,minval=1,title="Reversal Pin Bar Lookback Length")
sgb = input(false, title="Check Box To Turn Bars Gray")
stnd = input(true, title="Show Only Patterns Following Trend")
salc = input(true, title="Show Alert condition Dot")
// Get MACD for Alert Filtering
umacd  = input(true,title="Use MACD Filtering on Alert")
fastMA = input(title="MACD Fast MA Length", type = integer, defval = 5, minval = 2)
slowMA = input(title="MACD Slow MA Length", type = integer, defval = 15, minval = 7)
signal = input(title="MACD Signal Length",type=integer,defval=1,minval=1)
[currMacd,_,_] = macd(close[0], fastMA, slowMA, signal)
[prevMacd,_,_] = macd(close[1], fastMA, slowMA, signal)
plotColor = currMacd > 0 
    ? currMacd > prevMacd ? green : red
    : currMacd < prevMacd ? red : green

//PBar Percentages
pctCp = pctP * .01

//Shaved Bars Percentages
pctCs = pctS * .01
pctSPO = pctCs

range = high - low

///Reversal PinBars
pctCRp = pctRP * .01
pctCRPO = 1 - pctCRp
pBarRUp= upb and open<close and open > high - (range * pctCRPO) and close > high - (range * pctCRPO) and low <= lowest(pblb) ? 1 : 0
pBarRDn = upb and open>close and open < high - (range *  pctCRp) and close < high-(range * pctCRp) and high >= highest(pblb) ? 1 : 0

//Shaved Bars
sBarUp   = usb and (close >= (high - (range * pctCs)))
sBarDown = usb and (close <= (low + (range * pctCs)))

//Inside Bars
insideBarUp = uib and (high < high[1] and low > low[1])
insideBarDn = uib and (high < high[1] and low > low[1])
outsideBarUp= uob and (high > high[1] and low < low[1])
outsideBarDn= uob and (high > high[1] and low < low[1])

// PinBars representing possible change in trend direction
barcolor(pBarRUp ? green : na)
barcolor(pBarRDn ? red : na)

//Shaved Bars
barcolor(sBarDown and (not stnd or down) ? fuchsia : na)
barcolor(sBarUp and (not stnd or up) ? aqua : na)

//Inside and Outside Bars
barcolor((insideBarUp and (not stnd or up)) or (insideBarDn and (not stnd or down))? yellow : na )
barcolor((outsideBarUp and (not stnd or up)) or (outsideBarDn and (not stnd or down)) ? orange : na )

///PinBars Long Upper Shadow represent selling pressure
pBarDn = uhb and open < high - (range * pctCp) and close < high - (range * pctCp)
///PinBars with Long Lower Shadow represent buying pressure
pBarUp = uhb and open > low + (range * pctCp) and close > low + (range * pctCp)

//Long shadow PinBars supporting market direction
plotshape(pBarDn and (not stnd or down), title= "Bearish Pin Bar",  color=red, style=shape.arrowdown, text="Bearish\nPinBar")
plotshape(pBarUp and (not stnd or up),  title= "Bullish Pin Bar", location=location.belowbar, color=green, style=shape.arrowup, text="Bullish\nPinBar")

dcc = uhb and (close[1]>open[1] and abs(close[1]-open[1])/range[1]>=0.7 and close<open and abs(close-open)/range>=0.7 and open>=close[1] and close>open[1] and close<((open[1]+close[1])/2))
plotshape(dcc and (not stnd or down), title="Dark Cloud Cover",text='DarkCloud\nCover',color=red, style=shape.arrowdown,location=location.abovebar)

pln= uhb and (close[1]<open[1] and abs(open[1]-close[1])/range[1]>=0.7 and close>open and abs(close-open)/range>=0.7 and open<=close[1] and close<open[1] and close>((open[1]+close[1])/2))
plotshape(pln and (not stnd or up), title="Piercieng Line",text="Piercing\nLine",color=green, style=shape.arrowup,location=location.belowbar)

beh = uhb and (close[1] > open[1] and open > close and open <= close[1] and low >= open[1] and open - close < close[1] - open[1] and (high < high[1] and low > low[1]))
plotshape(beh and (not stnd or down), title= "Bearish Harami",  color=red, style=shape.arrowdown, text="Bear\nHarami")

blh = uhb and (open[1] > close[1] and close > open and close <= open[1] and high <= open[1] and close - open < open[1] - close[1] and (high < high[1] and low > low[1]))
plotshape(blh and (not stnd or up),  title= "Bullish Harami", location=location.belowbar, color=green, style=shape.arrowup, text="Bull\nHarami")

bee = uhb and (close[1] > open[1] and close < open and close<=low[1] and open>= close[1])
plotshape(bee and (not stnd or down),  title= "Bearish Engulfing", color=red, style=shape.arrowdown, text="Bearish\nEngulf")

ble = uhb and (close[1] < open[1] and close > open and close >= high[1] and open<=close[1])
plotshape(ble and (not stnd or up), title= "Bullish Engulfing", location=location.belowbar, color=green, style=shape.arrowup, text="Bullish\nEngulf")

barcolor(beh and down ? maroon : na)
barcolor(bee and down ? maroon : na)
barcolor(dcc and down ? maroon : na)
barcolor(pBarDn and down ? maroon : na)
barcolor(ble and up ? lime : na)
barcolor(blh and up ? lime : na)
barcolor(pln and up ? lime : na)
barcolor(pBarUp and up ? lime : na)
barcolor(sgb and close ? gray : na)

barAlertDn = (not umacd or plotColor==red) and ((bee or beh or pBarDn or insideBarDn or outsideBarDn or sBarDown or dcc) and down) 
barAlertUp = (not umacd or plotColor==green) and ((ble or blh or pBarUp or insideBarUp or outsideBarDn or sBarUp or pln) and up)
barAlert = barAlertDn or barAlertUp
alertcondition(barAlert,title="CDLTRD Alert", message="CDLTRD Bar Alert")
// show only when alert condition is met and bar closed.
plotshape(salc and barAlert[1],title= "Alert Indicator Closed", location=location.bottom, color=barAlertDn[1]?red:green, transp=0, style=shape.circle,offset=-1)
Ideas Scripts Chart
United States
United Kingdom
Home Stock Screener Forex Signal Finder Economic Calendar How It Works Chart Features House Rules Moderators For the WEB Widgets Stock Charting Library Priority Support Feature Request Blog & News FAQ Help & Wiki Twitter
Private Messages Chat Ideas Published Followers Following Priority Support Public Profile Profile Settings Account and Billing Sign Out