Candle Patterns 10 [BUY/SELL Auto] β€” Strategy by jolieeden123

By version

Performance Metrics

Description

🟒 Hammer🟒 Bull Engulfing🟒 Morning Star🟒 Bull Marubozu🟒 3 White SoldiersπŸ”΄ Shooting StarπŸ”΄ Bear EngulfingπŸ”΄ Evening StarπŸ”΄ Bear MarubozuπŸ”΄ 3 Black CrowsCΓ‘ch paste an toΓ n (trΓ‘nh mαΊ₯t kΓ½ tα»±):Click link tαΊ£i fileMở file bαΊ±ng Notepad β†’ Ctrl+A β†’ Ctrl+CTradingView β†’ Pine Editor β†’ Open β†’ New blank strategyCtrl+A trong editor β†’ Delete β†’ Ctrl+VSave β†’ Add to chartNαΊΏu vαΊ«n bΓ‘o lα»—i, gα»­i mΓ¬nh:TΓͺn file Δ‘ang dΓΉng (clean / multi_timeframe / 15min?)Sα»‘ dΓ²ng + nα»™i dung lα»—i (vΓ­ dα»₯: line 67: Could not find function ...)HoαΊ·c screenshot console phΓ­a dΖ°α»›i Pine EditorMΓ¬nh cαΊ§n thΓ΄ng tin lα»—i cα»₯ thể mα»›i fix chΓ­nh xΓ‘c được.//version=6strategy("Candle Patterns Auto-Detect [10 Patterns + BUY/SELL]", shorttitle = "Candles Auto", overlay = true, initial_capital = 10000, default_qty_type = strategy.percent_of_equity, default_qty_value = 10, pyramiding = 0, max_labels_count = 500, max_lines_count = 200)// ╔══════════════════════════════════════════════════════════════════════╗// β•‘ Tα»° ĐỘNG NHαΊ¬N DIỆN 10 MαΊͺU NαΊΎN + TRIGGER BUY/SELL β•‘// β•‘ Rule: SL = Δ‘Γ‘y/đỉnh nαΊΏn tΓ­n hiệu Β± 0.2Γ—ATR | TP = R:R 1:2 β•‘// β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•// ════════════════════════════════════════════════════════════════════════// INPUTS// ════════════════════════════════════════════════════════════════════════g_p = "β˜… Pattern Toggles"useHam = input.bool(true, "Hammer (BUY)", group=g_p, inline="r1")useStar = input.bool(true, "Shooting Star (SELL)", group=g_p, inline="r1")useBE = input.bool(true, "Bullish Engulfing (BUY)", group=g_p, inline="r2")useSE = input.bool(true, "Bearish Engulfing(SELL)", group=g_p, inline="r2")useMS = input.bool(true, "Morning Star (BUY)", group=g_p, inline="r3")useES = input.bool(true, "Evening Star (SELL)", group=g_p, inline="r3")useBM = input.bool(true, "Bull Marubozu (BUY)", group=g_p, inline="r4")useSM = input.bool(true, "Bear Marubozu(SELL)", group=g_p, inline="r4")use3WS = input.bool(true, "3 White Soldiers (BUY)", group=g_p, inline="r5")use3BC = input.bool(true, "3 Black Crows (SELL)", group=g_p, inline="r5")useIB = input.bool(false,"Inside Bar (Break BUY/SELL)", group=g_p)useDoji = input.bool(false,"Doji (Wait β€” no entry)", group=g_p)g_thr = "β˜… Pattern Thresholds (sα»‘ xαΊ₯p xỉ)"hamWickRatio = input.float(2.0, "Hammer/Star: Wick Γ· Body β‰₯", group=g_thr, step=0.1)hamBodyMaxPct = input.float(30, "Hammer/Star: Body% Max", group=g_thr)maruBodyPct = input.float(80, "Marubozu: Body% Min", group=g_thr)soldierBody = input.float(60, "3 Soldiers/Crows: Body% Min", group=g_thr)dojiMaxPct = input.float(5, "Doji: Body% Max", group=g_thr)starCloseRet = input.float(50, "Morning/Evening Star Retrace %", group=g_thr, tooltip="NαΊΏn 3 phαΊ£i Δ‘Γ³ng cα»­a β‰₯ X% thΓ’n nαΊΏn 1 (ngược chiều)")g_filt = "Filters"useVol = input.bool(true, "Volume Filter β‰₯ NΓ—MA", group=g_filt)volX = input.float(1.5, "Volume Γ— MA", group=g_filt, step=0.1)volLen = input.int(20, "Volume MA Length", group=g_filt)useTrend= input.bool(true, "Trade with EMA200 trend only", group=g_filt, tooltip="BUY chỉ khi giΓ‘ > EMA200, SELL chỉ khi giΓ‘ 0 ? body1 / range1 * 100 : 0isBull = close > openisBear = close open[1]isBear2 = close[1] 0 and volume >= volMA * volX)trendBullOK = not useTrend or close > emaValtrendBearOK = not useTrend or close 0 and dnWick >= hamWickRatio * body1 and upWick 0 and upWick >= hamWickRatio * body1 and dnWick = open[1] and open = body2// 4) BEARISH ENGULFINGisBearEng = useSE and isBear and isBull2 and close = close[1] and body1 >= body2// 5) MORNING STAR (3 nαΊΏn) β€” đỏ lα»›n β†’ small body β†’ xanh lα»›n close β‰₯ 50% nαΊΏn 1isSmall2 = body2 = midpoint1 + body3 * (starCloseRet - 50) / 100// 6) EVENING STARmidpoint1b = (open[2] + close[2]) / 2isEveningStar = useES and isBull[2] and isSmall2 and isBear and close = maruBodyPct and upWick = maruBodyPct and upWick nαΊΏn trΖ°α»›c, body β‰₯ 60%body1Pct = range1 > 0 ? body1 / range1 * 100 : 0body2Pct = range2 > 0 ? body2 / range2 * 100 : 0body3Pct = range3 > 0 ? body3 / range3 * 100 : 0is3Soldiers = use3WS and isBull and isBull[1] and isBull[2] and close > close[1] and close[1] > close[2] and body1Pct >= soldierBody and body2Pct >= soldierBody and body3Pct >= soldierBody// 10) 3 BLACK CROWSis3Crows = use3BC and isBear and isBear[1] and isBear[2] and close = soldierBody and body2Pct >= soldierBody and body3Pct >= soldierBody// BONUS: DOJI (cαΊ£nh bΓ‘o, khΓ΄ng vΓ o lệnh)isDoji = useDoji and bodyPct low[1]ibBuy = useIB and isInside[1] and high > high[1] // break high mαΊΉibSell = useIB and isInside[1] and low = cooldownbuySignal = canFire and buyPattern and trendBullOK and volOKsellSignal = canFire and sellPattern and trendBearOK and volOKif buySignal or sellSignal lastSig := bar_index// Pattern name (for display)patternName = isHammer ? "Hammer" : isBullEng ? "Bull Engulf" : isMorningStar ? "Morning Star" : isBullMaru ? "Bull Marubozu" : is3Soldiers ? "3 White Soldiers" : ibBuy ? "Inside Bar Break↑" : isShoot ? "Shooting Star" : isBearEng ? "Bear Engulf" : isEveningStar ? "Evening Star" : isBearMaru ? "Bear Marubozu" : is3Crows ? "3 Black Crows" : ibSell ? "Inside Bar Break↓" : isDoji ? "Doji (wait)" : ""// ════════════════════════════════════════════════════════════════════════// ENTRY / TP / SL// ════════════════════════════════════════════════════════════════════════// Entry = close (vΓ o tαΊ‘i close nαΊΏn tΓ­n hiệu hoαΊ·c vượt high/low theo rule)longEntry = closeshortEntry = close// SL = Δ‘Γ‘y/đỉnh nαΊΏn tΓ­n hiệu Β± bufferlongSL = low - atr * slBufshortSL = high + atr * slBuf// TP = R:RlongRisk = longEntry - longSLshortRisk = shortSL - shortEntrylongTP = longEntry + longRisk * rrTarshortTP = shortEntry - shortRisk * rrTarlongTPpct = longEntry > 0 ? (longTP - longEntry) / longEntry * 100 : 0longSLpct = longEntry > 0 ? (longSL - longEntry) / longEntry * 100 : 0shortTPpct = shortEntry > 0 ? (shortEntry - shortTP) / shortEntry * 100 : 0shortSLpct = shortEntry > 0 ? (shortSL - shortEntry) / shortEntry * 100 : 0// ════════════════════════════════════════════════════════════════════════// PLOTS// ════════════════════════════════════════════════════════════════════════plot(useTrend ? emaVal : na, "EMA200", color=color.new(color.orange, 40), linewidth=2)// Pattern labelsif showLbl and patternName != "" bool isBuy = buyPattern label.new(bar_index, isBuy ? low : high, text=patternName, style=isBuy ? label.style_label_up : label.style_label_down, color=isBuy ? color.new(color.green, 20) : color.new(color.red, 20), textcolor=color.white, size=size.small)// BUY/SELL big arrowsplotshape(buySignal, "BUY", shape.labelup, location.belowbar, color=color.green, text="BUY", textcolor=color.white, size=size.normal)plotshape(sellSignal, "SELL", shape.labeldown, location.abovebar, color=color.red, text="SELL", textcolor=color.white, size=size.normal)// Entry/TP/SL linesvar line ln_e = navar line ln_t = navar line ln_s = navar label lb_e = navar label lb_t = navar label lb_s = naif showLevels and (buySignal or sellSignal) line.delete(ln_e) line.delete(ln_t) line.delete(ln_s) label.delete(lb_e) label.delete(lb_t) label.delete(lb_s) float ePr = buySignal ? longEntry : shortEntry float tPr = buySignal ? longTP : shortTP float sPr = buySignal ? longSL : shortSL float pT = buySignal ? longTPpct : shortTPpct float pS = buySignal ? longSLpct : shortSLpct string dir = buySignal ? "BUY" : "SELL" int x2 = bar_index + 30 ln_e := line.new(bar_index, ePr, x2, ePr, color=color.yellow, width=2, extend=extend.right) ln_t := line.new(bar_index, tPr, x2, tPr, color=color.green, width=2, extend=extend.right, style=line.style_dashed) ln_s := line.new(bar_index, sPr, x2, sPr, color=color.red, width=2, extend=extend.right, style=line.style_dashed) lb_e := label.new(x2, ePr, dir + " " + str.tostring(ePr, format.mintick), style=label.style_label_left, color=color.yellow, textcolor=color.black, size=size.small) lb_t := label.new(x2, tPr, "TP " + str.tostring(tPr, format.mintick) + " (" + str.tostring(pT, "#.##") + "%)", style=label.style_label_left, color=color.green, textcolor=color.white, size=size.small) lb_s := label.new(x2, sPr, "SL " + str.tostring(sPr, format.mintick) + " (" + str.tostring(pS, "#.##") + "%)", style=label.style_label_left, color=color.red, textcolor=color.white, size=size.small)// ════════════════════════════════════════════════════════════════════════// PATTERN PANEL// ════════════════════════════════════════════════════════════════════════var table panel = table.new(position.top_right, 2, 14, bgcolor=color.new(color.black, 70), border_color=color.gray, border_width=1)if showPanel and barstate.islast table.cell(panel, 0, 0, "β˜… PATTERN STATUS", text_color=color.yellow, bgcolor=color.new(color.purple, 50)) table.cell(panel, 1, 0, "βœ“/βœ—", text_color=color.yellow, bgcolor=color.new(color.purple, 50)) table.cell(panel, 0, 1, "Hammer", text_color=color.white) table.cell(panel, 1, 1, isHammer ? "🟒 BUY" : "β€”", text_color=isHammer ? color.green : color.gray) table.cell(panel, 0, 2, "Shooting Star", text_color=color.white) table.cell(panel, 1, 2, isShoot ? "πŸ”΄ SELL": "β€”", text_color=isShoot ? color.red : color.gray) table.cell(panel, 0, 3, "Bull Engulfing", text_color=color.white) table.cell(panel, 1, 3, isBullEng ? "🟒 BUY": "β€”", text_color=isBullEng ? color.green : color.gray) table.cell(panel, 0, 4, "Bear Engulfing", text_color=color.white) table.cell(panel, 1, 4, isBearEng ? "πŸ”΄ SELL":"β€”", text_color=isBearEng ? color.red : color.gray) table.cell(panel, 0, 5, "Morning Star", text_color=color.white) table.cell(panel, 1, 5, isMorningStar ? "🟒 BUY":"β€”", text_color=isMorningStar ? color.green : color.gray) table.cell(panel, 0, 6, "Evening Star", text_color=color.white) table.cell(panel, 1, 6, isEveningStar ? "πŸ”΄ SELL":"β€”",text_color=isEveningStar ? color.red : color.gray) table.cell(panel, 0, 7, "Bull Marubozu", text_color=color.white) table.cell(panel, 1, 7, isBullMaru ? "🟒 BUY":"β€”",text_color=isBullMaru ? color.green : color.gray) table.cell(panel, 0, 8, "Bear Marubozu", text_color=color.white) table.cell(panel, 1, 8, isBearMaru ? "πŸ”΄ SELL":"β€”",text_color=isBearMaru ? color.red : color.gray) table.cell(panel, 0, 9, "3 White Soldiers", text_color=color.white) table.cell(panel, 1, 9, is3Soldiers ? "🟒 BUY":"β€”",text_color=is3Soldiers ? color.green : color.gray) table.cell(panel, 0, 10, "3 Black Crows", text_color=color.white) table.cell(panel, 1, 10, is3Crows ? "πŸ”΄ SELL":"β€”",text_color=is3Crows ? color.red : color.gray) table.cell(panel, 0, 11, "Doji", text_color=color.white) table.cell(panel, 1, 11, isDoji ? "⏸ WAIT":"β€”",text_color=isDoji ? color.yellow : color.gray) table.cell(panel, 0, 12, "Body%", text_color=color.white) table.cell(panel, 1, 12, str.tostring(bodyPct,"#.#") + "%", text_color=color.aqua) table.cell(panel, 0, 13, "VolumeΓ—MA", text_color=color.white) table.cell(panel, 1, 13, str.tostring(volMA > 0 ? volume/volMA : 0,"#.##") + "Γ—", text_color=volOK ? color.green : color.red)// ════════════════════════════════════════════════════════════════════════// TRADE PANEL// ════════════════════════════════════════════════════════════════════════var table tp = table.new(position.bottom_right, 3, 8, bgcolor=color.new(color.black, 70), border_color=color.gray, border_width=1)if barstate.islast string dir = buySignal ? "🟒 BUY" : sellSignal ? "πŸ”΄ SELL" : "⏸ WAIT" color dCol = buySignal ? color.green : sellSignal ? color.red : color.gray float ePr = buySignal ? longEntry : sellSignal ? shortEntry : close float tPr = buySignal ? longTP : sellSignal ? shortTP : na float sPr = buySignal ? longSL : sellSignal ? shortSL : na float pT = buySignal ? longTPpct : sellSignal ? shortTPpct : na float pS = buySignal ? longSLpct : sellSignal ? shortSLpct : na table.cell(tp, 0, 0, "TRADE PANEL", text_color=color.yellow, bgcolor=color.new(color.purple,50)) table.cell(tp, 1, 0, "VALUE", text_color=color.yellow, bgcolor=color.new(color.purple,50)) table.cell(tp, 2, 0, "%", text_color=color.yellow, bgcolor=color.new(color.purple,50)) table.cell(tp, 0, 1, "Pattern", text_color=color.white) table.cell(tp, 1, 1, patternName == "" ? "β€”" : patternName, text_color=color.aqua) table.cell(tp, 2, 1, "Detected", text_color=color.gray) table.cell(tp, 0, 2, "Direction", text_color=color.white) table.cell(tp, 1, 2, dir, text_color=dCol) table.cell(tp, 2, 2, "R:R " + str.tostring(rrTar,"#.#"),text_color=color.white) table.cell(tp, 0, 3, "Entry", text_color=color.white) table.cell(tp, 1, 3, str.tostring(ePr, format.mintick),text_color=color.yellow) table.cell(tp, 2, 3, "Market", text_color=color.gray) table.cell(tp, 0, 4, "🎯 TP", text_color=color.white) table.cell(tp, 1, 4, na(tPr) ? "β€”" : str.tostring(tPr, format.mintick), text_color=color.green) table.cell(tp, 2, 4, na(pT) ? "β€”" : str.tostring(pT,"#.##") + "% ↑", text_color=color.green) table.cell(tp, 0, 5, "πŸ›‘ SL", text_color=color.white) table.cell(tp, 1, 5, na(sPr) ? "β€”" : str.tostring(sPr, format.mintick), text_color=color.red) table.cell(tp, 2, 5, na(pS) ? "β€”" : str.tostring(pS,"#.##") + "% ↓", text_color=color.red) table.cell(tp, 0, 6, "ATR", text_color=color.white) table.cell(tp, 1, 6, str.tostring(atr, "#.####"), text_color=color.aqua) table.cell(tp, 2, 6, "Γ— " + str.tostring(slBuf,"#.#") + " buf",text_color=color.gray) table.cell(tp, 0, 7, "Current", text_color=color.white) table.cell(tp, 1, 7, str.tostring(close, format.mintick), text_color=color.aqua) table.cell(tp, 2, 7, "Live", text_color=color.gray)// ════════════════════════════════════════════════════════════════════════// STRATEGY ENTRIES// ════════════════════════════════════════════════════════════════════════if buySignal strategy.entry("Long", strategy.long) strategy.exit("Long Exit", "Long", stop=longSL, limit=longTP)if sellSignal strategy.entry("Short", strategy.short) strategy.exit("Short Exit", "Short", stop=shortSL, limit=shortTP)// ════════════════════════════════════════════════════════════════════════// ALERTS// ════════════════════════════════════════════════════════════════════════alertcondition(buySignal, "BUY Pattern", 'BUY {{ticker}} {{interval}} @ {{close}} β€” pattern detected')alertcondition(sellSignal, "SELL Pattern", 'SELL {{ticker}} {{interval}} @ {{close}} β€” pattern detected')Show moreYou said: bao loi sua laibao loi sua laiClaude responded: BαΊ‘n Δ‘ang paste lαΊ‘i file cΕ© (candlepatternsauto.BαΊ‘n Δ‘ang paste lαΊ‘i file cΕ© (candle_patterns_auto.pine) β€” file nΓ y cΓ³ vαΊ₯n đề ở vΓ i chα»—. MΓ¬nh Δ‘Γ£ tαΊ‘o bαΊ£n sα»­a rα»“i (candle_patterns_clean.pine), bαΊ‘n dΓΉng bαΊ£n Δ‘Γ³ nhΓ©:πŸ“₯ candle_patterns_clean.pine β€” BαΊ£n Δ‘Γ£ FIX, dΓΉng cΓ‘i nΓ y3 lα»—i cα»₯ thể trong file cΕ© bαΊ‘n vα»«a paste:Lα»—i 1 (dΓ²ng ~155): Khai bΓ‘o local bool trong if-block khΓ΄ng an toΓ npine// CΕ¨ (lα»—i):if showLbl and patternName != "" bool isBuy = buyPattern ← Pine v6 khΓ΄ng cho redefine biαΊΏn trong scope nΓ y label.new(bar_index, isBuy ? low : high, ...)β†’ BαΊ£n clean: tΓ‘ch labelBuy = buyPat and patName != "" ra global scope, khΓ΄ng khai bΓ‘o trong if.Lα»—i 2 (dΓ²ng ~110-115): isBull[2] vΓ  isBear[2] β€” truy cαΊ­p historical value cα»§a biαΊΏn bool dαΊ«n xuαΊ₯tpine// CΕ¨ (Pine v6 khΓ΄ng Ζ°a):isMorningStar = useMS and isBear[2] and ...is3Soldiers = use3WS and isBull and isBull[1] and isBull[2] and ...β†’ BαΊ£n clean: Δ‘α»‹nh nghΔ©a rΓ΅ rΓ ng bull2 = close[2] > open[2] vΓ  bear2 = close[2] = midpoint1 + body3 * (starCloseRet - 50) / 100β†’ BαΊ£n clean: Δ‘Ζ‘n giαΊ£n hΓ³a thΓ nh close >= mid2 (chuαΊ©n theo Δ‘α»‹nh nghΔ©a Morning Star).TΓ³m lαΊ‘i: Đừng dΓΉng file cΕ© (candle_patterns_auto.pine) nα»―a. TαΊ£i vΓ  dΓΉng candle_patterns_clean.pine ở link bΓͺn trΓͺn β€” Δ‘Γ£ loαΊ‘i cΓ‘c phαΊ§n lα»—i.NαΊΏu file clean vαΊ«n bΓ‘o lα»—i khi compile, bαΊ‘n copy nguyΓͺn dΓ²ng bΓ‘o lα»—i (cΓ³ chα»― "line XX" hoαΊ·c "Error at...") gα»­i mΓ¬nh, mΓ¬nh fix chΓ­nh xΓ‘c trong 1 phΓΊt.Opus uses your limit faster. Try another model for longer conversations.AskOpus 4.7

Browse all 5,900+ TradingView Pine Script strategies

View on TradingView