PROTECTED SOURCE SCRIPT
USDT.D MA30 MA200 PRO ULTIME

//version=5
indicator("USDT.D MA30 MA200 PRO ULTIME", shorttitle="USDT.D Pro", overlay=false, max_labels_count=500, max_lines_count=500)
///// PARAMETRES COMPLETS /////
len30 = input.int(30, "MA30 Periode", minval=1, maxval=500)
len200 = input.int(200, "MA200 Periode", minval=1, maxval=1000)
tf = input.timeframe("1D", "Timeframe USDT.D")
normalize = input.bool(true, "Normaliser 0-100")
forceLive = input.bool(true, "Force Update Live")
showDebug = input.bool(false, "Tableau Debug")
showAlerts = input.bool(true, "Alertes Cross")
///// RECUPERATION MULTI-SOURCES + ANTI-PLAT /////
usdt1 = request.security("TVC:USDT.D", tf, close, ignore_invalid_symbol=true, lookahead=barmerge.lookahead_off)
usdt2 = request.security("CRYPTOCAP:USDT.D", tf, close, ignore_invalid_symbol=true, lookahead=barmerge.lookahead_off)
usdtD = na(usdt1) or (forceLive and barstate.isrealtime) ? usdt2 : usdt1
///// CALCULS MA + DETECTION PLATS CORRIGEE /////
ma30 = ta.sma(usdtD, len30)
ma200 = ta.sma(usdtD, len200)
// CORRECTION CRITIQUE : flat_bars safe
flat30_bars = na(ta.valuewhen(ta.change(ma30) != 0, bar_index, 0)) ? 0 : bar_index - ta.valuewhen(ta.change(ma30) != 0, bar_index, 0)
flat200_bars = na(ta.valuewhen(ta.change(ma200) != 0, bar_index, 0)) ? 0 : bar_index - ta.valuewhen(ta.change(ma200) != 0, bar_index, 0)
isFlat30 = flat30_bars > 10
isFlat200 = flat200_bars > 10
///// NORMALISATION INTELLIGENTE /////
lookback = 1000
ma30_norm = normalize and not na(ma30) ? (ma30 - ta.lowest(ma30, lookback)) / (ta.highest(ma30, lookback) - ta.lowest(ma30, lookback)) * 100 : ma30
ma200_norm = normalize and not na(ma200) ? (ma200 - ta.lowest(ma200, lookback)) / (ta.highest(ma200, lookback) - ta.lowest(ma200, lookback)) * 100 : ma200
///// PLOTS AVANCES /////
ma30_color = isFlat30 ? color.new(color.gray, 50) : (ma30 > ma200 ? color.new(color.lime, 0) : color.new(color.blue, 0))
ma200_color = isFlat200 ? color.new(color.gray, 50) : (ma30 > ma200 ? color.new(color.orange, 20) : color.new(color.red, 0))
p30 = plot(ma30_norm, "MA30", ma30_color, 4)
p200 = plot(ma200_norm, "MA200", ma200_color, 4)
fill(p30, p200, color=ma30_norm > ma200_norm ? color.new(color.green, 88) : color.new(color.red, 88), title="Trend Fill")
///// NIVEAUX REFERENCE /////
hline_level = normalize ? 50 : 5
hline_high = normalize ? 80 : 7
hline_low = normalize ? 20 : 3
hline(hline_high, "Surachat", color=color.red, linestyle=hline.style_dashed, linewidth=2)
hline(hline_low, "Survente", color=color.green, linestyle=hline.style_dashed, linewidth=2)
hline(hline_level, "Milieu", color=color.gray, linestyle=hline.style_solid)
///// SIGNAUX CROSS + PLATS /////
bullCross = ta.crossover(ma30, ma200)
bearCross = ta.crossunder(ma30, ma200)
plotshape(bullCross and showAlerts, "ACHAT", shape.triangleup, location.bottom, color.lime, size=size.normal)
plotshape(bearCross and showAlerts, "VENTE", shape.triangledown, location.top, color.red, size=size.normal)
plotshape(isFlat30, "Plat MA30", shape.xcross, location.top, color.new(color.gray, 0), size=size.tiny)
plotshape(isFlat200, "Plat MA200", shape.xcross, location.bottom, color.new(color.gray, 0), size=size.tiny)
bgcolor((isFlat30 or isFlat200) ? color.new(color.yellow, 92) : na, title="Plat Alert")
///// ALERTES PROFESSIONNELLES /////
alertcondition(bullCross, "USDT.D Bull Cross", "USDT.D: MA30 croise AU-DESSUS MA200")
alertcondition(bearCross, "USDT.D Bear Cross", "USDT.D: MA30 croise EN-DESSOUS MA200")
alertcondition(isFlat30 or isFlat200, "USDT.D Flat", "USDT.D: MA PLAT detecte")
///// TABLEAU DEBUG LIVE CORRIGE /////
if showDebug and barstate.islast
var table dashboard = table.new(position.top_right, 2, 8, bgcolor=color.new(color.white, 10), border_width=2)
table.cell(dashboard, 0, 0, "USDT.D", text_color=color.purple, text_size=size.normal, bgcolor=color.new(color.purple, 90))
table.cell(dashboard, 1, 0, str.tostring(usdtD, "#.###") + "%", text_color=color.white, text_size=size.normal, bgcolor=color.new(color.purple, 90))
table.cell(dashboard, 0, 1, "MA30", text_color=ma30_color, text_size=size.small)
table.cell(dashboard, 1, 1, str.tostring(ma30, "#.###"), text_color=ma30_color, text_size=size.small)
table.cell(dashboard, 0, 2, "MA200", text_color=ma200_color, text_size=size.small)
table.cell(dashboard, 1, 2, str.tostring(ma200, "#.###"), text_color=ma200_color, text_size=size.small)
table.cell(dashboard, 0, 3, "Flat30", text_color=color.gray, text_size=size.small)
table.cell(dashboard, 1, 3, str.tostring(flat30_bars) + "b", text_color=isFlat30 ? color.red : color.green, text_size=size.small)
table.cell(dashboard, 0, 4, "Flat200", text_color=color.gray, text_size=size.small)
table.cell(dashboard, 1, 4, str.tostring(flat200_bars) + "b", text_color=isFlat200 ? color.red : color.green, text_size=size.small)
table.cell(dashboard, 0, 5, "Trend", text_color=color.black, text_size=size.small, bgcolor=color.new(color.yellow, 80))
table.cell(dashboard, 1, 5, ma30 > ma200 ? "HAUSSIER" : "BAISSIER", text_color=ma30 > ma200 ? color.green : color.red, text_size=size.normal, bgcolor=color.new(color.yellow, 80))
table.cell(dashboard, 0, 6, "TF", text_color=color.blue, text_size=size.small)
table.cell(dashboard, 1, 6, tf, text_color=color.blue, text_size=size.small)
table.cell(dashboard, 0, 7, "Plan OK", text_color=not na(usdtD) ? color.green : color.red, text_size=size.small)
table.cell(dashboard, 1, 7, not na(usdtD) ? "OK" : "NO", text_color=not na(usdtD) ? color.green : color.red, text_size=size.normal)
indicator("USDT.D MA30 MA200 PRO ULTIME", shorttitle="USDT.D Pro", overlay=false, max_labels_count=500, max_lines_count=500)
///// PARAMETRES COMPLETS /////
len30 = input.int(30, "MA30 Periode", minval=1, maxval=500)
len200 = input.int(200, "MA200 Periode", minval=1, maxval=1000)
tf = input.timeframe("1D", "Timeframe USDT.D")
normalize = input.bool(true, "Normaliser 0-100")
forceLive = input.bool(true, "Force Update Live")
showDebug = input.bool(false, "Tableau Debug")
showAlerts = input.bool(true, "Alertes Cross")
///// RECUPERATION MULTI-SOURCES + ANTI-PLAT /////
usdt1 = request.security("TVC:USDT.D", tf, close, ignore_invalid_symbol=true, lookahead=barmerge.lookahead_off)
usdt2 = request.security("CRYPTOCAP:USDT.D", tf, close, ignore_invalid_symbol=true, lookahead=barmerge.lookahead_off)
usdtD = na(usdt1) or (forceLive and barstate.isrealtime) ? usdt2 : usdt1
///// CALCULS MA + DETECTION PLATS CORRIGEE /////
ma30 = ta.sma(usdtD, len30)
ma200 = ta.sma(usdtD, len200)
// CORRECTION CRITIQUE : flat_bars safe
flat30_bars = na(ta.valuewhen(ta.change(ma30) != 0, bar_index, 0)) ? 0 : bar_index - ta.valuewhen(ta.change(ma30) != 0, bar_index, 0)
flat200_bars = na(ta.valuewhen(ta.change(ma200) != 0, bar_index, 0)) ? 0 : bar_index - ta.valuewhen(ta.change(ma200) != 0, bar_index, 0)
isFlat30 = flat30_bars > 10
isFlat200 = flat200_bars > 10
///// NORMALISATION INTELLIGENTE /////
lookback = 1000
ma30_norm = normalize and not na(ma30) ? (ma30 - ta.lowest(ma30, lookback)) / (ta.highest(ma30, lookback) - ta.lowest(ma30, lookback)) * 100 : ma30
ma200_norm = normalize and not na(ma200) ? (ma200 - ta.lowest(ma200, lookback)) / (ta.highest(ma200, lookback) - ta.lowest(ma200, lookback)) * 100 : ma200
///// PLOTS AVANCES /////
ma30_color = isFlat30 ? color.new(color.gray, 50) : (ma30 > ma200 ? color.new(color.lime, 0) : color.new(color.blue, 0))
ma200_color = isFlat200 ? color.new(color.gray, 50) : (ma30 > ma200 ? color.new(color.orange, 20) : color.new(color.red, 0))
p30 = plot(ma30_norm, "MA30", ma30_color, 4)
p200 = plot(ma200_norm, "MA200", ma200_color, 4)
fill(p30, p200, color=ma30_norm > ma200_norm ? color.new(color.green, 88) : color.new(color.red, 88), title="Trend Fill")
///// NIVEAUX REFERENCE /////
hline_level = normalize ? 50 : 5
hline_high = normalize ? 80 : 7
hline_low = normalize ? 20 : 3
hline(hline_high, "Surachat", color=color.red, linestyle=hline.style_dashed, linewidth=2)
hline(hline_low, "Survente", color=color.green, linestyle=hline.style_dashed, linewidth=2)
hline(hline_level, "Milieu", color=color.gray, linestyle=hline.style_solid)
///// SIGNAUX CROSS + PLATS /////
bullCross = ta.crossover(ma30, ma200)
bearCross = ta.crossunder(ma30, ma200)
plotshape(bullCross and showAlerts, "ACHAT", shape.triangleup, location.bottom, color.lime, size=size.normal)
plotshape(bearCross and showAlerts, "VENTE", shape.triangledown, location.top, color.red, size=size.normal)
plotshape(isFlat30, "Plat MA30", shape.xcross, location.top, color.new(color.gray, 0), size=size.tiny)
plotshape(isFlat200, "Plat MA200", shape.xcross, location.bottom, color.new(color.gray, 0), size=size.tiny)
bgcolor((isFlat30 or isFlat200) ? color.new(color.yellow, 92) : na, title="Plat Alert")
///// ALERTES PROFESSIONNELLES /////
alertcondition(bullCross, "USDT.D Bull Cross", "USDT.D: MA30 croise AU-DESSUS MA200")
alertcondition(bearCross, "USDT.D Bear Cross", "USDT.D: MA30 croise EN-DESSOUS MA200")
alertcondition(isFlat30 or isFlat200, "USDT.D Flat", "USDT.D: MA PLAT detecte")
///// TABLEAU DEBUG LIVE CORRIGE /////
if showDebug and barstate.islast
var table dashboard = table.new(position.top_right, 2, 8, bgcolor=color.new(color.white, 10), border_width=2)
table.cell(dashboard, 0, 0, "USDT.D", text_color=color.purple, text_size=size.normal, bgcolor=color.new(color.purple, 90))
table.cell(dashboard, 1, 0, str.tostring(usdtD, "#.###") + "%", text_color=color.white, text_size=size.normal, bgcolor=color.new(color.purple, 90))
table.cell(dashboard, 0, 1, "MA30", text_color=ma30_color, text_size=size.small)
table.cell(dashboard, 1, 1, str.tostring(ma30, "#.###"), text_color=ma30_color, text_size=size.small)
table.cell(dashboard, 0, 2, "MA200", text_color=ma200_color, text_size=size.small)
table.cell(dashboard, 1, 2, str.tostring(ma200, "#.###"), text_color=ma200_color, text_size=size.small)
table.cell(dashboard, 0, 3, "Flat30", text_color=color.gray, text_size=size.small)
table.cell(dashboard, 1, 3, str.tostring(flat30_bars) + "b", text_color=isFlat30 ? color.red : color.green, text_size=size.small)
table.cell(dashboard, 0, 4, "Flat200", text_color=color.gray, text_size=size.small)
table.cell(dashboard, 1, 4, str.tostring(flat200_bars) + "b", text_color=isFlat200 ? color.red : color.green, text_size=size.small)
table.cell(dashboard, 0, 5, "Trend", text_color=color.black, text_size=size.small, bgcolor=color.new(color.yellow, 80))
table.cell(dashboard, 1, 5, ma30 > ma200 ? "HAUSSIER" : "BAISSIER", text_color=ma30 > ma200 ? color.green : color.red, text_size=size.normal, bgcolor=color.new(color.yellow, 80))
table.cell(dashboard, 0, 6, "TF", text_color=color.blue, text_size=size.small)
table.cell(dashboard, 1, 6, tf, text_color=color.blue, text_size=size.small)
table.cell(dashboard, 0, 7, "Plan OK", text_color=not na(usdtD) ? color.green : color.red, text_size=size.small)
table.cell(dashboard, 1, 7, not na(usdtD) ? "OK" : "NO", text_color=not na(usdtD) ? color.green : color.red, text_size=size.normal)
Mã được bảo vệ
Tập lệnh này được đăng dưới dạng mã nguồn đóng. Tuy nhiên, bạn có thể sử dụng tự do và không giới hạn – tìm hiểu thêm tại đây.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.
Mã được bảo vệ
Tập lệnh này được đăng dưới dạng mã nguồn đóng. Tuy nhiên, bạn có thể sử dụng tự do và không giới hạn – tìm hiểu thêm tại đây.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.