NQ NY — EMA/TEMA Dashboard

alliecasaday · study · 230 行 · 点赞 1,005 · TradingView 原页

本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。

Pine Script

// ============================================================
//  NQ NY Session — 8 EMA / 13·21·55 TEMA Dashboard
//  Version: v3.0
//
//  Features:
//   — 8 EMA (blue, thick) + 13/21/55 TEMA lines
//   — VWAP
//   — Checklist table (top-right):
//       ✔/✘  8 EMA crossed 55 TEMA
//       ▲/▼  Trend direction (bullish/bearish)
//       ✔/✘  55 TEMA alignment (above all for short / below all for long)
//       ✔/✘  5m timeframe agrees (8 EMA vs 55 TEMA on 5m)
// ============================================================
 
//@version=6
indicator(title      = "NQ NY — EMA/TEMA Dashboard",
          shorttitle = "EMA/TEMA Dash",
          overlay    = true,
          max_labels_count = 500,
          max_boxes_count  = 100)
 
// ─────────────────────────────────────────────
// INPUTS
// ─────────────────────────────────────────────
grpEma    = "Moving Averages"
emaLen    = input.int(8,  "EMA Length",     minval=1, group=grpEma)
t13Len    = input.int(13, "TEMA 13 Length", minval=1, group=grpEma)
t21Len    = input.int(21, "TEMA 21 Length", minval=1, group=grpEma)
t55Len    = input.int(55, "TEMA 55 Length", minval=1, group=grpEma)
showT13   = input.bool(true, "Show 13 TEMA", group=grpEma)
showT21   = input.bool(true, "Show 21 TEMA", group=grpEma)
showVwap  = input.bool(true, "Show VWAP",    group=grpEma)
 
grpVis    = "Visuals"
emaCol    = input.color(#1E90FF,             "8 EMA Color",   group=grpVis)
t13Col    = input.color(color.new(#B39DDB,0),"13 TEMA Color", group=grpVis)
t21Col    = input.color(color.new(#FFD740,0),"21 TEMA Color", group=grpVis)
t55Col    = input.color(color.new(#FF9800,0),"55 TEMA Color", group=grpVis)
vwapCol   = input.color(color.new(#E040FB,0),"VWAP Color",    group=grpVis)
 
// ─────────────────────────────────────────────
// MOVING AVERAGE CALCULATIONS
// ─────────────────────────────────────────────
tema(src, len) =>
    e1 = ta.ema(src, len)
    e2 = ta.ema(e1,  len)
    e3 = ta.ema(e2,  len)
    3 * e1 - 3 * e2 + e3
 
ema8  = ta.ema(close, emaLen)
t13   = tema(close, t13Len)
t21   = tema(close, t21Len)
t55   = tema(close, t55Len)
 
// VWAP (session)
[vwapVal, _, _] = ta.vwap(hlc3, false, 1)
 
// ─────────────────────────────────────────────
// CHECKLIST LOGIC
// ─────────────────────────────────────────────
 
// 1. Has 8 EMA crossed 55 TEMA? (is currently on one side)
//    Green = a cross HAS occurred (ema8 != t55 side, i.e. they are not equal/tangled)
//    We track whether ema8 is above or below t55 as the cross state
emaCrossedBull = ema8 > t55   // ema crossed above → bullish
emaCrossedBear = ema8 < t55   // ema crossed below → bearish
crossOccurred  = emaCrossedBull or emaCrossedBear
 
// 2. Trend direction
isBullish = ema8 > t55
isBearish = ema8 < t55
 
// 3. 55 TEMA alignment
//    For SHORT: t55 should be ABOVE all other MAs (price below all = bearish stack)
//    For LONG:  t55 should be BELOW all other MAs (price above all = bullish stack)
t55AboveAll = t55 > ema8 and t55 > t13 and t55 > t21   // good for SHORT
t55BelowAll = t55 < ema8 and t55 < t13 and t55 < t21   // good for LONG
t55Aligned  = t55AboveAll or t55BelowAll
 
// 4. 5-minute timeframe alignment (8 EMA vs 55 TEMA on 5m)
ema8_5m  = request.security(syminfo.tickerid, "5", ta.ema(close, 8),  lookahead=barmerge.lookahead_off)
t55_5m_e1 = request.security(syminfo.tickerid, "5", ta.ema(close, 55), lookahead=barmerge.lookahead_off)
t55_5m_e2 = request.security(syminfo.tickerid, "5", ta.ema(t55_5m_e1, 55), lookahead=barmerge.lookahead_off)
t55_5m_e3 = request.security(syminfo.tickerid, "5", ta.ema(t55_5m_e2, 55), lookahead=barmerge.lookahead_off)
t55_5m    = 3 * t55_5m_e1 - 3 * t55_5m_e2 + t55_5m_e3
 
tfAlignBull = ema8_5m > t55_5m   // 5m bullish agrees with current bullish
tfAlignBear = ema8_5m < t55_5m   // 5m bearish agrees with current bearish
tfAligned   = (isBullish and tfAlignBull) or (isBearish and tfAlignBear)
 
// ─────────────────────────────────────────────
// CROSS DETECTION
// ─────────────────────────────────────────────
bullCross = ta.crossover(ema8, t55)
bearCross = ta.crossunder(ema8, t55)
 
// ─────────────────────────────────────────────
// PLOTS
// ─────────────────────────────────────────────
plot(t55,                   title="55 TEMA", color=t55Col,  linewidth=2)
plot(showT21 ? t21 : na,    title="21 TEMA", color=t21Col,  linewidth=2)
plot(showT13 ? t13 : na,    title="13 TEMA", color=t13Col,  linewidth=1)
plot(ema8,                  title="8 EMA",   color=emaCol,  linewidth=4)
plot(showVwap ? vwapVal : na, title="VWAP",  color=vwapCol, linewidth=1, style=plot.style_circles)
 
 
// Cross markers — "+" label placed at exact intersection of 8 EMA and 55 TEMA
crossPrice = math.avg(ema8, t55)
 
if bullCross
    label.new(bar_index, crossPrice,
              text      = "+",
              textcolor = #00E676,
              style     = label.style_none,
              size      = size.huge)
 
if bearCross
    label.new(bar_index, crossPrice,
              text      = "+",
              textcolor = #FF1744,
              style     = label.style_none,
              size      = size.huge)
 
// ─────────────────────────────────────────────
// DASHBOARD TABLE
// ─────────────────────────────────────────────
var table dash = table.new(
     position  = position.top_right,
     columns   = 2,
     rows      = 6,
     bgcolor   = color.new(#0D1117, 10),
     border_width = 1,
     border_color = color.new(#2A3A4A, 0),
     frame_width  = 2,
     frame_color  = color.new(#1E90FF, 60))
 
// Colors
C_GREEN  = #00E676
C_RED    = #FF1744
C_WHITE  = #EAEAEA
C_MUTED  = #607080
C_HEADER = #0D1117
C_BULL   = #00E676
C_BEAR   = #FF1744
 
if barstate.islast
 
    // ── Header ──────────────────────────────
    table.cell(dash, 0, 0, "CONDITION",
               text_color=color.new(C_MUTED, 0),
               text_size=size.small,
               bgcolor=color.new(#141C27, 0),
               text_halign=text.align_left)
    table.cell(dash, 1, 0, "STATUS",
               text_color=color.new(C_MUTED, 0),
               text_size=size.small,
               bgcolor=color.new(#141C27, 0),
               text_halign=text.align_center)
 
    // ── Row 1: Crossover ────────────────────
    table.cell(dash, 0, 1, "EMA8 × TEMA55 Cross",
               text_color=C_WHITE,
               text_size=size.small,
               bgcolor=color.new(#0D1117, 0),
               text_halign=text.align_left)
    table.cell(dash, 1, 1,
               crossOccurred ? "✔" : "✘",
               text_color = crossOccurred ? C_GREEN : C_RED,
               text_size  = size.normal,
               bgcolor    = color.new(#0D1117, 0),
               text_halign= text.align_center)
 
    // ── Row 2: Trend Direction ───────────────
    trendTxt   = isBullish ? "▲  BULLISH" : isBearish ? "▼  BEARISH" : "─  NEUTRAL"
    trendColor = isBullish ? C_BULL       : isBearish ? C_BEAR       : C_MUTED
    table.cell(dash, 0, 2, "Trend Direction",
               text_color=C_WHITE,
               text_size=size.small,
               bgcolor=color.new(#0D1117, 0),
               text_halign=text.align_left)
    table.cell(dash, 1, 2, trendTxt,
               text_color = trendColor,
               text_size  = size.small,
               bgcolor    = color.new(#0D1117, 0),
               text_halign= text.align_center)
 
    // ── Row 3: 55 TEMA Stack Alignment ───────
    //    Show what it's aligned FOR (long or short), or ✘ if neither
    stackTxt   = t55BelowAll ? "✔  LONG"  :
                 t55AboveAll ? "✔  SHORT" : "✘"
    stackColor = t55Aligned  ? C_GREEN : C_RED
    table.cell(dash, 0, 3, "TEMA55 Stack Aligned",
               text_color=C_WHITE,
               text_size=size.small,
               bgcolor=color.new(#0D1117, 0),
               text_halign=text.align_left)
    table.cell(dash, 1, 3, stackTxt,
               text_color = stackColor,
               text_size  = size.small,
               bgcolor    = color.new(#0D1117, 0),
               text_halign= text.align_center)
 
    // ── Row 4: 5m TF Alignment ───────────────
    tfTxt   = tfAligned ? "✔  AGREES" : "✘  CONFLICTS"
    tfColor = tfAligned ? C_GREEN : C_RED
    table.cell(dash, 0, 4, "5m TF Aligned",
               text_color=C_WHITE,
               text_size=size.small,
               bgcolor=color.new(#0D1117, 0),
               text_halign=text.align_left)
    table.cell(dash, 1, 4, tfTxt,
               text_color = tfColor,
               text_size  = size.small,
               bgcolor    = color.new(#0D1117, 0),
               text_halign= text.align_center)
 
    // ── Row 5: All-Green Summary ─────────────
    allGreen    = crossOccurred and t55Aligned and tfAligned
    summaryTxt  = allGreen ? "● CONFLUENT" : "● WAIT"
    summaryCol  = allGreen ? C_GREEN : C_MUTED
    table.cell(dash, 0, 5, "Confluence",
               text_color = C_MUTED,
               text_size  = size.small,
               bgcolor    = color.new(#141C27, 0),
               text_halign= text.align_left)
    table.cell(dash, 1, 5, summaryTxt,
               text_color = summaryCol,
               text_size  = size.small,
               bgcolor    = color.new(#141C27, 0),
               text_halign= text.align_center)

← 返回列表