OPEN-SOURCE SCRIPT
ema20+60+200

// version=5
indicator("Engineer's System: Clean EMA 20 Cross", overlay=true)
// ==========================================
// 1. SETTINGS
// ==========================================
group_ma = "Moving Averages"
maLength = input.int(20, title="Main MA (EMA 20)", group=group_ma)
// ลบ Input EMA 9 ออกแล้ว
ema13Length = input.int(13, title="Short MA (EMA 13)", group=group_ma)
ema60Length = input.int(60, title="Trend MA (EMA 60)", group=group_ma)
ema200Length = input.int(200, title="Filter MA (EMA 200)", group=group_ma)
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
// ลบการคำนวณ EMA 9 ออกแล้ว
ema13Val = ta.ema(close, ema13Length) // EMA 13
ema60Val = ta.ema(close, ema60Length) // EMA 60
ema200Val = ta.ema(close, ema200Length) // EMA 200
// --- Logic สีของเส้น ---
// 1. EMA 200 (Traffic Light)
bool isBullishTrend = ema60Val > ema200Val
color trendColor = isBullishTrend ? color.lime : color.red
// 2. EMA 20 (เปลี่ยนสีตามราคา)
// ถ้า ราคาปิด > EMA 20 เป็นสีฟ้า, ถ้าต่ำกว่าเป็นสีม่วง
bool isPriceAboveMA20 = close >= maVal
color ema20Color = isPriceAboveMA20 ? color.aqua : color.purple
// --- 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 EMA 200
plot(ema200Val, title="EMA 200 Traffic", color=trendColor, linewidth=3)
// Plot EMA 60 & 13
plot(ema60Val, title="EMA 60", color=color.blue, linewidth=2)
plot(ema13Val, title="EMA 13", color=color.aqua, linewidth=1)
// --- EMA 20 (พระเอก: เส้นหนา เปลี่ยนสี) ---
plot(maVal, title="EMA 20", color=ema20Color, linewidth=3)
// *** ลบการแสดงผล EMA 9 และ Cloud ออกทั้งหมดแล้ว ***
// ==========================================
// 4. SIGNALS
// ==========================================
// สัญญาณหลัก (Price Cross EMA 20)
trendBuy = ta.crossover(close, maVal) // ราคาปิด ตัดขึ้น EMA 20
trendSell = ta.crossunder(close, maVal) // ราคาปิด ตัดลง EMA 20
plotshape(trendBuy, title="Trend Buy", style=shape.labelup, location=location.belowbar, color=color.lime, text="BUY", textcolor=color.white, size=size.tiny)
plotshape(trendSell, title="Trend Sell", style=shape.labeldown, location=location.abovebar, color=color.red, text="SELL", textcolor=color.white, size=size.tiny)
// UT Bot Signals
plotshape(utBuy, title="UT Bot Buy Dot", style=shape.circle, location=location.belowbar, color=color.lime, size=size.tiny)
plotshape(utSell, title="UT Bot Sell Dot", style=shape.circle, location=location.abovebar, color=color.red, size=size.tiny)
// ==========================================
// 5. ALERTS
// ==========================================
alertcondition(trendBuy, title="Buy Signal", message="Engineer System: BUY (Close > EMA 20) 🚀")
alertcondition(trendSell, title="Sell Signal", message="Engineer System: SELL (Close < EMA 20) 🔻")
alertcondition(utBuy, title="UT Bot Buy Dot", message="UT Bot: BUY Signal 🟢")
alertcondition(utSell, title="UT Bot Sell Dot", message="UT Bot: SELL Signal 🔴")
alertcondition(isBullishTrend and not isBullishTrend[1], title="Trend 200 Bullish", message="Trend Change: EMA 60 Cross Above EMA 200 🟢")
alertcondition(not isBullishTrend and isBullishTrend[1], title="Trend 200 Bearish", message="Trend Change: EMA 60 Cross Below EMA 200 🔴")
indicator("Engineer's System: Clean EMA 20 Cross", overlay=true)
// ==========================================
// 1. SETTINGS
// ==========================================
group_ma = "Moving Averages"
maLength = input.int(20, title="Main MA (EMA 20)", group=group_ma)
// ลบ Input EMA 9 ออกแล้ว
ema13Length = input.int(13, title="Short MA (EMA 13)", group=group_ma)
ema60Length = input.int(60, title="Trend MA (EMA 60)", group=group_ma)
ema200Length = input.int(200, title="Filter MA (EMA 200)", group=group_ma)
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
// ลบการคำนวณ EMA 9 ออกแล้ว
ema13Val = ta.ema(close, ema13Length) // EMA 13
ema60Val = ta.ema(close, ema60Length) // EMA 60
ema200Val = ta.ema(close, ema200Length) // EMA 200
// --- Logic สีของเส้น ---
// 1. EMA 200 (Traffic Light)
bool isBullishTrend = ema60Val > ema200Val
color trendColor = isBullishTrend ? color.lime : color.red
// 2. EMA 20 (เปลี่ยนสีตามราคา)
// ถ้า ราคาปิด > EMA 20 เป็นสีฟ้า, ถ้าต่ำกว่าเป็นสีม่วง
bool isPriceAboveMA20 = close >= maVal
color ema20Color = isPriceAboveMA20 ? color.aqua : color.purple
// --- 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 EMA 200
plot(ema200Val, title="EMA 200 Traffic", color=trendColor, linewidth=3)
// Plot EMA 60 & 13
plot(ema60Val, title="EMA 60", color=color.blue, linewidth=2)
plot(ema13Val, title="EMA 13", color=color.aqua, linewidth=1)
// --- EMA 20 (พระเอก: เส้นหนา เปลี่ยนสี) ---
plot(maVal, title="EMA 20", color=ema20Color, linewidth=3)
// *** ลบการแสดงผล EMA 9 และ Cloud ออกทั้งหมดแล้ว ***
// ==========================================
// 4. SIGNALS
// ==========================================
// สัญญาณหลัก (Price Cross EMA 20)
trendBuy = ta.crossover(close, maVal) // ราคาปิด ตัดขึ้น EMA 20
trendSell = ta.crossunder(close, maVal) // ราคาปิด ตัดลง EMA 20
plotshape(trendBuy, title="Trend Buy", style=shape.labelup, location=location.belowbar, color=color.lime, text="BUY", textcolor=color.white, size=size.tiny)
plotshape(trendSell, title="Trend Sell", style=shape.labeldown, location=location.abovebar, color=color.red, text="SELL", textcolor=color.white, size=size.tiny)
// UT Bot Signals
plotshape(utBuy, title="UT Bot Buy Dot", style=shape.circle, location=location.belowbar, color=color.lime, size=size.tiny)
plotshape(utSell, title="UT Bot Sell Dot", style=shape.circle, location=location.abovebar, color=color.red, size=size.tiny)
// ==========================================
// 5. ALERTS
// ==========================================
alertcondition(trendBuy, title="Buy Signal", message="Engineer System: BUY (Close > EMA 20) 🚀")
alertcondition(trendSell, title="Sell Signal", message="Engineer System: SELL (Close < EMA 20) 🔻")
alertcondition(utBuy, title="UT Bot Buy Dot", message="UT Bot: BUY Signal 🟢")
alertcondition(utSell, title="UT Bot Sell Dot", message="UT Bot: SELL Signal 🔴")
alertcondition(isBullishTrend and not isBullishTrend[1], title="Trend 200 Bullish", message="Trend Change: EMA 60 Cross Above EMA 200 🟢")
alertcondition(not isBullishTrend and isBullishTrend[1], title="Trend 200 Bearish", message="Trend Change: EMA 60 Cross Below EMA 200 🔴")
סקריפט קוד פתוח
ברוח האמיתית של TradingView, יוצר הסקריפט הזה הפך אותו לקוד פתוח, כך שסוחרים יוכלו לעיין בו ולאמת את פעולתו. כל הכבוד למחבר! אמנם ניתן להשתמש בו בחינם, אך זכור כי פרסום חוזר של הקוד כפוף ל־כללי הבית שלנו.
כתב ויתור
המידע והפרסומים אינם מיועדים להיות, ואינם מהווים, ייעוץ או המלצה פיננסית, השקעתית, מסחרית או מכל סוג אחר המסופקת או מאושרת על ידי TradingView. קרא עוד ב־תנאי השימוש.
סקריפט קוד פתוח
ברוח האמיתית של TradingView, יוצר הסקריפט הזה הפך אותו לקוד פתוח, כך שסוחרים יוכלו לעיין בו ולאמת את פעולתו. כל הכבוד למחבר! אמנם ניתן להשתמש בו בחינם, אך זכור כי פרסום חוזר של הקוד כפוף ל־כללי הבית שלנו.
כתב ויתור
המידע והפרסומים אינם מיועדים להיות, ואינם מהווים, ייעוץ או המלצה פיננסית, השקעתית, מסחרית או מכל סוג אחר המסופקת או מאושרת על ידי TradingView. קרא עוד ב־תנאי השימוש.