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) 🔴")
오픈 소스 스크립트
트레이딩뷰의 진정한 정신에 따라, 이 스크립트의 작성자는 이를 오픈소스로 공개하여 트레이더들이 기능을 검토하고 검증할 수 있도록 했습니다. 작성자에게 찬사를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 코드를 재게시하는 경우 하우스 룰이 적용된다는 점을 기억하세요.
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.
오픈 소스 스크립트
트레이딩뷰의 진정한 정신에 따라, 이 스크립트의 작성자는 이를 오픈소스로 공개하여 트레이더들이 기능을 검토하고 검증할 수 있도록 했습니다. 작성자에게 찬사를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 코드를 재게시하는 경우 하우스 룰이 적용된다는 점을 기억하세요.
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.