Daily 1m Index: IGV, MAGS, SOXX

dkpm_trader · study · 84 行 · 点赞 6 · TradingView 原页

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

Pine Script

//@version=6
 
// Daily 1m Index — IGV / MAGS / SOXX
// Compares the intraday performance of software, Magnificent Seven and
// semiconductor ETFs on one percentage chart, useful as context for /NQ.
// Each ETF's return is measured from the opening price of its first
// available 1-minute bar in the new trading day.
// Best viewed on a 1-minute RTH chart; higher timeframes sample the 1m data.
// On futures/extended-hours charts, ETF lines may be flat outside ETF trading.
 
indicator("Daily 1m Index: IGV, MAGS, SOXX", overlay=false, format=format.percent)
 
// CHOOSE: the circle size, label transparency and pane colors.
 
circleSize = input.int(4, "New Day Circle Size", minval=1, maxval=12)
labelTransparency = input.int(50, "Closing Price Label Transparency (%)", minval=0, maxval=100)
paneBg = input.color(#202020, "Indicator Background")
 
// Light gray makes MAGS visible against the dark background.
 
magsColor = input.color(#E0E0E0, "MAGS Line / Scale Label Color")
bgcolor(paneBg, title="Indicator Background")
 
// SET: the daily opening reference independently for each ETF.
// Return the latest close, percentage change and daily timestamp.
 
f_closeAndDailyPct() =>
    var float dayReference = na
    if ta.change(time("D")) != 0 or na(dayReference)
        dayReference := open
    [close, (close / dayReference - 1) * 100, time("D")]
 
 // FETCH: 1-minute prices and percentages for the three ETFs.
 
[closeIgv, pctIgv, igvDay] = request.security("AMEX:IGV", "1", f_closeAndDailyPct(), lookahead=barmerge.lookahead_off)
[closeMags, pctMags, magsDay] = request.security("MAGS", "1", f_closeAndDailyPct(), lookahead=barmerge.lookahead_off)
[closeSoxx, pctSoxx, soxxDay] = request.security("NASDAQ:SOXX", "1", f_closeAndDailyPct(), lookahead=barmerge.lookahead_off)
 
// DETECT: a new IGV trading day for the white reset circle.
 
isNewIgvDay = not na(igvDay[1]) and igvDay != igvDay[1]
 
// DRAW: zero line and the three percentage-performance lines.
 
hline(0, "Baseline 0%", color=color.new(color.gray, 50), linestyle=hline.style_dashed)
plot(isNewIgvDay ? 0.0 : pctIgv, "IGV", color=color.green, linewidth=2)
plot(isNewIgvDay ? 0.0 : pctMags, "MAGS", color=magsColor, linewidth=2)
plot(isNewIgvDay ? 0.0 : pctSoxx, "SOXX", color=color.blue, linewidth=2)
 
// DRAW: white circle at the start of each IGV trading day.
// The three lines display zero on that bar so they meet at the circle.
 
plot(isNewIgvDay ? 0.0 : na, "09:30 ET", color=color.white, style=plot.style_circles, linewidth=circleSize)
 
// LABEL: the latest $ price, one per ETF.
// Reuse each label as new prices arrive instead of adding more labels.
 
var label igvLabel = na
var label magsLabel = na
var label soxxLabel = na
 
if barstate.islast
    if na(igvLabel)
        igvLabel := label.new(bar_index - 2, pctIgv, "", style=label.style_label_right, color=color.new(color.green, labelTransparency), textcolor=color.white, size=size.small)
        magsLabel := label.new(bar_index - 2, pctMags, "", style=label.style_label_right, color=color.new(color.white, labelTransparency), textcolor=color.black, size=size.small)
        soxxLabel := label.new(bar_index - 2, pctSoxx, "", style=label.style_label_right, color=color.new(color.blue, labelTransparency), textcolor=color.white, size=size.small)
 
    // Move each price label to the latest plotted percentage value.
 
    label.set_xy(igvLabel, bar_index - 2, pctIgv)
    label.set_xy(magsLabel, bar_index - 2, pctMags)
    label.set_xy(soxxLabel, bar_index - 2, pctSoxx)
 
    // Show only the current dollar closing price, not the percentage.
 
    label.set_text(igvLabel, "$" + str.tostring(closeIgv, "#.00"))
    label.set_text(magsLabel, "$" + str.tostring(closeMags, "#.00"))
    label.set_text(soxxLabel, "$" + str.tostring(closeSoxx, "#.00"))
 
    // Apply the chosen transparency to each label background.
 
    label.set_color(igvLabel, color.new(color.green, labelTransparency))
    label.set_color(magsLabel, color.new(color.white, labelTransparency))
    label.set_color(soxxLabel, color.new(color.blue, labelTransparency))

← 返回列表