OPEN-SOURCE SCRIPT
Fast Cross (9/20) + EMA 50

// version=5
indicator("Engineer's System: Fast Cross (9/20) + EMA 50", overlay=true)
// ==========================================
// 1. SETTINGS
// ==========================================
group_ma = "Moving Averages"
maLength = input.int(20, title="Main MA (EMA 20)", group=group_ma)
ema9Length = input.int(9, title="Signal MA (EMA 9)", group=group_ma)
ema50Length = input.int(50, title="Trend MA (EMA 50)", group=group_ma)
ema200Length = input.int(200, title="Filter MA (EMA 200)", group=group_ma)
group_macd = "MACD Logic"
fastLen = input.int(12, title="MACD Fast", group=group_macd)
slowLen = input.int(26, title="MACD Slow", group=group_macd)
sigLen = input.int(9, title="MACD Signal", group=group_macd)
group_ut = "UT Bot Settings"
ut_key = input.float(1.0, title="Key Value", step=0.1, group=group_ut)
ut_period = input.int(10, title="ATR Period", group=group_ut)
ut_showLine = input.bool(false, title="Show Trailing Line?", group=group_ut)
// ==========================================
// 2. CALCULATIONS
// ==========================================
maVal = ta.ema(close, maLength) // EMA 20
ema9Val = ta.ema(close, ema9Length) // EMA 9
ema50Val = ta.ema(close, ema50Length) // EMA 50
ema200Val = ta.ema(close, ema200Length) // EMA 200
// MACD for Colors
[macdLine, signalLine, _] = ta.macd(close, fastLen, slowLen, sigLen)
bool isGreenZone = macdLine > signalLine
// UT Bot Logic
xATR = ta.atr(ut_period)
nLoss = ut_key * xATR
src = close
xATRTrailingStop = 0.0
xATRTrailingStop := if src > nz(xATRTrailingStop[1], 0) and src[1] > nz(xATRTrailingStop[1], 0)
math.max(nz(xATRTrailingStop[1]), src - nLoss)
else if src < nz(xATRTrailingStop[1], 0) and src[1] < nz(xATRTrailingStop[1], 0)
math.min(nz(xATRTrailingStop[1]), src + nLoss)
else if src > nz(xATRTrailingStop[1], 0)
src - nLoss
else
src + nLoss
pos = 0
pos := if src[1] < nz(xATRTrailingStop[1], 0) and src > nz(xATRTrailingStop[1], 0)
1
else if src[1] > nz(xATRTrailingStop[1], 0) and src < nz(xATRTrailingStop[1], 0)
-1
else
nz(pos[1], 0)
utBuy = (pos == 1) and (pos[1] == -1)
utSell = (pos == -1) and (pos[1] == 1)
// ==========================================
// 3. PLOTTING
// ==========================================
// Plot Lines
plot(ema200Val, title="EMA 200", color=color.white, linewidth=2)
plot(ema50Val, title="EMA 50", color=color.blue, linewidth=2)
// EMA 9 & 20 with Cloud
color mainColor = isGreenZone ? color.lime : color.red
color ema9Color = ema9Val >= maVal ? color.aqua : color.purple
p_ema20 = plot(maVal, title="EMA 20", color=mainColor, linewidth=3)
p_ema9 = plot(ema9Val, title="EMA 9", color=ema9Color, linewidth=2)
fillColor = ema9Val >= maVal ? color.new(color.aqua, 85) : color.new(color.purple, 85)
fill(p_ema9, p_ema20, color=fillColor, title="Cloud EMA 9-20")
// ==========================================
// 4. SIGNALS (UPDATED)
// ==========================================
// --- สัญญาณหลัก (Fast Cross) ---
// แสดงทันทีที่ 9 ตัด 20 (ไม่ต้องสนเส้น 50)
fastBuy = ta.crossover(ema9Val, maVal)
fastSell = ta.crossunder(ema9Val, maVal)
plotshape(fastBuy, title="Fast Buy", style=shape.labelup, location=location.belowbar, color=color.lime, text="BUY", textcolor=color.white, size=size.tiny)
plotshape(fastSell, title="Fast Sell", style=shape.labeldown, location=location.abovebar, color=color.red, text="SELL", textcolor=color.white, size=size.tiny)
// --- UT Bot Signals (Dots) ---
// ยังคงกรองด้วย EMA 200 เพื่อความปลอดภัย
validBuy = utBuy and (close > ema200Val)
validSell = utSell and (close < ema200Val)
plotshape(validBuy, title="Trend Buy Dot", style=shape.circle, location=location.belowbar, color=color.lime, size=size.tiny)
plotshape(validSell, title="Trend Sell Dot", style=shape.circle, location=location.abovebar, color=color.red, size=size.tiny)
// ==========================================
// 5. ALERTS
// ==========================================
alertcondition(fastBuy, title="Buy Signal", message="Engineer System: BUY (9 Cross 20) 🚀")
alertcondition(fastSell, title="Sell Signal", message="Engineer System: SELL (9 Cross 20) 🔻")
alertcondition(validBuy, title="Trend Buy Dot", message="Trend System: UT Bot BUY (Above EMA 200) 🟢")
alertcondition(validSell, title="Trend Sell Dot", message="Trend System: UT Bot SELL (Below EMA 200) 🔴")
indicator("Engineer's System: Fast Cross (9/20) + EMA 50", overlay=true)
// ==========================================
// 1. SETTINGS
// ==========================================
group_ma = "Moving Averages"
maLength = input.int(20, title="Main MA (EMA 20)", group=group_ma)
ema9Length = input.int(9, title="Signal MA (EMA 9)", group=group_ma)
ema50Length = input.int(50, title="Trend MA (EMA 50)", group=group_ma)
ema200Length = input.int(200, title="Filter MA (EMA 200)", group=group_ma)
group_macd = "MACD Logic"
fastLen = input.int(12, title="MACD Fast", group=group_macd)
slowLen = input.int(26, title="MACD Slow", group=group_macd)
sigLen = input.int(9, title="MACD Signal", group=group_macd)
group_ut = "UT Bot Settings"
ut_key = input.float(1.0, title="Key Value", step=0.1, group=group_ut)
ut_period = input.int(10, title="ATR Period", group=group_ut)
ut_showLine = input.bool(false, title="Show Trailing Line?", group=group_ut)
// ==========================================
// 2. CALCULATIONS
// ==========================================
maVal = ta.ema(close, maLength) // EMA 20
ema9Val = ta.ema(close, ema9Length) // EMA 9
ema50Val = ta.ema(close, ema50Length) // EMA 50
ema200Val = ta.ema(close, ema200Length) // EMA 200
// MACD for Colors
[macdLine, signalLine, _] = ta.macd(close, fastLen, slowLen, sigLen)
bool isGreenZone = macdLine > signalLine
// UT Bot Logic
xATR = ta.atr(ut_period)
nLoss = ut_key * xATR
src = close
xATRTrailingStop = 0.0
xATRTrailingStop := if src > nz(xATRTrailingStop[1], 0) and src[1] > nz(xATRTrailingStop[1], 0)
math.max(nz(xATRTrailingStop[1]), src - nLoss)
else if src < nz(xATRTrailingStop[1], 0) and src[1] < nz(xATRTrailingStop[1], 0)
math.min(nz(xATRTrailingStop[1]), src + nLoss)
else if src > nz(xATRTrailingStop[1], 0)
src - nLoss
else
src + nLoss
pos = 0
pos := if src[1] < nz(xATRTrailingStop[1], 0) and src > nz(xATRTrailingStop[1], 0)
1
else if src[1] > nz(xATRTrailingStop[1], 0) and src < nz(xATRTrailingStop[1], 0)
-1
else
nz(pos[1], 0)
utBuy = (pos == 1) and (pos[1] == -1)
utSell = (pos == -1) and (pos[1] == 1)
// ==========================================
// 3. PLOTTING
// ==========================================
// Plot Lines
plot(ema200Val, title="EMA 200", color=color.white, linewidth=2)
plot(ema50Val, title="EMA 50", color=color.blue, linewidth=2)
// EMA 9 & 20 with Cloud
color mainColor = isGreenZone ? color.lime : color.red
color ema9Color = ema9Val >= maVal ? color.aqua : color.purple
p_ema20 = plot(maVal, title="EMA 20", color=mainColor, linewidth=3)
p_ema9 = plot(ema9Val, title="EMA 9", color=ema9Color, linewidth=2)
fillColor = ema9Val >= maVal ? color.new(color.aqua, 85) : color.new(color.purple, 85)
fill(p_ema9, p_ema20, color=fillColor, title="Cloud EMA 9-20")
// ==========================================
// 4. SIGNALS (UPDATED)
// ==========================================
// --- สัญญาณหลัก (Fast Cross) ---
// แสดงทันทีที่ 9 ตัด 20 (ไม่ต้องสนเส้น 50)
fastBuy = ta.crossover(ema9Val, maVal)
fastSell = ta.crossunder(ema9Val, maVal)
plotshape(fastBuy, title="Fast Buy", style=shape.labelup, location=location.belowbar, color=color.lime, text="BUY", textcolor=color.white, size=size.tiny)
plotshape(fastSell, title="Fast Sell", style=shape.labeldown, location=location.abovebar, color=color.red, text="SELL", textcolor=color.white, size=size.tiny)
// --- UT Bot Signals (Dots) ---
// ยังคงกรองด้วย EMA 200 เพื่อความปลอดภัย
validBuy = utBuy and (close > ema200Val)
validSell = utSell and (close < ema200Val)
plotshape(validBuy, title="Trend Buy Dot", style=shape.circle, location=location.belowbar, color=color.lime, size=size.tiny)
plotshape(validSell, title="Trend Sell Dot", style=shape.circle, location=location.abovebar, color=color.red, size=size.tiny)
// ==========================================
// 5. ALERTS
// ==========================================
alertcondition(fastBuy, title="Buy Signal", message="Engineer System: BUY (9 Cross 20) 🚀")
alertcondition(fastSell, title="Sell Signal", message="Engineer System: SELL (9 Cross 20) 🔻")
alertcondition(validBuy, title="Trend Buy Dot", message="Trend System: UT Bot BUY (Above EMA 200) 🟢")
alertcondition(validSell, title="Trend Sell Dot", message="Trend System: UT Bot SELL (Below EMA 200) 🔴")
Skrip sumber terbuka
Dalam semangat TradingView sebenar, pencipta skrip ini telah menjadikannya sumber terbuka, jadi pedagang boleh menilai dan mengesahkan kefungsiannya. Terima kasih kepada penulis! Walaupuan anda boleh menggunakan secara percuma, ingat bahawa penerbitan semula kod ini tertakluk kepada Peraturan Dalaman.
Penafian
Maklumat dan penerbitan adalah tidak bertujuan, dan tidak membentuk, nasihat atau cadangan kewangan, pelaburan, dagangan atau jenis lain yang diberikan atau disahkan oleh TradingView. Baca lebih dalam Terma Penggunaan.
Skrip sumber terbuka
Dalam semangat TradingView sebenar, pencipta skrip ini telah menjadikannya sumber terbuka, jadi pedagang boleh menilai dan mengesahkan kefungsiannya. Terima kasih kepada penulis! Walaupuan anda boleh menggunakan secara percuma, ingat bahawa penerbitan semula kod ini tertakluk kepada Peraturan Dalaman.
Penafian
Maklumat dan penerbitan adalah tidak bertujuan, dan tidak membentuk, nasihat atau cadangan kewangan, pelaburan, dagangan atau jenis lain yang diberikan atau disahkan oleh TradingView. Baca lebih dalam Terma Penggunaan.