OPEN-SOURCE SCRIPT
HalfTrend Adaptive Pro v3

half trend version 3.1//version=6
indicator("Candlestick Recognizer v1 (Praveen Edition)", overlay=true, max_labels_count=500)
// ──────────────────────────────
// Inputs: toggles & thresholds
// ──────────────────────────────
grpUse = "Enable Patterns"
useEngulf = input.bool(true, "Engulfing (Bull/Bear)", group=grpUse)
usePiercing = input.bool(true, "Piercing Line / Dark Cloud", group=grpUse)
useMarubozu = input.bool(true, "Marubozu (Bull/Bear)", group=grpUse)
useHammers = input.bool(true, "Hammer / Hanging Man", group=grpUse)
useInverted = input.bool(true, "Inverted Hammer / Shooting Star", group=grpUse)
useDoji = input.bool(true, "Doji", group=grpUse)
useStars = input.bool(true, "Morning/Evening Star", group=grpUse)
useThree = input.bool(true, "Three Soldiers / Three Crows", group=grpUse)
grpThr = "Thresholds"
minBodyPct = input.float(0.6, "Min Body vs Range (0-1) for 'strong body'", step=0.05, group=grpThr)
maxDojiBodyPct = input.float(0.1, "Max Body vs Range (0-1) for Doji", step=0.02, group=grpThr)
minEngulfFactor = input.float(1.02, "Engulf body size factor", step=0.01, group=grpThr)
wickRatioHammer = input.float(2.0, "Hammer lower wick ≥ body ×", step=0.1, group=grpThr)
wickRatioShooting = input.float(2.0, "Shooting Star upper wick ≥ body ×", step=0.1, group=grpThr)
gapTolerance = input.float(0.15, "Star gap tolerance as % of ATR", step=0.01, group=grpThr)
grpVis = "Visuals"
showLabels = input.bool(true, "Show Labels", group=grpVis)
labelSize = input.string("normal", "Label Size", options=["tiny","small","normal","large","huge"], group=grpVis)
onlyConfirmed = input.bool(true, "Only on bar close (confirmed)", group=grpVis)
// Colors
bullCol = color.new(color.green, 0)
bearCol = color.new(color.red, 0)
warnCol = color.new(color.yellow, 0)
textCol = color.black
// Helper to gate by confirmation
confirmed = onlyConfirmed ? barstate.isconfirmed : true
// ──────────────────────────────
// Candle math helpers
// ──────────────────────────────
body(o, c) => math.abs(c - o)
range(h, l) => h - l
isBull(o, c) => c > o
isBear(o, c) => c < o
upperW(h, o, c) => h - math.max(o, c)
lowerW(l, o, c) => math.min(o, c) - l
safeDiv(x, y) => y == 0.0 ? 0.0 : x / y
// Current and previous (p1, p2)
o = open, c = close, h = high, l = low
o1 = open[1], c1 = close[1], h1 = high[1], l1 = low[1]
o2 = open[2], c2 = close[2], h2 = high[2], l2 = low[2]
b = body(o, c)
r = range(h, l)
ub = upperW(h, o, c)
lb = lowerW(l, o, c)
b1 = body(o1, c1)
r1 = range(h1, l1)
b2 = body(o2, c2)
r2 = range(h2, l2)
bull = isBull(o, c)
bear = isBear(o, c)
bull1 = isBull(o1, c1)
bear1 = isBear(o1, c1)
bull2 = isBull(o2, c2)
bear2 = isBear(o2, c2)
bodyVsRange = safeDiv(b, r)
bodyVsRange1 = safeDiv(b1, r1)
bodyVsRange2 = safeDiv(b2, r2)
atr = ta.atr(14)
// ──────────────────────────────
/* Pattern logic */
// ──────────────────────────────
// 1) Engulfing
bullEngulf = useEngulf and confirmed and bear1 and bull and (b >= b1 * minEngulfFactor) and (o <= c1) and (c >= o1)
bearEngulf = useEngulf and confirmed and bull1 and bear and (b >= b1 * minEngulfFactor) and (o >= c1) and (c <= o1)
// 2) Piercing Line / Dark Cloud Cover
piercing = usePiercing and confirmed and bear1 and bull and c > (o1 + c1)/2 and o <= l1 + (h1 - l1)*0.25 // open near/below prior low, close into upper half
darkCloud = usePiercing and confirmed and bull1 and bear and c < (o1 + c1)/2 and o >= h1 - (h1 - l1)*0.25 // open near/above prior high, close into lower half
// 3) Marubozu (strong body, tiny wicks)
maruBull = useMarubozu and confirmed and bull and bodyVsRange >= minBodyPct and ub <= b * 0.1 and lb <= b * 0.1
maruBear = useMarubozu and confirmed and bear and bodyVsRange >= minBodyPct and ub <= b * 0.1 and lb <= b * 0.1
// 4) Hammer / Hanging Man (small body, long lower wick)
hammer = useHammers and confirmed and bull and lb >= b * wickRatioHammer and ub <= b * 0.5
hangingMan = useHammers and confirmed and bear and lb >= b * wickRatioHammer and ub <= b * 0.5
// 5) Inverted Hammer / Shooting Star (small body, long upper wick)
invHammer = useInverted and confirmed and bull and ub >= b * wickRatioShooting and lb <= b * 0.5
shootingStar = useInverted and confirmed and bear and ub >= b * wickRatioShooting and lb <= b * 0.5
// 6) Doji
doji = useDoji and confirmed and bodyVsRange <= maxDojiBodyPct
// 7) Morning Star
indicator("Candlestick Recognizer v1 (Praveen Edition)", overlay=true, max_labels_count=500)
// ──────────────────────────────
// Inputs: toggles & thresholds
// ──────────────────────────────
grpUse = "Enable Patterns"
useEngulf = input.bool(true, "Engulfing (Bull/Bear)", group=grpUse)
usePiercing = input.bool(true, "Piercing Line / Dark Cloud", group=grpUse)
useMarubozu = input.bool(true, "Marubozu (Bull/Bear)", group=grpUse)
useHammers = input.bool(true, "Hammer / Hanging Man", group=grpUse)
useInverted = input.bool(true, "Inverted Hammer / Shooting Star", group=grpUse)
useDoji = input.bool(true, "Doji", group=grpUse)
useStars = input.bool(true, "Morning/Evening Star", group=grpUse)
useThree = input.bool(true, "Three Soldiers / Three Crows", group=grpUse)
grpThr = "Thresholds"
minBodyPct = input.float(0.6, "Min Body vs Range (0-1) for 'strong body'", step=0.05, group=grpThr)
maxDojiBodyPct = input.float(0.1, "Max Body vs Range (0-1) for Doji", step=0.02, group=grpThr)
minEngulfFactor = input.float(1.02, "Engulf body size factor", step=0.01, group=grpThr)
wickRatioHammer = input.float(2.0, "Hammer lower wick ≥ body ×", step=0.1, group=grpThr)
wickRatioShooting = input.float(2.0, "Shooting Star upper wick ≥ body ×", step=0.1, group=grpThr)
gapTolerance = input.float(0.15, "Star gap tolerance as % of ATR", step=0.01, group=grpThr)
grpVis = "Visuals"
showLabels = input.bool(true, "Show Labels", group=grpVis)
labelSize = input.string("normal", "Label Size", options=["tiny","small","normal","large","huge"], group=grpVis)
onlyConfirmed = input.bool(true, "Only on bar close (confirmed)", group=grpVis)
// Colors
bullCol = color.new(color.green, 0)
bearCol = color.new(color.red, 0)
warnCol = color.new(color.yellow, 0)
textCol = color.black
// Helper to gate by confirmation
confirmed = onlyConfirmed ? barstate.isconfirmed : true
// ──────────────────────────────
// Candle math helpers
// ──────────────────────────────
body(o, c) => math.abs(c - o)
range(h, l) => h - l
isBull(o, c) => c > o
isBear(o, c) => c < o
upperW(h, o, c) => h - math.max(o, c)
lowerW(l, o, c) => math.min(o, c) - l
safeDiv(x, y) => y == 0.0 ? 0.0 : x / y
// Current and previous (p1, p2)
o = open, c = close, h = high, l = low
o1 = open[1], c1 = close[1], h1 = high[1], l1 = low[1]
o2 = open[2], c2 = close[2], h2 = high[2], l2 = low[2]
b = body(o, c)
r = range(h, l)
ub = upperW(h, o, c)
lb = lowerW(l, o, c)
b1 = body(o1, c1)
r1 = range(h1, l1)
b2 = body(o2, c2)
r2 = range(h2, l2)
bull = isBull(o, c)
bear = isBear(o, c)
bull1 = isBull(o1, c1)
bear1 = isBear(o1, c1)
bull2 = isBull(o2, c2)
bear2 = isBear(o2, c2)
bodyVsRange = safeDiv(b, r)
bodyVsRange1 = safeDiv(b1, r1)
bodyVsRange2 = safeDiv(b2, r2)
atr = ta.atr(14)
// ──────────────────────────────
/* Pattern logic */
// ──────────────────────────────
// 1) Engulfing
bullEngulf = useEngulf and confirmed and bear1 and bull and (b >= b1 * minEngulfFactor) and (o <= c1) and (c >= o1)
bearEngulf = useEngulf and confirmed and bull1 and bear and (b >= b1 * minEngulfFactor) and (o >= c1) and (c <= o1)
// 2) Piercing Line / Dark Cloud Cover
piercing = usePiercing and confirmed and bear1 and bull and c > (o1 + c1)/2 and o <= l1 + (h1 - l1)*0.25 // open near/below prior low, close into upper half
darkCloud = usePiercing and confirmed and bull1 and bear and c < (o1 + c1)/2 and o >= h1 - (h1 - l1)*0.25 // open near/above prior high, close into lower half
// 3) Marubozu (strong body, tiny wicks)
maruBull = useMarubozu and confirmed and bull and bodyVsRange >= minBodyPct and ub <= b * 0.1 and lb <= b * 0.1
maruBear = useMarubozu and confirmed and bear and bodyVsRange >= minBodyPct and ub <= b * 0.1 and lb <= b * 0.1
// 4) Hammer / Hanging Man (small body, long lower wick)
hammer = useHammers and confirmed and bull and lb >= b * wickRatioHammer and ub <= b * 0.5
hangingMan = useHammers and confirmed and bear and lb >= b * wickRatioHammer and ub <= b * 0.5
// 5) Inverted Hammer / Shooting Star (small body, long upper wick)
invHammer = useInverted and confirmed and bull and ub >= b * wickRatioShooting and lb <= b * 0.5
shootingStar = useInverted and confirmed and bear and ub >= b * wickRatioShooting and lb <= b * 0.5
// 6) Doji
doji = useDoji and confirmed and bodyVsRange <= maxDojiBodyPct
// 7) Morning Star
Skrip open-source
Dengan semangat TradingView yang sesungguhnya, penulis skrip ini telah menjadikannya sumber terbuka, sehingga para trader dapat meninjau dan memverifikasi fungsinya. Hormat untuk penulisnya! Meskipun anda dapat menggunakannya secara gratis, ingatlah bahwa penerbitan ulang kode tersebut tunduk pada Tata Tertib kami.
Pernyataan Penyangkalan
Informasi dan publikasi tidak dimaksudkan untuk menjadi, dan bukan merupakan saran keuangan, investasi, perdagangan, atau rekomendasi lainnya yang diberikan atau didukung oleh TradingView. Baca selengkapnya di Persyaratan Penggunaan.
Skrip open-source
Dengan semangat TradingView yang sesungguhnya, penulis skrip ini telah menjadikannya sumber terbuka, sehingga para trader dapat meninjau dan memverifikasi fungsinya. Hormat untuk penulisnya! Meskipun anda dapat menggunakannya secara gratis, ingatlah bahwa penerbitan ulang kode tersebut tunduk pada Tata Tertib kami.
Pernyataan Penyangkalan
Informasi dan publikasi tidak dimaksudkan untuk menjadi, dan bukan merupakan saran keuangan, investasi, perdagangan, atau rekomendasi lainnya yang diberikan atau didukung oleh TradingView. Baca selengkapnya di Persyaratan Penggunaan.