OPEN-SOURCE SCRIPT
1MTF MACD Alignement XAUUSD - Webhook v6

//version=6
indicator("MTF MACD Alignement XAUUSD - Webhook v6", overlay=false)
// ===== Paramètres utilisateur =====
fast_len = input.int(12, "Fast Length")
slow_len = input.int(26, "Slow Length")
signal_len = input.int(9, "Signal Length")
repl_secret = input.string(title="Webhook secret (doit matcher WEBHOOK_SECRET)", defval="Covid-192020")
// ===== Fonction MACD histogramme =====
f_macd_hist(src) =>
macd = ta.ema(src, fast_len) - ta.ema(src, slow_len)
signal = ta.ema(macd, signal_len)
hist = macd - signal
hist
// ===== Récupération multi-timeframe =====
hist4h = request.security(syminfo.tickerid, "240", f_macd_hist(close), lookahead=barmerge.lookahead_off)
hist1h = request.security(syminfo.tickerid, "60", f_macd_hist(close), lookahead=barmerge.lookahead_off)
hist15m = request.security(syminfo.tickerid, "15", f_macd_hist(close), lookahead=barmerge.lookahead_off)
hist5m = request.security(syminfo.tickerid, "5", f_macd_hist(close), lookahead=barmerge.lookahead_off)
// ===== Signes de MACD =====
s4 = hist4h > 0 ? 1 : (hist4h < 0 ? -1 : 0)
s1 = hist1h > 0 ? 1 : (hist1h < 0 ? -1 : 0)
s15 = hist15m > 0 ? 1 : (hist15m < 0 ? -1 : 0)
s5 = hist5m > 0 ? 1 : (hist5m < 0 ? -1 : 0)
// ===== Vérification alignement TF supérieurs =====
three_same = (s4 != 0) and (s4 == s1) and (s1 == s15)
// ===== Confirmation 5M =====
five_in_same = three_same and (s5 == s4)
// ===== Préparation du JSON pour webhook =====
signal_type = s4 == 1 ? "BUY" : (s4 == -1 ? "SELL" : "NEUTRAL")
alert_json = '{"secret":"'+repl_secret+'","symbol":"'+syminfo.ticker+'","signal":"'+signal_type+'","time":"'+str.tostring(time, "yyyy-MM-dd HH:mm:ss")+'","aligned":["4H","1H","15M","5M"]}'
// ===== Alertcondition compilable =====
// v6 n’accepte pas message dynamique, donc on met un message fixe
alertcondition(five_in_same and ta.change(five_in_same), title="MACD Align + 5M confirm", message="MACD alignement détecté")
// ===== Affichage optionnel des histogrammes =====
plot(hist4h, title="hist 4H", color=color.new(color.green, 0), linewidth=1)
plot(hist1h, title="hist 1H", color=color.new(color.blue, 0), linewidth=1)
plot(hist15m, title="hist 15M", color=color.new(color.orange, 0), linewidth=1)
plot(hist5m, title="hist 5M", color=color.new(color.purple, 0), linewidth=1)
indicator("MTF MACD Alignement XAUUSD - Webhook v6", overlay=false)
// ===== Paramètres utilisateur =====
fast_len = input.int(12, "Fast Length")
slow_len = input.int(26, "Slow Length")
signal_len = input.int(9, "Signal Length")
repl_secret = input.string(title="Webhook secret (doit matcher WEBHOOK_SECRET)", defval="Covid-192020")
// ===== Fonction MACD histogramme =====
f_macd_hist(src) =>
macd = ta.ema(src, fast_len) - ta.ema(src, slow_len)
signal = ta.ema(macd, signal_len)
hist = macd - signal
hist
// ===== Récupération multi-timeframe =====
hist4h = request.security(syminfo.tickerid, "240", f_macd_hist(close), lookahead=barmerge.lookahead_off)
hist1h = request.security(syminfo.tickerid, "60", f_macd_hist(close), lookahead=barmerge.lookahead_off)
hist15m = request.security(syminfo.tickerid, "15", f_macd_hist(close), lookahead=barmerge.lookahead_off)
hist5m = request.security(syminfo.tickerid, "5", f_macd_hist(close), lookahead=barmerge.lookahead_off)
// ===== Signes de MACD =====
s4 = hist4h > 0 ? 1 : (hist4h < 0 ? -1 : 0)
s1 = hist1h > 0 ? 1 : (hist1h < 0 ? -1 : 0)
s15 = hist15m > 0 ? 1 : (hist15m < 0 ? -1 : 0)
s5 = hist5m > 0 ? 1 : (hist5m < 0 ? -1 : 0)
// ===== Vérification alignement TF supérieurs =====
three_same = (s4 != 0) and (s4 == s1) and (s1 == s15)
// ===== Confirmation 5M =====
five_in_same = three_same and (s5 == s4)
// ===== Préparation du JSON pour webhook =====
signal_type = s4 == 1 ? "BUY" : (s4 == -1 ? "SELL" : "NEUTRAL")
alert_json = '{"secret":"'+repl_secret+'","symbol":"'+syminfo.ticker+'","signal":"'+signal_type+'","time":"'+str.tostring(time, "yyyy-MM-dd HH:mm:ss")+'","aligned":["4H","1H","15M","5M"]}'
// ===== Alertcondition compilable =====
// v6 n’accepte pas message dynamique, donc on met un message fixe
alertcondition(five_in_same and ta.change(five_in_same), title="MACD Align + 5M confirm", message="MACD alignement détecté")
// ===== Affichage optionnel des histogrammes =====
plot(hist4h, title="hist 4H", color=color.new(color.green, 0), linewidth=1)
plot(hist1h, title="hist 1H", color=color.new(color.blue, 0), linewidth=1)
plot(hist15m, title="hist 15M", color=color.new(color.orange, 0), linewidth=1)
plot(hist5m, title="hist 5M", color=color.new(color.purple, 0), linewidth=1)
สคริปต์โอเพนซอร์ซ
ด้วยเจตนารมณ์หลักของ TradingView ผู้สร้างสคริปต์นี้ได้ทำให้เป็นโอเพนซอร์ส เพื่อให้เทรดเดอร์สามารถตรวจสอบและยืนยันฟังก์ชันการทำงานของมันได้ ขอชื่นชมผู้เขียน! แม้ว่าคุณจะใช้งานได้ฟรี แต่โปรดจำไว้ว่าการเผยแพร่โค้ดซ้ำจะต้องเป็นไปตาม กฎระเบียบการใช้งาน ของเรา
คำจำกัดสิทธิ์ความรับผิดชอบ
ข้อมูลและบทความไม่ได้มีวัตถุประสงค์เพื่อก่อให้เกิดกิจกรรมทางการเงิน, การลงทุน, การซื้อขาย, ข้อเสนอแนะ หรือคำแนะนำประเภทอื่น ๆ ที่ให้หรือรับรองโดย TradingView อ่านเพิ่มเติมใน ข้อกำหนดการใช้งาน
สคริปต์โอเพนซอร์ซ
ด้วยเจตนารมณ์หลักของ TradingView ผู้สร้างสคริปต์นี้ได้ทำให้เป็นโอเพนซอร์ส เพื่อให้เทรดเดอร์สามารถตรวจสอบและยืนยันฟังก์ชันการทำงานของมันได้ ขอชื่นชมผู้เขียน! แม้ว่าคุณจะใช้งานได้ฟรี แต่โปรดจำไว้ว่าการเผยแพร่โค้ดซ้ำจะต้องเป็นไปตาม กฎระเบียบการใช้งาน ของเรา
คำจำกัดสิทธิ์ความรับผิดชอบ
ข้อมูลและบทความไม่ได้มีวัตถุประสงค์เพื่อก่อให้เกิดกิจกรรมทางการเงิน, การลงทุน, การซื้อขาย, ข้อเสนอแนะ หรือคำแนะนำประเภทอื่น ๆ ที่ให้หรือรับรองโดย TradingView อ่านเพิ่มเติมใน ข้อกำหนดการใช้งาน