Candles - All

# ─────────────────────────────────────────────
# │ MarketFragments.com | DNA & Market │
# │ info@marketfragments.com │
# │ www.marketfragments.com │
# ─────────────────────────────────────────────
# Time →
# │
# █ █ █│ █
# █ █ █ │ █ █
# █ █ █ │ █ █ █ ╭─╮
# █ █ █ │ █ █ █ █ ╭─╯ ╰─╮
# █ █ █ │ █ █ █ █ █ █ ╭─╯ ╰─╮
# █ █ █ │ █ █ █ █ █ █ █ █ ╭─╯ ╰─╮
# █ █ █ │ █ █ █ █ █ █ █ █ █ █╭─╯ ╰─╮
# █ █ █ │ █ █ █ █ █ █ █ █ ╰─╮ ╭─╯
# █ █ █ │ █ █ █ █ █ █ ╰─╮ ╭─╯
# █ █ █ │ █ █ █ █ ╰─╮ ╭─╯
# █ █ █ │ █ █ ╰─╮ ╭─╯
# █ █ █ │ █ ╰─────╯
# ──────┴──────────────────────────────────────────────────────────────
# T1 T2 T3 T4 T5 T6
#
# Description:
# This script identifies 105 different candlestick patterns and plots them on the chart.
# It also includes optional breakout signals for many of the patterns.
# Each pattern can be individually enabled or disabled through the study's input settings.
#
# Instructions:
# 1. Open a chart in ThinkOrSwim.
# 2. Click on "Studies" -> "Edit Studies".
# 3. Click on "New" in the lower-left corner.
# 4. Paste the entire contents of this script into the new study window.
# 5. Click "OK" to add the study to your chart.
# 6. You can customize which patterns to display by editing the study's inputs.
#
declare lower;
# -----------------------------------------------------------------------------
# Inputs - Enable/Disable Individual Patterns
# -----------------------------------------------------------------------------
input showAbandonedBabyBull = yes;
input showAbandonedBabyBear = yes;
input showAboveTheStomach = yes;
input showAdvanceBlock = yes;
input showBelowTheStomach = yes;
input showBeltHoldBullish = yes;
input showBeltHoldBearish = yes;
input showBreakawayBullish = yes;
input showBreakawayBearish = yes;
input showConcealingBabySwallow = yes;
input showDarkCloudCover = yes;
input showDeliberation = yes;
input showDojiDragonFly = yes;
input showDojiGappingDown = yes;
input showDojiGappingUp = yes;
input showDojiGravestone = yes;
input showDojiLongLegged = yes;
input showDojiNorthern = yes;
input showDojiSouthern = yes;
input showDojiStarBullish = yes;
input showDojiStarBearish = yes;
input showDojiStarCollapsing = yes;
input showDownsideGap3Methods = yes;
input showDownsideTasukiGap = yes;
input showEngulfingBullish = yes;
input showEngulfingBearish = yes;
input showEveningDojiStar = yes;
input showEveningStar = yes;
input showFalling3Methods = yes;
input showHammer = yes;
input showHammerInverted = yes;
input showHangingMan = yes;
input showHaramiBullish = yes;
input showHaramiBearish = yes;
input showHaramiCrossBullish = yes;
input showHaramiCrossBearish = yes;
input showHighWave = yes;
input showHomingPigeon = yes;
input showIdentical3Crows = yes;
input showInNeckLine = yes;
input showKickingBearish = yes;
input showKickingBullish = yes;
input showLadderBottom = yes;
input showLastEngulfingBottom = yes;
input showLastEngulfingTop = yes;
input showMatchingLow = yes;
input showMatHold = yes;
input showMeetingLinesBullish = yes;
input showMeetingLinesBearish = yes;
input showMorningDojiStar = yes;
input showMorningStar = yes;
input showOnNeckLine = yes;
input showPiercingPattern = yes;
input showRickshawMan = yes;
input showRising3Methods = yes;
input showSeparatingLinesBullish = yes;
input showSeparatingLinesBearish = yes;
input showShootingStar = yes;
input showSideBySideWhiteLinesBullish = yes;
input showSideBySideWhiteLinesBearish = yes;
input showSpinningTop = yes;
input showStickSandwich = yes;
input showTakuri = yes;
input showThreeBlackCrows = yes;
input showThreeInsideUp = yes;
input showThreeInsideDown = yes;
input showThreeLineStrikeBullish = yes;
input showThreeLineStrikeBearish = yes;
input showThreeOutsideUp = yes;
input showThreeOutsideDown = yes;
input showThreeStarsInTheSouth = yes;
input showThreeWhiteSoldiers = yes;
input showThrusting = yes;
input showTriStarBullish = yes;
input showTriStarBearish = yes;
input showTweezersBottom = yes;
input showTweezersTop = yes;
input showTwoBlackGapping = yes;
input showTwoCrows = yes;
input showUnique3RiverBottom = yes;
input showUpsideGap2Crows = yes;
input showUpsideGap3Methods = yes;
input showUpsideTasukiGap = yes;
input showFallingWindow = yes;
input showRisingWindow = yes;
# -----------------------------------------------------------------------------
# Helper Variables and Functions
# -----------------------------------------------------------------------------
def o = open;
def h = high;
def l = low;
def c = close;
def bodyHeight = Absvalue(o - c);
def candleHeight = h - l;
def upperShadow = h - Max(o, c);
def lowerShadow = Min(o, c) - l;
def isWhite = c > o;
def isBlack = c < o;
def isDoji = bodyHeight <= candleHeight * 0.1;
def avgBodyHeight = Average(bodyHeight, 10);
def isLongBody = bodyHeight > avgBodyHeight * 1.5;
def isSmallBody = bodyHeight < avgBodyHeight * 0.5;
def trend = if LinearRegCurve(price = (h + l) / 2, length = 10) > LinearRegCurve(price = (h + l) / 2, length = 10)[1] then 1 else -1;
# -----------------------------------------------------------------------------
# Candlestick Pattern Definitions
# -----------------------------------------------------------------------------
# 1. Abandoned Baby Bullish
def abandonedBabyBull_Pattern = trend[2] == -1 and isBlack[2] and isDoji[1] and h[1] < l[2] and isWhite and o > h[1] and c > o;
plot p_abandonedBabyBull = if showAbandonedBabyBull and abandonedBabyBull_Pattern then l - 10 * TickSize() else Double.NaN;
p_abandonedBabyBull.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
p_abandonedBabyBull.SetDefaultColor(Color.GREEN);
# 2. Abandoned Baby Bearish
def abandonedBabyBear_Pattern = trend[2] == 1 and isWhite[2] and isDoji[1] and l[1] > h[2] and isBlack and o < l[1] and c < o;
plot p_abandonedBabyBear = if showAbandonedBabyBear and abandonedBabyBear_Pattern then h + 10 * TickSize() else Double.NaN;
p_abandonedBabyBear.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
p_abandonedBabyBear.SetDefaultColor(Color.RED);
# 3. Above The Stomach
def aboveTheStomach_Pattern = trend == -1 and isBlack[1] and isWhite and o > (o[1] + c[1]) / 2 and c > c[1];
plot p_aboveTheStomach = if showAboveTheStomach and aboveTheStomach_Pattern then l - 10 * TickSize() else Double.NaN;
p_aboveTheStomach.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
p_aboveTheStomach.SetDefaultColor(Color.GREEN);
# 4. Advance Block
def advanceBlock_Pattern = trend == 1 and isWhite[2] and isWhite[1] and isWhite and c > c[1] and c[1] > c[2] and (c - o) < (c[1] - o[1]) and (c[1] - o[1]) < (c[2] - o[2]) and upperShadow > bodyHeight and upperShadow[1] > bodyHeight[1];
plot p_advanceBlock = if showAdvanceBlock and advanceBlock_Pattern then h + 10 * TickSize() else Double.NaN;
p_advanceBlock.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
p_advanceBlock.SetDefaultColor(Color.RED);
# 5. Below The Stomach
def belowTheStomach_Pattern = trend == 1 and isWhite[1] and isBlack and o < (o[1] + c[1]) / 2 and c < c[1];
plot p_belowTheStomach = if showBelowTheStomach and belowTheStomach_Pattern then h + 10 * TickSize() else Double.NaN;
p_belowTheStomach.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
p_belowTheStomach.SetDefaultColor(Color.RED);
# 6. Belt Hold Bullish
def beltHoldBullish_Pattern = trend == -1 and isWhite and o == l and isLongBody;
plot p_beltHoldBullish = if showBeltHoldBullish and beltHoldBullish_Pattern then l - 10 * TickSize() else Double.NaN;
p_beltHoldBullish.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
p_beltHoldBullish.SetDefaultColor(Color.GREEN);
# 7. Belt Hold Bearish
def beltHoldBearish_Pattern = trend == 1 and isBlack and o == h and isLongBody;
plot p_beltHoldBearish = if showBeltHoldBearish and beltHoldBearish_Pattern then h + 10 * TickSize() else Double.NaN;
p_beltHoldBearish.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
p_beltHoldBearish.SetDefaultColor(Color.RED);
# 8. Breakaway Bullish
def breakawayBullish_Pattern = trend == -1 and isBlack[4] and isLongBody[4] and isBlack[3] and o[3] < o[4] and c[3] < c[4] and isBlack[2] and isBlack[1] and isWhite and isLongBody and c > o[3] and c < o[4];
plot p_breakawayBullish = if showBreakawayBullish and breakawayBullish_Pattern then l - 10 * TickSize() else Double.NaN;
p_breakawayBullish.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
p_breakawayBullish.SetDefaultColor(Color.GREEN);
# 9. Breakaway Bearish
def breakawayBearish_Pattern = trend == 1 and isWhite[4] and isLongBody[4] and isWhite[3] and o[3] > o[4] and c[3] > c[4] and isWhite[2] and isWhite[1] and isBlack and isLongBody and c < o[3] and c > o[4];
plot p_breakawayBearish = if showBreakawayBearish and breakawayBearish_Pattern then h + 10 * TickSize() else Double.NaN;
p_breakawayBearish.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
p_breakawayBearish.SetDefaultColor(Color.RED);
# 10. Concealing Baby Swallow
def concealingBabySwallow_Pattern = trend == -1 and isBlack[3] and isBlack[2] and o[2] == h[2] and c[2] == l[2] and isBlack[1] and c[1] > c[2] and o[1] < o[2] and isBlack and c > c[1] and o < o[1];
plot p_concealingBabySwallow = if showConcealingBabySwallow and concealingBabySwallow_Pattern then l - 10 * TickSize() else Double.NaN;
p_concealingBabySwallow.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
p_concealingBabySwallow.SetDefaultColor(Color.GREEN);
# 11. Dark Cloud Cover
def darkCloudCover_Pattern = trend == 1 and isWhite[1] and isLongBody[1] and isBlack and o > h[1] and c < (o[1] + c[1]) / 2 and c > o[1];
plot p_darkCloudCover = if showDarkCloudCover and darkCloudCover_Pattern then h + 10 * TickSize() else Double.NaN;
p_darkCloudCover.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
p_darkCloudCover.SetDefaultColor(Color.RED);
# 12. Deliberation
def deliberation_Pattern = trend == 1 and isWhite[2] and isLongBody[2] and isWhite[1] and isLongBody[1] and c[1] > c[2] and isSmallBody and o > c[1];
plot p_deliberation = if showDeliberation and deliberation_Pattern then h + 10 * TickSize() else Double.NaN;
p_deliberation.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
p_deliberation.SetDefaultColor(Color.RED);
# 13. Doji Star Bullish
def dojiStarBullish_Pattern = trend == -1 and isBlack[1] and isLongBody[1] and isDoji and o < c[1];
plot p_dojiStarBullish = if showDojiStarBullish and dojiStarBullish_Pattern then l - 10 * TickSize() else Double.NaN;
p_dojiStarBullish.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
p_dojiStarBullish.SetDefaultColor(Color.GREEN);
# 14. Doji Star Bearish
def dojiStarBearish_Pattern = trend == 1 and isWhite[1] and isLongBody[1] and isDoji and o > c[1];
plot p_dojiStarBearish = if showDojiStarBearish and dojiStarBearish_Pattern then h + 10 * TickSize() else Double.NaN;
p_dojiStarBearish.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
p_dojiStarBearish.SetDefaultColor(Color.RED);
# 15. Downside Gap 3 Methods
def downsideGap3Methods_Pattern = trend == -1 and isBlack[2] and isLongBody[2] and isBlack[1] and isLongBody[1] and c[1] < c[2] and o[1] < l[2] and isWhite and o > o[1] and c > c[2];
plot p_downsideGap3Methods = if showDownsideGap3Methods and downsideGap3Methods_Pattern then l - 10 * TickSize() else Double.NaN;
p_downsideGap3Methods.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
p_downsideGap3Methods.SetDefaultColor(Color.GREEN);
# 16. Downside Tasuki Gap
def downsideTasukiGap_Pattern = trend == -1 and isBlack[2] and isBlack[1] and o[1] < c[2] and c[1] < o[1] and isWhite and o > c[1] and o < o[1] and c > o[1] and c < c[2];
plot p_downsideTasukiGap = if showDownsideTasukiGap and downsideTasukiGap_Pattern then l - 10 * TickSize() else Double.NaN;
p_downsideTasukiGap.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
p_downsideTasukiGap.SetDefaultColor(Color.GREEN);
# 17. Engulfing Bullish
def engulfingBullish_Pattern = trend == -1 and isBlack[1] and isWhite and o < c[1] and c > o[1];
plot p_engulfingBullish = if showEngulfingBullish and engulfingBullish_Pattern then l - 10 * TickSize() else Double.NaN;
p_engulfingBullish.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
p_engulfingBullish.SetDefaultColor(Color.GREEN);
# 18. Engulfing Bearish
def engulfingBearish_Pattern = trend == 1 and isWhite[1] and isBlack and o > c[1] and c < o[1];
plot p_engulfingBearish = if showEngulfingBearish and engulfingBearish_Pattern then h + 10 * TickSize() else Double.NaN;
p_engulfingBearish.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
p_engulfingBearish.SetDefaultColor(Color.RED);
# 19. Evening Doji Star
def eveningDojiStar_Pattern = trend == 1 and isWhite[2] and isLongBody[2] and isDoji[1] and o[1] > c[2] and isBlack and o < o[1] and c < (c[2] + o[2]) / 2;
plot p_eveningDojiStar = if showEveningDojiStar and eveningDojiStar_Pattern then h + 10 * TickSize() else Double.NaN;
p_eveningDojiStar.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
p_eveningDojiStar.SetDefaultColor(Color.RED);
# 20. Evening Star
def eveningStar_Pattern = trend == 1 and isWhite[2] and isLongBody[2] and isSmallBody[1] and o[1] > c[2] and isBlack and o < o[1] and c < (c[2] + o[2]) / 2;
plot p_eveningStar = if showEveningStar and eveningStar_Pattern then h + 10 * TickSize() else Double.NaN;
p_eveningStar.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
p_eveningStar.SetDefaultColor(Color.RED);
# 21. Falling 3 Methods
def falling3Methods_Pattern = isBlack[4] and isLongBody[4] and isWhite[3] and isWhite[2] and isWhite[1] and o[3] > c[4] and c[1] < o[4] and isBlack and isLongBody and c < c[4];
plot p_falling3Methods = if showFalling3Methods and falling3Methods_Pattern then h + 10 * TickSize() else Double.NaN;
p_falling3Methods.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
p_falling3Methods.SetDefaultColor(Color.RED);
# 22. Hammer
def hammer_Pattern = trend == -1 and isSmallBody and lowerShadow >= 2 * bodyHeight and upperShadow <= 0.1 * candleHeight;
plot p_hammer = if showHammer and hammer_Pattern then l - 10 * TickSize() else Double.NaN;
p_hammer.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
p_hammer.SetDefaultColor(Color.GREEN);
# 23. Hanging Man
def hangingMan_Pattern = trend == 1 and isSmallBody and lowerShadow >= 2 * bodyHeight and upperShadow <= 0.1 * candleHeight;
plot p_hangingMan = if showHangingMan and hangingMan_Pattern then h + 10 * TickSize() else Double.NaN;
p_hangingMan.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
p_hangingMan.SetDefaultColor(Color.RED);
# 24. Harami Bullish
def haramiBullish_Pattern = trend == -1 and isBlack[1] and isLongBody[1] and isWhite and isSmallBody and c < o[1] and o > c[1];
plot p_haramiBullish = if showHaramiBullish and haramiBullish_Pattern then l - 10 * TickSize() else Double.NaN;
p_haramiBullish.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
p_haramiBullish.SetDefaultColor(Color.GREEN);
# 25. Harami Bearish
def haramiBearish_Pattern = trend == 1 and isWhite[1] and isLongBody[1] and isBlack and isSmallBody and c > o[1] and o < c[1];
plot p_haramiBearish = if showHaramiBearish and haramiBearish_Pattern then h + 10 * TickSize() else Double.NaN;
p_haramiBearish.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
p_haramiBearish.SetDefaultColor(Color.RED);
# 26. Harami Cross Bullish
def haramiCrossBullish_Pattern = trend == -1 and isBlack[1] and isLongBody[1] and isDoji and c < o[1] and o > c[1];
plot p_haramiCrossBullish = if showHaramiCrossBullish and haramiCrossBullish_Pattern then l - 10 * TickSize() else Double.NaN;
p_haramiCrossBullish.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
p_haramiCrossBullish.SetDefaultColor(Color.GREEN);
# 27. Harami Cross Bearish
def haramiCrossBearish_Pattern = trend == 1 and isWhite[1] and isLongBody[1] and isDoji and c > o[1] and o < c[1];
plot p_haramiCrossBearish = if showHaramiCrossBearish and haramiCrossBearish_Pattern then h + 10 * TickSize() else Double.NaN;
p_haramiCrossBearish.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
p_haramiCrossBearish.SetDefaultColor(Color.RED);
# 28. High Wave
def highWave_Pattern = isSmallBody and upperShadow > 2 * bodyHeight and lowerShadow > 2 * bodyHeight;
plot p_highWave = if showHighWave and highWave_Pattern then h + 10 * TickSize() else Double.NaN;
p_highWave.SetPaintingStrategy(paintingStrategy.BOOLEAN_POINTS);
p_highWave.SetDefaultColor(Color.GRAY);
# 29. Homing Pigeon
def homingPigeon_Pattern = trend == -1 and isBlack[1] and isLongBody[1] and isBlack and isSmallBody and c < o[1] and o > c[1];
plot p_homingPigeon = if showHomingPigeon and homingPigeon_Pattern then l - 10 * TickSize() else Double.NaN;
p_homingPigeon.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
p_homingPigeon.SetDefaultColor(Color.GREEN);
# 30. Identical 3 Crows
def identical3Crows_Pattern = trend == 1 and isBlack[2] and isLongBody[2] and isBlack[1] and isLongBody[1] and isBlack and isLongBody and o[1] == o[2] and o == o[1];
plot p_identical3Crows = if showIdentical3Crows and identical3Crows_Pattern then h + 10 * TickSize() else Double.NaN;
p_identical3Crows.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
p_identical3Crows.SetDefaultColor(Color.RED);
# 31. In-Neck Line
def inNeckLine_Pattern = trend == -1 and isBlack[1] and isLongBody[1] and isWhite and o < l[1] and Absvalue(c - c[1]) < (c[1] * 0.05);
plot p_inNeckLine = if showInNeckLine and inNeckLine_Pattern then h + 10 * TickSize() else Double.NaN;
p_inNeckLine.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
p_inNeckLine.SetDefaultColor(Color.RED);
# 32. Inverted Hammer
def invertedHammer_Pattern = trend == -1 and isSmallBody and upperShadow >= 2 * bodyHeight and lowerShadow <= 0.1 * candleHeight;
plot p_invertedHammer = if showHammerInverted and invertedHammer_Pattern then l - 10 * TickSize() else Double.NaN;
p_invertedHammer.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
p_invertedHammer.SetDefaultColor(Color.GREEN);
# 33. Kicking Bullish
def kickingBullish_Pattern = isBlack[1] and o[1] == h[1] and c[1] == l[1] and isWhite and o == l and c == h and o > o[1];
plot p_kickingBullish = if showKickingBullish and kickingBullish_Pattern then l - 10 * TickSize() else Double.NaN;
p_kickingBullish.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
p_kickingBullish.SetDefaultColor(Color.GREEN);
# 34. Kicking Bearish
def kickingBearish_Pattern = isWhite[1] and o[1] == l[1] and c[1] == h[1] and isBlack and o == h and c == l and o < o[1];
plot p_kickingBearish = if showKickingBearish and kickingBearish_Pattern then h + 10 * TickSize() else Double.NaN;
p_kickingBearish.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
p_kickingBearish.SetDefaultColor(Color.RED);
# 35. Ladder Bottom
def ladderBottom_Pattern = trend == -1 and isBlack[4] and isLongBody[4] and isBlack[3] and isLongBody[3] and isBlack[2] and isLongBody[2] and c[3] < c[4] and c[2] < c[3] and isBlack[1] and upperShadow[1] > bodyHeight[1] and isWhite and o > c[1];
plot p_ladderBottom = if showLadderBottom and ladderBottom_Pattern then l - 10 * TickSize() else Double.NaN;
p_ladderBottom.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
p_ladderBottom.SetDefaultColor(Color.GREEN);
# 36. Last Engulfing Bottom
def lastEngulfingBottom_Pattern = trend == -1 and isWhite[1] and isBlack and engulfingBearish_Pattern[1];
plot p_lastEngulfingBottom = if showLastEngulfingBottom and lastEngulfingBottom_Pattern then l - 10 * TickSize() else Double.NaN;
p_lastEngulfingBottom.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
p_lastEngulfingBottom.SetDefaultColor(Color.GREEN);
# 37. Last Engulfing Top
def lastEngulfingTop_Pattern = trend == 1 and isBlack[1] and isWhite and engulfingBullish_Pattern[1];
plot p_lastEngulfingTop = if showLastEngulfingTop and lastEngulfingTop_Pattern then h + 10 * TickSize() else Double.NaN;
p_lastEngulfingTop.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
p_lastEngulfingTop.SetDefaultColor(Color.RED);
# 38. Matching Low
def matchingLow_Pattern = trend == -1 and isBlack[1] and isLongBody[1] and isBlack and c == c[1];
plot p_matchingLow = if showMatchingLow and matchingLow_Pattern then l - 10 * TickSize() else Double.NaN;
p_matchingLow.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
p_matchingLow.SetDefaultColor(Color.GREEN);
# 39. Mat Hold
def matHold_Pattern = trend == 1 and isWhite[4] and isLongBody[4] and isBlack[3] and o[3] > c[4] and isSmallBody[2] and isSmallBody[1] and c[1] < h[4] and c[2] < h[4] and isWhite and o > h[4] and c > c[4];
plot p_matHold = if showMatHold and matHold_Pattern then l - 10 * TickSize() else Double.NaN;
p_matHold.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
p_matHold.SetDefaultColor(Color.GREEN);
# 40. Meeting Lines Bullish
def meetingLinesBullish_Pattern = trend == -1 and isBlack[1] and isLongBody[1] and isWhite and isLongBody and o < l[1] and c == c[1];
plot p_meetingLinesBullish = if showMeetingLinesBullish and meetingLinesBullish_Pattern then l - 10 * TickSize() else Double.NaN;
p_meetingLinesBullish.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
p_meetingLinesBullish.SetDefaultColor(Color.GREEN);
# 41. Meeting Lines Bearish
def meetingLinesBearish_Pattern = trend == 1 and isWhite[1] and isLongBody[1] and isBlack and isLongBody and o > h[1] and c == c[1];
plot p_meetingLinesBearish = if showMeetingLinesBearish and meetingLinesBearish_Pattern then h + 10 * TickSize() else Double.NaN;
p_meetingLinesBearish.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
p_meetingLinesBearish.SetDefaultColor(Color.RED);
# 42. Morning Doji Star
def morningDojiStar_Pattern = trend == -1 and isBlack[2] and isLongBody[2] and isDoji[1] and o[1] < c[2] and isWhite and o > o[1] and c > (c[2] + o[2]) / 2;
plot p_morningDojiStar = if showMorningDojiStar and morningDojiStar_Pattern then l - 10 * TickSize() else Double.NaN;
p_morningDojiStar.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
p_morningDojiStar.SetDefaultColor(Color.GREEN);
# 43. Morning Star
def morningStar_Pattern = trend == -1 and isBlack[2] and isLongBody[2] and isSmallBody[1] and o[1] < c[2] and isWhite and o > o[1] and c > (c[2] + o[2]) / 2;
plot p_morningStar = if showMorningStar and morningStar_Pattern then l - 10 * TickSize() else Double.NaN;
p_morningStar.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
p_morningStar.SetDefaultColor(Color.GREEN);
# 44. On-Neck Line
def onNeckLine_Pattern = trend == -1 and isBlack[1] and isLongBody[1] and isWhite and o < l[1] and c == l[1];
plot p_onNeckLine = if showOnNeckLine and onNeckLine_Pattern then h + 10 * TickSize() else Double.NaN;
p_onNeckLine.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
p_onNeckLine.SetDefaultColor(Color.RED);
# 45. Piercing Pattern
def piercingPattern_Pattern = trend == -1 and isBlack[1] and isLongBody[1] and isWhite and o < l[1] and c > (o[1] + c[1]) / 2 and c < o[1];
plot p_piercingPattern = if showPiercingPattern and piercingPattern_Pattern then l - 10 * TickSize() else Double.NaN;
p_piercingPattern.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
p_piercingPattern.SetDefaultColor(Color.GREEN);
# 46. Rickshaw Man
def rickshawMan_Pattern = isDoji and upperShadow == lowerShadow and upperShadow > bodyHeight;
plot p_rickshawMan = if showRickshawMan and rickshawMan_Pattern then h + 10 * TickSize() else Double.NaN;
p_rickshawMan.SetPaintingStrategy(paintingStrategy.BOOLEAN_POINTS);
p_rickshawMan.SetDefaultColor(Color.GRAY);
# 47. Rising 3 Methods
def rising3Methods_Pattern = isWhite[4] and isLongBody[4] and isBlack[3] and isBlack[2] and isBlack[1] and o[3] < c[4] and c[1] > o[4] and isWhite and isLongBody and c > c[4];
plot p_rising3Methods = if showRising3Methods and rising3Methods_Pattern then l - 10 * TickSize() else Double.NaN;
p_rising3Methods.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
p_rising3Methods.SetDefaultColor(Color.GREEN);
# 48. Separating Lines Bullish
def separatingLinesBullish_Pattern = trend == 1 and isBlack[1] and isWhite and o == o[1] and isLongBody and isLongBody[1];
plot p_separatingLinesBullish = if showSeparatingLinesBullish and separatingLinesBullish_Pattern then l - 10 * TickSize() else Double.NaN;
p_separatingLinesBullish.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
p_separatingLinesBullish.SetDefaultColor(Color.GREEN);
# 49. Separating Lines Bearish
def separatingLinesBearish_Pattern = trend == -1 and isWhite[1] and isBlack and o == o[1] and isLongBody and isLongBody[1];
plot p_separatingLinesBearish = if showSeparatingLinesBearish and separatingLinesBearish_Pattern then h + 10 * TickSize() else Double.NaN;
p_separatingLinesBearish.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
p_separatingLinesBearish.SetDefaultColor(Color.RED);
# 50. Shooting Star
def shootingStar_Pattern = trend == 1 and isSmallBody and upperShadow >= 2 * bodyHeight and lowerShadow <= 0.1 * candleHeight;
plot p_shootingStar = if showShootingStar and shootingStar_Pattern then h + 10 * TickSize() else Double.NaN;
p_shootingStar.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
p_shootingStar.SetDefaultColor(Color.RED);
# 51. Side-by-Side White Lines Bullish
def sideBySideWhiteLinesBullish_Pattern = trend == 1 and isWhite[2] and isWhite[1] and isWhite and o[1] > c[2] and Absvalue(o - o[1]) < (o * 0.05) and Absvalue(c - c[1]) < (c * 0.05);
plot p_sideBySideWhiteLinesBullish = if showSideBySideWhiteLinesBullish and sideBySideWhiteLinesBullish_Pattern then l - 10 * TickSize() else Double.NaN;
p_sideBySideWhiteLinesBullish.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
p_sideBySideWhiteLinesBullish.SetDefaultColor(Color.GREEN);
# 52. Side-by-Side White Lines Bearish
def sideBySideWhiteLinesBearish_Pattern = trend == -1 and isBlack[2] and isWhite[1] and isWhite and o[1] < c[2] and Absvalue(o - o[1]) < (o * 0.05) and Absvalue(c - c[1]) < (c * 0.05);
plot p_sideBySideWhiteLinesBearish = if showSideBySideWhiteLinesBearish and sideBySideWhiteLinesBearish_Pattern then h + 10 * TickSize() else Double.NaN;
p_sideBySideWhiteLinesBearish.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
p_sideBySideWhiteLinesBearish.SetDefaultColor(Color.RED);
# 53. Spinning Top
def spinningTop_Pattern = isSmallBody and upperShadow > bodyHeight and lowerShadow > bodyHeight;
plot p_spinningTop = if showSpinningTop and spinningTop_Pattern then h + 10 * TickSize() else Double.NaN;
p_spinningTop.SetPaintingStrategy(paintingStrategy.BOOLEAN_POINTS);
p_spinningTop.SetDefaultColor(Color.GRAY);
# 54. Stick Sandwich
def stickSandwich_Pattern = isBlack[2] and isWhite[1] and isBlack and c == c[2] and c[1] > c and c[1] > c[2];
plot p_stickSandwich = if showStickSandwich and stickSandwich_Pattern then l - 10 * TickSize() else Double.NaN;
p_stickSandwich.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
p_stickSandwich.SetDefaultColor(Color.GREEN);
# 55. Takuri
def takuri_Pattern = trend == -1 and isSmallBody and lowerShadow >= 3 * bodyHeight and upperShadow <= 0.05 * candleHeight;
plot p_takuri = if showTakuri and takuri_Pattern then l - 10 * TickSize() else Double.NaN;
p_takuri.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
p_takuri.SetDefaultColor(Color.GREEN);
# 56. Three Black Crows
def threeBlackCrows_Pattern = trend == 1 and isBlack[2] and isLongBody[2] and isBlack[1] and isLongBody[1] and isBlack and isLongBody and c[1] < c[2] and c < c[1] and o[1] < o[2] and o < o[1] and o[1] > c[2] and o > c[1];
plot p_threeBlackCrows = if showThreeBlackCrows and threeBlackCrows_Pattern then h + 10 * TickSize() else Double.NaN;
p_threeBlackCrows.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
p_threeBlackCrows.SetDefaultColor(Color.RED);
# 57. Three Inside Up
def threeInsideUp_Pattern = haramiBullish_Pattern[1] and isWhite and c > c[1];
plot p_threeInsideUp = if showThreeInsideUp and threeInsideUp_Pattern then l - 10 * TickSize() else Double.NaN;
p_threeInsideUp.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
p_threeInsideUp.SetDefaultColor(Color.GREEN);
# 58. Three Inside Down
def threeInsideDown_Pattern = haramiBearish_Pattern[1] and isBlack and c < c[1];
plot p_threeInsideDown = if showThreeInsideDown and threeInsideDown_Pattern then h + 10 * TickSize() else Double.NaN;
p_threeInsideDown.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
p_threeInsideDown.SetDefaultColor(Color.RED);
def threeWhiteSoldiers_Pattern = trend == -1 and isWhite[2] and isLongBody[2] and isWhite[1] and isLongBody[1] and isWhite and isLongBody and c[1] > c[2] and c > c[1] and o[1] > o[2] and o > o[1] and o[1] < c[2] and o < c[1];
# 59. Three-Line Strike Bullish
def threeLineStrikeBullish_Pattern = threeWhiteSoldiers_Pattern[1] and isBlack and o > c[1] and c < o[2];
plot p_threeLineStrikeBullish = if showThreeLineStrikeBullish and threeLineStrikeBullish_Pattern then h + 10 * TickSize() else Double.NaN;
p_threeLineStrikeBullish.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
p_threeLineStrikeBullish.SetDefaultColor(Color.RED);
# 60. Three-Line Strike Bearish
def threeLineStrikeBearish_Pattern = threeBlackCrows_Pattern[1] and isWhite and o < c[1] and c > o[2];
plot p_threeLineStrikeBearish = if showThreeLineStrikeBearish and threeLineStrikeBearish_Pattern then l - 10 * TickSize() else Double.NaN;
p_threeLineStrikeBearish.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
p_threeLineStrikeBearish.SetDefaultColor(Color.GREEN);
# 61. Three Outside Up
def threeOutsideUp_Pattern = engulfingBullish_Pattern[1] and isWhite and c > c[1];
plot p_threeOutsideUp = if showThreeOutsideUp and threeOutsideUp_Pattern then l - 10 * TickSize() else Double.NaN;
p_threeOutsideUp.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
p_threeOutsideUp.SetDefaultColor(Color.GREEN);
# 62. Three Outside Down
def threeOutsideDown_Pattern = engulfingBearish_Pattern[1] and isBlack and c < c[1];
plot p_threeOutsideDown = if showThreeOutsideDown and threeOutsideDown_Pattern then h + 10 * TickSize() else Double.NaN;
p_threeOutsideDown.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
p_threeOutsideDown.SetDefaultColor(Color.RED);
# 63. Three Stars in the South
def threeStarsInTheSouth_Pattern = trend == -1 and isBlack[2] and isLongBody[2] and lowerShadow[2] > bodyHeight[2] and isBlack[1] and c[1] > c[2] and l[1] > l[2] and isBlack and isSmallBody and h < h[1] and l > l[1];
plot p_threeStarsInTheSouth = if showThreeStarsInTheSouth and threeStarsInTheSouth_Pattern then l - 10 * TickSize() else Double.NaN;
p_threeStarsInTheSouth.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
p_threeStarsInTheSouth.SetDefaultColor(Color.GREEN);
# 64. Three White Soldiers
plot p_threeWhiteSoldiers = if showThreeWhiteSoldiers and threeWhiteSoldiers_Pattern then l - 10 * TickSize() else Double.NaN;
p_threeWhiteSoldiers.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
p_threeWhiteSoldiers.SetDefaultColor(Color.GREEN);
# 65. Thrusting
def thrusting_Pattern = trend == -1 and isBlack[1] and isWhite and o < c[1] and c > c[1] and c < (o[1] + c[1]) / 2;
plot p_thrusting = if showThrusting and thrusting_Pattern then h + 10 * TickSize() else Double.NaN;
p_thrusting.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
p_thrusting.SetDefaultColor(Color.RED);
# 66. Tri-Star Bullish
def triStarBullish_Pattern = trend == -1 and isDoji[2] and isDoji[1] and isDoji and h[1] < l[2] and h[1] < l;
plot p_triStarBullish = if showTriStarBullish and triStarBullish_Pattern then l - 10 * TickSize() else Double.NaN;
p_triStarBullish.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
p_triStarBullish.SetDefaultColor(Color.GREEN);
# 67. Tri-Star Bearish
def triStarBearish_Pattern = trend == 1 and isDoji[2] and isDoji[1] and isDoji and l[1] > h[2] and l[1] > h;
plot p_triStarBearish = if showTriStarBearish and triStarBearish_Pattern then h + 10 * TickSize() else Double.NaN;
p_triStarBearish.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
p_triStarBearish.SetDefaultColor(Color.RED);
# 68. Tweezers Bottom
def tweezersBottom_Pattern = trend == -1 and isBlack[1] and isWhite and l == l[1];
plot p_tweezersBottom = if showTweezersBottom and tweezersBottom_Pattern then l - 10 * TickSize() else Double.NaN;
p_tweezersBottom.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
p_tweezersBottom.SetDefaultColor(Color.GREEN);
# 69. Tweezers Top
def tweezersTop_Pattern = trend == 1 and isWhite[1] and isBlack and h == h[1];
plot p_tweezersTop = if showTweezersTop and tweezersTop_Pattern then h + 10 * TickSize() else Double.NaN;
p_tweezersTop.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
p_tweezersTop.SetDefaultColor(Color.RED);
# 70. Two Black Gapping
def twoBlackGapping_Pattern = trend == 1 and isBlack[2] and isBlack[1] and o[1] > h[2] and c < c[1] and o < o[1];
plot p_twoBlackGapping = if showTwoBlackGapping and twoBlackGapping_Pattern then h + 10 * TickSize() else Double.NaN;
p_twoBlackGapping.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
p_twoBlackGapping.SetDefaultColor(Color.RED);
# 71. Two Crows
def twoCrows_Pattern = trend == 1 and isWhite[2] and isLongBody[2] and isBlack[1] and o[1] > c[2] and isBlack and o > o[1] and c < c[2];
plot p_twoCrows = if showTwoCrows and twoCrows_Pattern then h + 10 * TickSize() else Double.NaN;
p_twoCrows.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
p_twoCrows.SetDefaultColor(Color.RED);
# 72. Unique 3-River Bottom
def unique3RiverBottom_Pattern = trend == -1 and isBlack[2] and isLongBody[2] and haramiBearish_Pattern[1] and isWhite and c < c[1];
plot p_unique3RiverBottom = if showUnique3RiverBottom and unique3RiverBottom_Pattern then l - 10 * TickSize() else Double.NaN;
p_unique3RiverBottom.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
p_unique3RiverBottom.SetDefaultColor(Color.GREEN);
# 73. Upside Gap 2 Crows
def upsideGap2Crows_Pattern = trend == 1 and isWhite[2] and isBlack[1] and o[1] > c[2] and isBlack and o > o[1] and c < c[2] and c > o[1];
plot p_upsideGap2Crows = if showUpsideGap2Crows and upsideGap2Crows_Pattern then h + 10 * TickSize() else Double.NaN;
p_upsideGap2Crows.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
p_upsideGap2Crows.SetDefaultColor(Color.RED);
# 74. Upside Gap 3 Methods
def upsideGap3Methods_Pattern = trend == 1 and isWhite[2] and isLongBody[2] and isWhite[1] and isLongBody[1] and c[1] > c[2] and o[1] > h[2] and isBlack and o < o[1] and c < c[2];
plot p_upsideGap3Methods = if showUpsideGap3Methods and upsideGap3Methods_Pattern then h + 10 * TickSize() else Double.NaN;
p_upsideGap3Methods.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
p_upsideGap3Methods.SetDefaultColor(Color.RED);
# 75. Upside Tasuki Gap
def upsideTasukiGap_Pattern = trend == 1 and isWhite[2] and isWhite[1] and o[1] > c[2] and c[1] > o[1] and isBlack and o < c[1] and o > o[1] and c < o[1] and c > c[2];
plot p_upsideTasukiGap = if showUpsideTasukiGap and upsideTasukiGap_Pattern then h + 10 * TickSize() else Double.NaN;
p_upsideTasukiGap.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
p_upsideTasukiGap.SetDefaultColor(Color.RED);
# 76. Falling Window
def fallingWindow_Pattern = h[1] < l;
plot p_fallingWindow = if showFallingWindow and fallingWindow_Pattern then h + 10 * TickSize() else Double.NaN;
p_fallingWindow.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
p_fallingWindow.SetDefaultColor(Color.RED);
# 77. Rising Window
def risingWindow_Pattern = l[1] > h;
plot p_risingWindow = if showRisingWindow and risingWindow_Pattern then l - 10 * TickSize() else Double.NaN;
p_risingWindow.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
p_risingWindow.SetDefaultColor(Color.GREEN);
# 78. Doji Gapping Down
def dojiGappingDown_Pattern = isDoji and h < l[1];
plot p_dojiGappingDown = if showDojiGappingDown and dojiGappingDown_Pattern then h + 10 * TickSize() else Double.NaN;
p_dojiGappingDown.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
p_dojiGappingDown.SetDefaultColor(Color.RED);
# 79. Doji Gapping Up
def dojiGappingUp_Pattern = isDoji and l > h[1];
plot p_dojiGappingUp = if showDojiGappingUp and dojiGappingUp_Pattern then l - 10 * TickSize() else Double.NaN;
p_dojiGappingUp.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
p_dojiGappingUp.SetDefaultColor(Color.GREEN);
# 80. Doji Gravestone
def dojiGravestone_Pattern = isDoji and upperShadow > 0.8 * candleHeight and lowerShadow < 0.1 * candleHeight;
plot p_dojiGravestone = if showDojiGravestone and dojiGravestone_Pattern then h + 10 * TickSize() else Double.NaN;
p_dojiGravestone.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
p_dojiGravestone.SetDefaultColor(Color.RED);
# 81. Doji Long-Legged
def dojiLongLegged_Pattern = isDoji and upperShadow > bodyHeight and lowerShadow > bodyHeight;
plot p_dojiLongLegged = if showDojiLongLegged and dojiLongLegged_Pattern then h + 10 * TickSize() else Double.NaN;
p_dojiLongLegged.SetPaintingStrategy(paintingStrategy.BOOLEAN_POINTS);
p_dojiLongLegged.SetDefaultColor(Color.GRAY);
# 82. Doji Northern
def dojiNorthern_Pattern = trend == 1 and isDoji;
plot p_dojiNorthern = if showDojiNorthern and dojiNorthern_Pattern then h + 10 * TickSize() else Double.NaN;
p_dojiNorthern.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
p_dojiNorthern.SetDefaultColor(Color.RED);
# 83. Doji Southern
def dojiSouthern_Pattern = trend == -1 and isDoji;
plot p_dojiSouthern = if showDojiSouthern and dojiSouthern_Pattern then l - 10 * TickSize() else Double.NaN;
p_dojiSouthern.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
p_dojiSouthern.SetDefaultColor(Color.GREEN);
# 84. Doji Dragonfly
def dojiDragonfly_Pattern = isDoji and lowerShadow > 0.8 * candleHeight and upperShadow < 0.1 * candleHeight;
plot p_dojiDragonfly = if showDojiDragonFly and dojiDragonfly_Pattern then l - 10 * TickSize() else Double.NaN;
p_dojiDragonfly.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
p_dojiDragonfly.SetDefaultColor(Color.GREEN);
# 85. Doji Star Collapsing
def dojiStarCollapsing_Pattern = trend == 1 and isWhite[2] and isDoji[1] and l[1] > h[2] and isBlack and o < l[1] and c < o;
plot p_dojiStarCollapsing = if showDojiStarCollapsing and dojiStarCollapsing_Pattern then h + 10 * TickSize() else Double.NaN;
p_dojiStarCollapsing.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
p_dojiStarCollapsing.SetDefaultColor(Color.RED);

