VWAP Super Script

Uno_Mas · study · 1105 行 · 点赞 31 · TradingView 原页

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

Pine Script

// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// Uno_Mas
 
//@version=6
 
// ============================================================================
// VWAP SUPER SCRIPT - SESSION, NY CASH, OR/IB, FIBS & MULTI-SYMBOL DASHBOARD
// ============================================================================
//
// OVERVIEW:
// This indicator combines several VWAP-based tools for US equity markets:
//
//   1. NY VWAP (Cash Session VWAP) - VWAP for regular trading hours only
//      (9:30 AM - 4:00 PM ET). Resets daily at market open. Optional std-dev bands.
//
//   2. Session VWAP - VWAP for the full trading session including pre-market
//      and after-hours. Only displays when extended hours data is available.
//      Optional std-dev bands.
//
//   3. Previous-Day NY VWAP - the prior day's completed NY cash VWAP, carried
//      forward as a reference line.
//
//   4. LOD / HOD VWAP - VWAP lines anchored to the day's low and high.
//
//   5. NY Open, Previous-Day Close, Opening Range (OR) High/Low, and
//      Initial Balance (IB) High/Low.
//
//   6. Fibonacci levels (10 slots) anchored to the IB range, the OR range, or a
//      single level (NY Open / Previous-Day Close) used as the 0 line with
//      1 / -1 = one ATR (default: daily ATR 14) above / below it.
//
//   7. Multi-symbol Dashboard - a table monitoring up to 3 tickers and their
//      position relative to the key levels above.
//
// ============================================================================
 
indicator("VWAP Super Script", overlay = true, max_lines_count = 500, max_labels_count = 500)
 
// ============================================================================
// CONSTANTS
// ============================================================================
// Time session definitions (America/New_York timezone)
const string TIMEZONE           = "America/New_York"
const string EXTENDED_SESSION   = "1800-0929"  // Extended hours: 6:00 PM to 9:29 AM
 
// Fully transparent color for label backgrounds
transparent = color.rgb(0, 0, 0, 100)
 
// ============================================================================
// USER INPUTS
// ============================================================================
 
// Calculation Settings
CALC_GROUP = "Calculation"
i_enableHD = input.bool(true, title = "Use 5-min data for precision", group = CALC_GROUP, tooltip = "On chart timeframes above 5 minutes, calculate VWAP using 5-minute bars for more accurate values. Prevents VWAP drift on higher timeframe charts.")
i_debugLog = input.bool(false, title = "Debug Logging", group = CALC_GROUP, tooltip = "Enable logging to Pine Logs for debugging. Logs every 30 minutes.")
 
// NY Cash VWAP Settings
NY_GROUP = "NY VWAP"
i_NY_color          = input.color(color.new(#4caf50, 0), title = "Color", group = NY_GROUP, inline = "line")
i_NY_width          = input.int(1, title = "Width", group = NY_GROUP, inline = "line")
i_NY_style          = input.string("Solid", title = "Style", options = ["Solid", "Dashed", "Dotted"], group = NY_GROUP, inline = "line")
i_NY_showlabel      = input.bool(true, title = "Show Label", group = NY_GROUP, inline = "label")
i_NY_label          = input.string("NYVWAP", title = "", group = NY_GROUP, inline = "label")
i_NY_labelOffset    = input.int(0, title = "Offset", group = NY_GROUP, inline = "label")
i_NY_txtSize        = str.lower(input.string("Normal", title = "Label Size", options = ["Tiny", "Small", "Normal", "Large", "Huge"], group = NY_GROUP))
i_NY_showPriceScale = input.bool(true, title = "Show in Price Scale", group = NY_GROUP)
 
// NY VWAP Bands Settings
NY_BANDS_GROUP = "NY VWAP Bands"
i_showNYBand1       = input.bool(false, title = "Band Std Dev #1", group = NY_BANDS_GROUP, inline = "nyband1a")
i_nyBandMult1       = input.float(1.0, title = "", group = NY_BANDS_GROUP, inline = "nyband1a", step = 0.5, minval = 0)
i_nyBandStyle1      = input.string("Solid", title = "", options = ["Solid", "Dashed", "Dotted"], group = NY_BANDS_GROUP, inline = "nyband1a")
i_nyBandColor1      = input.color(color.new(color.green, 0), title = "Line", group = NY_BANDS_GROUP, inline = "nyband1b")
i_nyBandFill1       = input.color(color.new(color.green, 90), title = "Fill", group = NY_BANDS_GROUP, inline = "nyband1b")
i_nyBandPriceScale1 = input.bool(false, title = "Price Scale", group = NY_BANDS_GROUP, inline = "nyband1b")
 
i_showNYBand2       = input.bool(false, title = "Band Std Dev #2", group = NY_BANDS_GROUP, inline = "nyband2a")
i_nyBandMult2       = input.float(2.0, title = "", group = NY_BANDS_GROUP, inline = "nyband2a", step = 0.5, minval = 0)
i_nyBandStyle2      = input.string("Solid", title = "", options = ["Solid", "Dashed", "Dotted"], group = NY_BANDS_GROUP, inline = "nyband2a")
i_nyBandColor2      = input.color(color.new(color.olive, 0), title = "Line", group = NY_BANDS_GROUP, inline = "nyband2b")
i_nyBandFill2       = input.color(color.new(color.olive, 90), title = "Fill", group = NY_BANDS_GROUP, inline = "nyband2b")
i_nyBandPriceScale2 = input.bool(false, title = "Price Scale", group = NY_BANDS_GROUP, inline = "nyband2b")
 
i_showNYBand3       = input.bool(false, title = "Band Std Dev #3", group = NY_BANDS_GROUP, inline = "nyband3a")
i_nyBandMult3       = input.float(3.0, title = "", group = NY_BANDS_GROUP, inline = "nyband3a", step = 0.5, minval = 0)
i_nyBandStyle3      = input.string("Solid", title = "", options = ["Solid", "Dashed", "Dotted"], group = NY_BANDS_GROUP, inline = "nyband3a")
i_nyBandColor3      = input.color(color.new(color.teal, 0), title = "Line", group = NY_BANDS_GROUP, inline = "nyband3b")
i_nyBandFill3       = input.color(color.new(color.teal, 90), title = "Fill", group = NY_BANDS_GROUP, inline = "nyband3b")
i_nyBandPriceScale3 = input.bool(false, title = "Price Scale", group = NY_BANDS_GROUP, inline = "nyband3b")
 
// Previous-Day NY VWAP Settings
PREVNY_GROUP = "Previous-Day NY VWAP"
i_showPrevNY     = input.bool(true, "Show Prev-Day NY VWAP", group = PREVNY_GROUP, inline = "pn")
i_prevNYColor    = input.color(#f23645, "", group = PREVNY_GROUP, inline = "pn")
i_prevNYWidth    = input.int(1, "W", minval = 1, group = PREVNY_GROUP, inline = "pn")
i_prevNYStyle    = input.string("Solid", "S", options = ["Solid", "Dashed", "Dotted"], group = PREVNY_GROUP, inline = "pn")
i_prevNYLabel    = input.string("PD NY VWAP", "Label", group = PREVNY_GROUP)
 
// LOD / HOD VWAP Settings
LODHOD_GROUP = "LOD / HOD VWAP"
i_showLOD     = input.bool(true, "Show LOD VWAP", group = LODHOD_GROUP, inline = "lod")
i_lodColor    = input.color(#f23645, "", group = LODHOD_GROUP, inline = "lod")
i_lodWidth    = input.int(1, "W", minval = 1, group = LODHOD_GROUP, inline = "lod")
i_lodStyle    = input.string("Dotted", "S", options = ["Solid", "Dashed", "Dotted"], group = LODHOD_GROUP, inline = "lod")
i_lodLabel    = input.string("LOD VWAP", "Label", group = LODHOD_GROUP)
 
i_showHOD     = input.bool(true, "Show HOD VWAP", group = LODHOD_GROUP, inline = "hod")
i_hodColor    = input.color(#089981, "", group = LODHOD_GROUP, inline = "hod")
i_hodWidth    = input.int(1, "W", minval = 1, group = LODHOD_GROUP, inline = "hod")
i_hodStyle    = input.string("Dotted", "S", options = ["Solid", "Dashed", "Dotted"], group = LODHOD_GROUP, inline = "hod")
i_hodLabel    = input.string("HOD VWAP", "Label", group = LODHOD_GROUP)
 
// NY Open & IB Settings
NY_OPEN_GROUP = "NY Open & Initial Balance"
i_showNYOpen      = input.bool(true, "Show NY Open", group = NY_OPEN_GROUP)
i_nyOpenColor     = input.color(color.gray, "Open Color", group = NY_OPEN_GROUP, inline = "open")
i_nyOpenStyle     = input.string("Dashed", "Style", options = ["Solid", "Dashed", "Dotted"], group = NY_OPEN_GROUP, inline = "open")
i_showNYOpenLabel = input.bool(true, "Show Label", group = NY_OPEN_GROUP, inline = "open_lab")
i_nyOpenLabelText = input.string("NY Open", "", group = NY_OPEN_GROUP, inline = "open_lab")
 
i_showIB          = input.bool(true, "Show Initial Balance (IB)", group = NY_OPEN_GROUP)
i_ibSession       = input.session("0930-1030", "IB Session Time", group = NY_OPEN_GROUP, tooltip = "The time period used to calculate the Initial Balance High and Low. Defaults to the first hour of the NY session (9:30-10:30 ET). Change this to trade a different session or asset with a different opening time.")
i_ibColor         = input.color(color.new(#5b9cf6, 0), "IB Color", group = NY_OPEN_GROUP, inline = "ib")
i_ibStyle         = input.string("Solid", "Style", options = ["Solid", "Dashed", "Dotted"], group = NY_OPEN_GROUP, inline = "ib")
i_ibWidth         = input.int(1, "Width", group = NY_OPEN_GROUP, inline = "ib")
i_showIBLabel     = input.bool(true, "Show Labels", group = NY_OPEN_GROUP, inline = "ib_lab")
i_ibHighLabelText = input.string("IB High", "", group = NY_OPEN_GROUP, inline = "ib_lab")
i_ibLowLabelText  = input.string("IB Low", "", group = NY_OPEN_GROUP, inline = "ib_lab")
i_openIBLabOffset = input.int(0, "Label Offset", group = NY_OPEN_GROUP)
 
// Previous-Day Close Settings
PDC_GROUP = "Previous-Day Close"
i_showPDC      = input.bool(true, "Show Prev-Day Close", group = PDC_GROUP)
i_pdcMode      = input.string("Session Close", "Close Source", options = ["Session Close", "Daily Bar Close"], group = PDC_GROUP, tooltip = "Session Close: the close of the last bar inside the Close Session below (default = 4:00 PM ET cash close).\nDaily Bar Close: the close of the previous daily bar (on 24h futures this is the 5:00 PM ET settlement bar).")
i_pdcSession   = input.session("0930-1600", "Close Session", group = PDC_GROUP, tooltip = "Only used when Close Source = Session Close. The Prev-Day Close is the close of the final bar inside this window.")
i_pdcColor     = input.color(color.orange, "Close Color", group = PDC_GROUP, inline = "pdc")
i_pdcStyle     = input.string("Dashed", "Style", options = ["Solid", "Dashed", "Dotted"], group = PDC_GROUP, inline = "pdc")
i_pdcWidth     = input.int(1, "Width", minval = 1, group = PDC_GROUP, inline = "pdc")
i_showPDCLabel = input.bool(true, "Show Label", group = PDC_GROUP, inline = "pdc_lab")
i_pdcLabelText = input.string("PD Close", "", group = PDC_GROUP, inline = "pdc_lab")
 
// Opening Range (OR) Settings
OR_GROUP = "Opening Range (OR)"
i_orMinutes    = input.int(15, "OR Duration (minutes)", minval = 1, group = OR_GROUP, tooltip = "The Opening Range uses the same start time as the IB session. Set how many minutes from that start the Opening Range should span. Default is 15 minutes.")
i_showORHigh   = input.bool(true, "Show OR High", group = OR_GROUP, inline = "orh")
i_orHighColor  = input.color(#089981, "", group = OR_GROUP, inline = "orh")
i_orHighWidth  = input.int(2, "W", minval = 1, group = OR_GROUP, inline = "orh")
i_orHighStyle  = input.string("Solid", "S", options = ["Solid", "Dashed", "Dotted"], group = OR_GROUP, inline = "orh")
i_orHighLabel  = input.string("OR High", "Label", group = OR_GROUP, inline = "orh_lab")
 
i_showORLow    = input.bool(true, "Show OR Low", group = OR_GROUP, inline = "orl")
i_orLowColor   = input.color(#f23645, "", group = OR_GROUP, inline = "orl")
i_orLowWidth   = input.int(2, "W", minval = 1, group = OR_GROUP, inline = "orl")
i_orLowStyle   = input.string("Solid", "S", options = ["Solid", "Dashed", "Dotted"], group = OR_GROUP, inline = "orl")
i_orLowLabel   = input.string("OR Low", "Label", group = OR_GROUP, inline = "orl_lab")
 
// IB Fibonacci Levels Settings
IB_FIB_GROUP = "IB Fibonacci Levels"
i_fibSource   = input.string("Initial Balance", "Fib Source", options = ["Initial Balance", "Opening Range", "NY Open", "Previous Day Close"], group = IB_FIB_GROUP, tooltip = "Initial Balance / Opening Range: 0 = range low, 1 = range high.\nNY Open / Previous Day Close: that single level is the 0 line and 1 / -1 = one ATR above / below it (see the ATR inputs below).")
i_fibAtrLen   = input.int(14, "Level Fib ATR Length", minval = 1, group = IB_FIB_GROUP, inline = "atr", tooltip = "Only used when Fib Source is NY Open or Previous Day Close. The 0→1 span is one ATR of this length on the ATR Timeframe. The value is taken from the last COMPLETED bar of that timeframe so the levels do not repaint intraday.")
i_fibAtrTf    = input.timeframe("D", "Timeframe", group = IB_FIB_GROUP, inline = "atr")
i_fibLvlDir   = input.string("Both", "Level Fib Direction", options = ["Above", "Below", "Both"], group = IB_FIB_GROUP, tooltip = "Only used when Fib Source is NY Open or Previous Day Close. Project the fib set above the level, below it, or mirrored both ways.")
i_fibStyle    = input.string("Dotted", "Fib Line Style", options = ["Solid", "Dashed", "Dotted"], group = IB_FIB_GROUP)
i_showFibLabs = input.bool(true, "Show Fib Labels", group = IB_FIB_GROUP)
i_fibLabType  = input.string("Level", "Label Content", options = ["Level", "Price"], group = IB_FIB_GROUP)
 
// Fib Slots 1-5
i_f1_on = input.bool(false, "Slot 1", group = IB_FIB_GROUP, inline = "f1"), i_f1_val = input.float(0.236, "", group = IB_FIB_GROUP, inline = "f1"), i_f1_col = input.color(color.new(#787b86, 50), "", group = IB_FIB_GROUP, inline = "f1")
i_f2_on = input.bool(false, "Slot 2", group = IB_FIB_GROUP, inline = "f2"), i_f2_val = input.float(0.382, "", group = IB_FIB_GROUP, inline = "f2"), i_f2_col = input.color(color.new(#f23645, 50), "", group = IB_FIB_GROUP, inline = "f2")
i_f3_on = input.bool(false, "Slot 3", group = IB_FIB_GROUP, inline = "f3"), i_f3_val = input.float(0.500, "", group = IB_FIB_GROUP, inline = "f3"), i_f3_col = input.color(color.new(#4caf50, 50), "", group = IB_FIB_GROUP, inline = "f3")
i_f4_on = input.bool(false, "Slot 4", group = IB_FIB_GROUP, inline = "f4"), i_f4_val = input.float(0.618, "", group = IB_FIB_GROUP, inline = "f4"), i_f4_col = input.color(color.new(#2962ff, 50), "", group = IB_FIB_GROUP, inline = "f4")
i_f5_on = input.bool(false, "Slot 5", group = IB_FIB_GROUP, inline = "f5"), i_f5_val = input.float(0.786, "", group = IB_FIB_GROUP, inline = "f5"), i_f5_col = input.color(color.new(#9c27b0, 50), "", group = IB_FIB_GROUP, inline = "f5")
// Fib Slots 6-10
i_f6_on = input.bool(false, "Slot 6", group = IB_FIB_GROUP, inline = "f6"), i_f6_val = input.float(1.000, "", group = IB_FIB_GROUP, inline = "f6"), i_f6_col = input.color(color.new(#787b86, 50), "", group = IB_FIB_GROUP, inline = "f6")
i_f7_on = input.bool(false, "Slot 7", group = IB_FIB_GROUP, inline = "f7"), i_f7_val = input.float(1.272, "", group = IB_FIB_GROUP, inline = "f7"), i_f7_col = input.color(color.new(#787b86, 50), "", group = IB_FIB_GROUP, inline = "f7")
i_f8_on = input.bool(false, "Slot 8", group = IB_FIB_GROUP, inline = "f8"), i_f8_val = input.float(1.618, "", group = IB_FIB_GROUP, inline = "f8"), i_f8_col = input.color(color.new(#787b86, 50), "", group = IB_FIB_GROUP, inline = "f8")
i_f9_on = input.bool(false, "Slot 9", group = IB_FIB_GROUP, inline = "f9"), i_f9_val = input.float(2.000, "", group = IB_FIB_GROUP, inline = "f9"), i_f9_col = input.color(color.new(#787b86, 50), "", group = IB_FIB_GROUP, inline = "f9")
i_f10_on = input.bool(false, "Slot 10", group = IB_FIB_GROUP, inline = "f10"), i_f10_val = input.float(2.618, "", group = IB_FIB_GROUP, inline = "f10"), i_f10_col = input.color(color.new(#787b86, 50), "", group = IB_FIB_GROUP, inline = "f10")
 
// Session VWAP Settings
SESSION_GROUP = "Session VWAP"
i_Session_enabled        = input.bool(true, title = "Enabled", group = SESSION_GROUP, tooltip = "Disable to skip Session VWAP calculation and rendering. Useful when using the built-in VWAP indicator separately.")
i_Session_color          = input.color(color.new(#04eb85, 0), title = "Color", group = SESSION_GROUP, inline = "line")
i_Session_width          = input.int(2, title = "Width", group = SESSION_GROUP, inline = "line")
i_Session_style          = input.string("Dashed", title = "Style", options = ["Solid", "Dashed", "Dotted"], group = SESSION_GROUP, inline = "line")
i_Session_showlabel      = input.bool(true, title = "Show Label", group = SESSION_GROUP, inline = "label")
i_Session_label          = input.string("VWAP", title = "", group = SESSION_GROUP, inline = "label")
i_Session_labelOffset    = input.int(0, title = "Offset", group = SESSION_GROUP, inline = "label")
i_Session_txtSize        = str.lower(input.string("Normal", title = "Label Size", options = ["Tiny", "Small", "Normal", "Large", "Huge"], group = SESSION_GROUP))
i_Session_showPriceScale = input.bool(true, title = "Show in Price Scale", group = SESSION_GROUP)
 
// Session VWAP Bands Settings
BANDS_GROUP = "Session VWAP Bands"
i_showBand1       = input.bool(false, title = "Band Std Dev #1", group = BANDS_GROUP, inline = "band1a")
i_bandMult1       = input.float(1.0, title = "", group = BANDS_GROUP, inline = "band1a", step = 0.5, minval = 0)
i_bandStyle1      = input.string("Solid", title = "", options = ["Solid", "Dashed", "Dotted"], group = BANDS_GROUP, inline = "band1a")
i_bandColor1      = input.color(color.new(color.green, 0), title = "Line", group = BANDS_GROUP, inline = "band1b")
i_bandFill1       = input.color(color.new(color.green, 90), title = "Fill", group = BANDS_GROUP, inline = "band1b")
i_bandPriceScale1 = input.bool(false, title = "Price Scale", group = BANDS_GROUP, inline = "band1b")
 
i_showBand2       = input.bool(false, title = "Band Std Dev #2", group = BANDS_GROUP, inline = "band2a")
i_bandMult2       = input.float(2.0, title = "", group = BANDS_GROUP, inline = "band2a", step = 0.5, minval = 0)
i_bandStyle2      = input.string("Solid", title = "", options = ["Solid", "Dashed", "Dotted"], group = BANDS_GROUP, inline = "band2a")
i_bandColor2      = input.color(color.new(color.olive, 0), title = "Line", group = BANDS_GROUP, inline = "band2b")
i_bandFill2       = input.color(color.new(color.olive, 90), title = "Fill", group = BANDS_GROUP, inline = "band2b")
i_bandPriceScale2 = input.bool(false, title = "Price Scale", group = BANDS_GROUP, inline = "band2b")
 
i_showBand3       = input.bool(false, title = "Band Std Dev #3", group = BANDS_GROUP, inline = "band3a")
i_bandMult3       = input.float(3.0, title = "", group = BANDS_GROUP, inline = "band3a", step = 0.5, minval = 0)
i_bandStyle3      = input.string("Solid", title = "", options = ["Solid", "Dashed", "Dotted"], group = BANDS_GROUP, inline = "band3a")
i_bandColor3      = input.color(color.new(color.teal, 0), title = "Line", group = BANDS_GROUP, inline = "band3b")
i_bandFill3       = input.color(color.new(color.teal, 90), title = "Fill", group = BANDS_GROUP, inline = "band3b")
i_bandPriceScale3 = input.bool(false, title = "Price Scale", group = BANDS_GROUP, inline = "band3b")
 
// Dashboard Settings
DASH_GROUP = "Dashboard"
i_showDashboard = input.bool(true, "Show Dashboard", group = DASH_GROUP)
i_dashTicker1   = input.symbol("CME_MINI:MNQ1!", "Ticker 1", group = DASH_GROUP)
i_dashTicker2   = input.symbol("CME_MINI:MES1!", "Ticker 2", group = DASH_GROUP)
i_dashTicker3   = input.symbol("CBOT_MINI:MYM1!", "Ticker 3", group = DASH_GROUP)
i_dashPos       = input.string(position.top_right, "Position", options = [position.top_right, position.bottom_right, position.top_left, position.bottom_left], group = DASH_GROUP)
i_dashTextSize  = input.string(size.small, "Text Size", options = [size.tiny, size.small, size.normal, size.large], group = DASH_GROUP)
i_dashHeaderBg  = input.color(#2a2e39, "Header BG", group = DASH_GROUP, inline = "dh")
i_dashHeaderTxt = input.color(color.white, "Header Text", group = DASH_GROUP, inline = "dh")
i_dashCellBg    = input.color(color.new(color.black, 100), "Cell BG", group = DASH_GROUP, inline = "dc")
i_dashBodyTxt   = input.color(color.white, "Body Text", group = DASH_GROUP, inline = "dc")
i_dashBorderCol = input.color(color.gray, "Border", group = DASH_GROUP, inline = "db")
i_dashBorderW   = input.int(1, "Width", minval = 0, maxval = 10, group = DASH_GROUP, inline = "db")
i_dashBull      = input.color(#089981, "Bullish", group = DASH_GROUP, inline = "dbull")
i_dashBear      = input.color(#f23645, "Bearish", group = DASH_GROUP, inline = "dbull")
 
// Band Labels (Session + NY std-dev bands)
BAND_LAB_GROUP = "Band Labels"
i_showSessBandLabs = input.bool(false, "Show Session Band Labels", group = BAND_LAB_GROUP)
i_showNYBandLabs   = input.bool(false, "Show NY Band Labels", group = BAND_LAB_GROUP)
i_bandLabContent   = input.string("Std Dev", "Label Content", options = ["Name", "Std Dev", "Price", "Name + Price"], group = BAND_LAB_GROUP, tooltip = "Name: +1σ VWAP / -1σ NY style using the prefixes below.\nStd Dev: +1σ / -2σ from the band multiplier.\nPrice: the band price.\nName + Price: both.")
i_sessBandPrefix   = input.string("VWAP", "Session Prefix", group = BAND_LAB_GROUP, inline = "bpfx")
i_nyBandPrefix     = input.string("NY", "NY Prefix", group = BAND_LAB_GROUP, inline = "bpfx")
i_bandLabSize      = str.lower(input.string("Small", "Label Size", options = ["Tiny", "Small", "Normal", "Large", "Huge"], group = BAND_LAB_GROUP))
i_bandLabOffset    = input.int(0, "Label Offset", group = BAND_LAB_GROUP)
 
// Extra Label Toggles — lines that already had labels but no separate Show Label switch
EXTRA_LAB_GROUP = "Extra Label Toggles"
i_showPrevNYLabel = input.bool(true, "Show Prev-Day NY VWAP Label", group = EXTRA_LAB_GROUP)
i_showLODLabel    = input.bool(true, "Show LOD VWAP Label", group = EXTRA_LAB_GROUP)
i_showHODLabel    = input.bool(true, "Show HOD VWAP Label", group = EXTRA_LAB_GROUP)
i_showORHighLabel = input.bool(true, "Show OR High Label", group = EXTRA_LAB_GROUP)
i_showORLowLabel  = input.bool(true, "Show OR Low Label", group = EXTRA_LAB_GROUP)
 
// ============================================================================
// USER DEFINED TYPE
// ============================================================================
type myVWAP
    label lab
    int lab_offset
    bool isActive = true
    float cumPV = 0.0
    float cumVol = 0.0
    float cumPV2 = 0.0
    float vwap = na
    float stdev = na
 
// ============================================================================
// STATE VARIABLES
// ============================================================================
 
// Session VWAP - tracks full trading day (including extended hours)
var myVWAP sessionVWAP = myVWAP.new(
     label.new(bar_index, 0.0, text = "", style = label.style_label_left, color = transparent, textcolor = color.new(i_Session_color, 0), size = i_Session_txtSize),
     i_Session_labelOffset
 )
 
// Cash VWAP uses two alternating instances to handle the market open transition smoothly.
// When market opens, we swap which VWAP is "active" - the inactive one continues displaying
// the previous day's VWAP while the active one calculates the new day's VWAP.
var myVWAP cashVWAP1 = myVWAP.new(
     label.new(bar_index, 0.0, text = "", style = label.style_label_left, color = transparent, textcolor = color.new(i_NY_color, 0), size = i_NY_txtSize),
     i_NY_labelOffset
 )
 
var myVWAP cashVWAP2 = myVWAP.new(
     label.new(bar_index, 0.0, text = "", style = label.style_label_left, color = transparent, textcolor = color.new(i_NY_color, 0), size = i_NY_txtSize),
     i_NY_labelOffset,
     isActive = false
 )
 
// NY Open and IB Variables
var float nyOpenPrice = na
var int nyOpenBar = na
var float ibHigh = na
var float ibLow = na
 
// Opening Range Variables
var float orHigh = na
var float orLow = na
 
// Fib Level State - 20 slots: 0-9 project up from the anchor, 10-19 mirror down.
// IB/OR sources only use 0-9; single-level sources (NY Open / PD Close) use both
// halves depending on the Level Fib Direction input.
const int FIB_SLOTS = 20
var float[] fibLevels = array.new_float(FIB_SLOTS, na)
var label[] fibLabels = array.new_label(FIB_SLOTS, na)
var line[]  fibLines  = array.new_line(FIB_SLOTS, na)
 
// Previous-Day Close
var float prevDayClose = na
 
// NY Open, PD Close and IB Labels
var label nyOpenLab = label.new(bar_index, 0.0, text = "", style = label.style_label_left, color = transparent, textcolor = i_nyOpenColor, size = size.normal)
var label pdcLab    = label.new(bar_index, 0.0, text = "", style = label.style_label_left, color = transparent, textcolor = i_pdcColor, size = size.normal)
var label ibHighLab = label.new(bar_index, 0.0, text = "", style = label.style_label_left, color = transparent, textcolor = i_ibColor, size = size.normal)
var label ibLowLab  = label.new(bar_index, 0.0, text = "", style = label.style_label_left, color = transparent, textcolor = i_ibColor, size = size.normal)
 
// OR Labels
var label orHighLab = label.new(bar_index, 0.0, text = "", style = label.style_label_left, color = transparent, textcolor = i_orHighColor, size = size.normal)
var label orLowLab  = label.new(bar_index, 0.0, text = "", style = label.style_label_left, color = transparent, textcolor = i_orLowColor, size = size.normal)
 
// Prev-Day NY / LOD / HOD VWAP Labels
var label prevNYLab = label.new(bar_index, 0.0, text = "", style = label.style_label_left, color = transparent, textcolor = i_prevNYColor, size = size.normal)
var label lodLab    = label.new(bar_index, 0.0, text = "", style = label.style_label_left, color = transparent, textcolor = i_lodColor, size = size.normal)
var label hodLab    = label.new(bar_index, 0.0, text = "", style = label.style_label_left, color = transparent, textcolor = i_hodColor, size = size.normal)
 
// Session / NY std-dev band labels (U1/L1 .. U3/L3)
var label sessU1Lab = label.new(bar_index, 0.0, text = "", style = label.style_label_left, color = transparent, textcolor = i_bandColor1, size = i_bandLabSize)
var label sessL1Lab = label.new(bar_index, 0.0, text = "", style = label.style_label_left, color = transparent, textcolor = i_bandColor1, size = i_bandLabSize)
var label sessU2Lab = label.new(bar_index, 0.0, text = "", style = label.style_label_left, color = transparent, textcolor = i_bandColor2, size = i_bandLabSize)
var label sessL2Lab = label.new(bar_index, 0.0, text = "", style = label.style_label_left, color = transparent, textcolor = i_bandColor2, size = i_bandLabSize)
var label sessU3Lab = label.new(bar_index, 0.0, text = "", style = label.style_label_left, color = transparent, textcolor = i_bandColor3, size = i_bandLabSize)
var label sessL3Lab = label.new(bar_index, 0.0, text = "", style = label.style_label_left, color = transparent, textcolor = i_bandColor3, size = i_bandLabSize)
var label nyU1Lab   = label.new(bar_index, 0.0, text = "", style = label.style_label_left, color = transparent, textcolor = i_nyBandColor1, size = i_bandLabSize)
var label nyL1Lab   = label.new(bar_index, 0.0, text = "", style = label.style_label_left, color = transparent, textcolor = i_nyBandColor1, size = i_bandLabSize)
var label nyU2Lab   = label.new(bar_index, 0.0, text = "", style = label.style_label_left, color = transparent, textcolor = i_nyBandColor2, size = i_bandLabSize)
var label nyL2Lab   = label.new(bar_index, 0.0, text = "", style = label.style_label_left, color = transparent, textcolor = i_nyBandColor2, size = i_bandLabSize)
var label nyU3Lab   = label.new(bar_index, 0.0, text = "", style = label.style_label_left, color = transparent, textcolor = i_nyBandColor3, size = i_bandLabSize)
var label nyL3Lab   = label.new(bar_index, 0.0, text = "", style = label.style_label_left, color = transparent, textcolor = i_nyBandColor3, size = i_bandLabSize)
 
// Initialize Fib Labels and Lines
if barstate.isfirst
    for i = 0 to FIB_SLOTS - 1
        array.set(fibLabels, i, label.new(bar_index, 0.0, "", style = label.style_label_left, color = transparent, size = size.small))
        array.set(fibLines, i, line.new(bar_index, 0.0, bar_index, 0.0, color = transparent, extend = extend.none))
 
// Display configurations
var sessionVWAPdisplay = i_Session_showPriceScale ? display.pane + display.data_window + display.status_line + display.price_scale : display.pane + display.data_window + display.status_line
var cashVWAPdisplay = i_NY_showPriceScale ? display.data_window + display.status_line + display.price_scale : display.data_window + display.status_line
 
var int activeCashVWAP = 1
var bool showSessionVWAP = false
var bool firstRun = true
var bool hasExtendedHoursData = false
 
// Session VWAP Band values
var float upperBand1 = na
var float lowerBand1 = na
var float upperBand2 = na
var float lowerBand2 = na
var float upperBand3 = na
var float lowerBand3 = na
 
// NY VWAP Band values
var float nyUpperBand1 = na
var float nyLowerBand1 = na
var float nyUpperBand2 = na
var float nyLowerBand2 = na
var float nyUpperBand3 = na
var float nyLowerBand3 = na
 
// Prev-Day NY / LOD / HOD VWAP values
var float prevNYVwap = na
float lodVwap = na
float hodVwap = na
bool lodBreak = false
bool hodBreak = false
 
// ============================================================================
// FUNCTIONS
// ============================================================================
 
resetVWAP(myVWAP vwap) =>
    vwap.cumPV := 0.0
    vwap.cumVol := 0.0
    vwap.cumPV2 := 0.0
    vwap.vwap := 0.0
    vwap.stdev := na
 
updateVWAP(myVWAP vwap, bool showLabel, string labelText) =>
    if vwap.isActive
        vwap.cumPV += hlc3 * volume
        vwap.cumVol += volume
        vwap.cumPV2 += hlc3 * hlc3 * volume
        vwap.vwap := vwap.cumVol > 0 ? vwap.cumPV / vwap.cumVol : na
        // Volume-weighted variance: E[x^2] - (E[x])^2, clamped to >= 0
        float variance = vwap.cumVol > 0 ? (vwap.cumPV2 / vwap.cumVol) - (vwap.vwap * vwap.vwap) : na
        vwap.stdev := not na(variance) ? math.sqrt(math.max(variance, 0)) : na
 
        vwap.lab.set_x(bar_index + vwap.lab_offset)
        vwap.lab.set_y(vwap.vwap)
        vwap.lab.set_text(showLabel ? labelText : "")
        vwap.lab.set_tooltip(showLabel ? str.tostring(vwap.vwap, format.mintick) : "")
 
// Force-accumulate a VWAP instance regardless of its isActive flag. Used to keep the
// previous-day NY VWAP instance running with the current day's bars (Option 3 behavior),
// so it traces a moving line instead of freezing at a single value.
accumVWAP(myVWAP vwap) =>
    vwap.cumPV += hlc3 * volume
    vwap.cumVol += volume
    vwap.cumPV2 += hlc3 * hlc3 * volume
    vwap.vwap := vwap.cumVol > 0 ? vwap.cumPV / vwap.cumVol : na
 
calcHigherTimeframeVWAP(myVWAP vwap, simple string vwapPeriod, bool showLabel, string labelText) =>
    vwap.vwap := ta.vwap(hlc3, timeframe.change(vwapPeriod))
    vwap.lab.set_x(bar_index + vwap.lab_offset)
    vwap.lab.set_y(vwap.vwap)
    vwap.lab.set_text(showLabel ? labelText : "")
    vwap.lab.set_tooltip(showLabel ? str.tostring(vwap.vwap, format.mintick) : "")
 
// Generic style helper
f_getStyle(s) => s == "Solid" ? plot.linestyle_solid : s == "Dashed" ? plot.linestyle_dashed : plot.linestyle_dotted
 
// Encode a float for string-packing (na -> "nan"). Used to pack dashboard data
// into a single string so each request.security call costs only one plot output.
f_enc(float x) => na(x) ? "nan" : str.tostring(x)
 
// Decode the i-th packed value from a "|"-split array back into a float.
// str.tonumber returns na for "nan", restoring the original na values.
f_dec(string[] parts, int idx) => str.tonumber(array.get(parts, idx))
 
// Band label text: Name (+1σ VWAP), Std Dev (+1σ), Price, or Name + Price
f_bandLabText(float mult, bool upper, string prefix, float price) =>
    string sign = upper ? "+" : "-"
    string sigma = sign + str.tostring(mult, "#.##") + "σ"
    string name = sigma + " " + prefix
    string priceTxt = str.tostring(price, format.mintick)
    i_bandLabContent == "Name" ? name : i_bandLabContent == "Std Dev" ? sigma : i_bandLabContent == "Price" ? priceTxt : name + " " + priceTxt
 
// Update one band label (same style as nyOpenLab: set_xy / set_text / set_textcolor)
f_updateBandLab(label lab, bool show, float val, float mult, bool upper, string prefix, color col) =>
    if show and not na(val)
        lab.set_xy(bar_index + i_bandLabOffset, val)
        lab.set_text(f_bandLabText(mult, upper, prefix, val))
        lab.set_textcolor(col)
    else
        lab.set_text("")
 
// ----------------------------------------------------------------------------
// Dashboard data function - computes levels for any symbol via request.security.
// Uses a lightweight toggle-based NY VWAP (no HD) so it stays cheap across
// multiple securities, while remaining consistent in method with the chart.
// ----------------------------------------------------------------------------
f_calcDashData() =>
    bool newDay = timeframe.change("1D")
    // Session is anchored to the IB session start and runs through the rest of the
    // trading day (matches the chart's IB-driven session model).
    bool ibPeriod = not na(time(timeframe.period, i_ibSession, TIMEZONE))
    bool nyStart = ibPeriod and (ibPeriod != ibPeriod[1])
    var bool isSession = false
    if newDay
        isSession := false
    if nyStart
        isSession := true
 
    // Standard (full-day) VWAP - manual cumulative (avoids ta.vwap plot-count cost)
    var float stdPV = 0.0, var float stdVol = 0.0
    if newDay
        stdPV := hlc3 * volume, stdVol := volume
    else
        stdPV += hlc3 * volume, stdVol += volume
    float stdV = stdVol > 0 ? stdPV / stdVol : na
 
    // NY cash VWAP via two-accumulator toggle (current + previous day)
    var float s1 = 0.0, var float v1 = 0.0
    var float s2 = 0.0, var float v2 = 0.0
    var int toggleV = 0
    if nyStart
        if toggleV == 0
            s1 := hlc3 * volume, v1 := volume, toggleV := 1
        else
            s2 := hlc3 * volume, v2 := volume, toggleV := 0
    else if isSession
        if toggleV == 1
            s1 += hlc3 * volume, v1 += volume
        else
            s2 += hlc3 * volume, v2 += volume
    float nyV = toggleV == 1 ? (v1 > 0 ? s1 / v1 : na) : (v2 > 0 ? s2 / v2 : na)
    float pnV = toggleV == 1 ? (v2 > 0 ? s2 / v2 : na) : (v1 > 0 ? s1 / v1 : na)
 
    // LOD / HOD anchored VWAP - anchored to the regular-session low/high.
    // Extremes reset at NY open and are tracked only during the session, so the
    // VWAP re-anchors on each new RTH low/high (not at midnight).
    var float dLow = na, var float dHigh = na
    var float lodPV = 0.0, var float lodVol = 0.0
    var float hodPV = 0.0, var float hodVol = 0.0
    bool lodReanchor = false
    bool hodReanchor = false
    if nyStart
        dLow := low, dHigh := high
        lodReanchor := true, hodReanchor := true
    else if isSession
        if low < nz(dLow, 1e10)
            dLow := low
            lodReanchor := true
        if high > nz(dHigh, -1e10)
            dHigh := high
            hodReanchor := true
    if isSession
        if lodReanchor
            lodPV := hlc3 * volume, lodVol := volume
        else
            lodPV += hlc3 * volume, lodVol += volume
        if hodReanchor
            hodPV := hlc3 * volume, hodVol := volume
        else
            hodPV += hlc3 * volume, hodVol += volume
    float lodV = lodVol > 0 ? lodPV / lodVol : na
    float hodV = hodVol > 0 ? hodPV / hodVol : na
 
    // Initial Balance
    t_ib = time(timeframe.period, i_ibSession, TIMEZONE)
    bool ibStart = not na(t_ib) and na(t_ib[1])
    var float ibH = na, var float ibL = na
    if ibStart
        ibH := high, ibL := low
    else if not na(t_ib)
        ibH := math.max(ibH, high), ibL := math.min(ibL, low)
 
    // Opening Range - shares the IB start time, spans i_orMinutes from there
    var int orOpenT = na
    if ibStart
        orOpenT := time
    bool orInPeriod = not na(orOpenT) and (time - orOpenT) < (i_orMinutes * 60 * 1000)
    var float orH = na, var float orL = na
    if ibStart
        orH := high, orL := low
    else if orInPeriod
        orH := math.max(orH, high), orL := math.min(orL, low)
 
    var float nyo = na
    if nyStart
        nyo := open
 
    // Pack all values into a single string. This makes each request.security call
    // count as ONE plot output instead of twelve, keeping us under TradingView's
    // 64-output limit. Values are joined with "|" and unpacked on the chart side.
    // na values are encoded as the literal "nan".
    string packed = f_enc(close) + "|" + f_enc(nyV) + "|" + f_enc(stdV) + "|" + f_enc(pnV) + "|" + f_enc(lodV) + "|" + f_enc(hodV) + "|" + f_enc(orH) + "|" + f_enc(orL) + "|" + f_enc(ibH) + "|" + f_enc(ibL) + "|" + f_enc(nyo)
    packed
 
// Dashboard row filler - takes the packed string from f_calcDashData and unpacks it
f_fillRow(tbl, row, tkr, packed) =>
    dot = "●"
    parts = str.split(packed, "|")
    float c    = f_dec(parts, 0)
    float nyv  = f_dec(parts, 1)
    float stdv = f_dec(parts, 2)
    float pnv  = f_dec(parts, 3)
    float lodv = f_dec(parts, 4)
    float hodv = f_dec(parts, 5)
    float orh  = f_dec(parts, 6)
    float orl  = f_dec(parts, 7)
    float ibh  = f_dec(parts, 8)
    float ibl  = f_dec(parts, 9)
    float nyo  = f_dec(parts, 10)
    // Strip exchange prefix (e.g. "CME_MINI:NQ1!" -> "NQ1!") for a cleaner display
    tkrDisplay = str.contains(tkr, ":") ? array.get(str.split(tkr, ":"), 1) : tkr
    table.cell(tbl, 0, row, tkrDisplay, bgcolor = i_dashCellBg, text_color = i_dashBodyTxt, text_size = i_dashTextSize)
    table.cell(tbl, 1, row, dot, bgcolor = i_dashCellBg, text_color = c > nyo ? i_dashBull : i_dashBear, text_size = i_dashTextSize)
    table.cell(tbl, 2, row, dot, bgcolor = i_dashCellBg, text_color = c > nyv ? i_dashBull : i_dashBear, text_size = i_dashTextSize)
    table.cell(tbl, 3, row, dot, bgcolor = i_dashCellBg, text_color = c > stdv ? i_dashBull : i_dashBear, text_size = i_dashTextSize)
    table.cell(tbl, 4, row, dot, bgcolor = i_dashCellBg, text_color = c > pnv ? i_dashBull : i_dashBear, text_size = i_dashTextSize)
    table.cell(tbl, 5, row, dot, bgcolor = i_dashCellBg, text_color = c > lodv ? i_dashBull : i_dashBear, text_size = i_dashTextSize)
    table.cell(tbl, 6, row, dot, bgcolor = i_dashCellBg, text_color = c > hodv ? i_dashBull : i_dashBear, text_size = i_dashTextSize)
    table.cell(tbl, 7, row, c > orh ? "Above" : c < orl ? "Below" : "Inside", bgcolor = i_dashCellBg, text_color = i_dashBodyTxt, text_size = i_dashTextSize)
    table.cell(tbl, 8, row, c > ibh ? "Above" : c < ibl ? "Below" : "Inside", bgcolor = i_dashCellBg, text_color = i_dashBodyTxt, text_size = i_dashTextSize)
    table.cell(tbl, 9, row, c > orh and c > nyv ? "Bullish" : c < orl and c < nyv ? "Bearish" : "Neutral", bgcolor = i_dashCellBg, text_color = (c > orh and c > nyv) ? i_dashBull : (c < orl and c < nyv) ? i_dashBear : i_dashBodyTxt, text_size = i_dashTextSize)
 
// ============================================================================
// VOLUME VALIDATION
// ============================================================================
cumVolume = ta.cum(volume)
if barstate.islast and cumVolume == 0
    runtime.error("No volume is provided by the data vendor.")
 
// ============================================================================
// SESSION DETECTION
// ============================================================================
bool isExtendedSession = not na(time(timeframe.period, EXTENDED_SESSION, TIMEZONE))
bool isIBPeriod = not na(time(timeframe.period, i_ibSession, TIMEZONE))
bool isIBOpen = isIBPeriod and (isIBPeriod != isIBPeriod[1])
 
// Opening Range shares the IB session's start time and spans i_orMinutes from there.
// It opens with the IB and stays "in period" until orMinutes have elapsed past the open.
bool isOROpen = isIBOpen
var int orOpenTime = na
if isOROpen
    orOpenTime := time
bool isORPeriod = not na(orOpenTime) and (time - orOpenTime) < (i_orMinutes * 60 * 1000)
 
// The "current session" is anchored to the IB session start. It begins when the IB
// window opens and runs through the rest of the trading day (no hard end), so the
// NY/Current-Session VWAP, NY Open, LOD/HOD, fibs and bands all follow whatever
// IB session time the user sets. This replaces the old hardcoded 0930-1600 window.
bool isNewTradingDay = timeframe.change("1D")
var bool isMarketSession = false
if isNewTradingDay
    isMarketSession := false
if isIBOpen
    isMarketSession := true
bool isMarketOpen = isIBOpen
 
// ============================================================================
// PREVIOUS-DAY CLOSE
// ============================================================================
// Daily Bar Close: prior daily bar's close, pulled with lookahead_on + [1] so it is
// known from the first bar of the day and never repaints.
float pdcDaily = request.security(syminfo.tickerid, "D", close[1], lookahead = barmerge.lookahead_on)
 
// Session Close: the close of the final bar inside the Close Session window. Captured
// on the first bar AFTER the window ends (or on a new day when the chart has no
// out-of-session bars, e.g. RTH-only stock data), so it carries into the next session.
bool inCloseSess = not na(time(timeframe.period, i_pdcSession, TIMEZONE))
var float pdcSess = na
if inCloseSess[1] and (not inCloseSess or isNewTradingDay)
    pdcSess := close[1]
 
prevDayClose := i_pdcMode == "Daily Bar Close" ? pdcDaily : pdcSess
 
// ATR used as the 0→1 span when the fibs are anchored to a single level. Pulled from
// the last COMPLETED bar of the ATR timeframe ([1] + lookahead_on) so it is fixed for
// the whole session and never repaints.
float fibAtr = request.security(syminfo.tickerid, i_fibAtrTf, ta.atr(i_fibAtrLen)[1], lookahead = barmerge.lookahead_on)
 
// ============================================================================
// MAIN LOGIC
// ============================================================================
 
if firstRun
    firstRun := false
    if timeframe.isdaily or timeframe.isweekly
        label.delete(cashVWAP1.lab)
        label.delete(cashVWAP2.lab)
        label.delete(nyOpenLab)
        label.delete(pdcLab)
        label.delete(ibHighLab)
        label.delete(ibLowLab)
        label.delete(orHighLab)
        label.delete(orLowLab)
        label.delete(prevNYLab)
        label.delete(lodLab)
        label.delete(hodLab)
        label.delete(sessU1Lab)
        label.delete(sessL1Lab)
        label.delete(sessU2Lab)
        label.delete(sessL2Lab)
        label.delete(sessU3Lab)
        label.delete(sessL3Lab)
        label.delete(nyU1Lab)
        label.delete(nyL1Lab)
        label.delete(nyU2Lab)
        label.delete(nyL2Lab)
        label.delete(nyU3Lab)
        label.delete(nyL3Lab)
        for lab in fibLabels
            label.delete(lab)
        for ln in fibLines
            line.delete(ln)
    if not i_Session_enabled
        label.delete(sessionVWAP.lab)
 
if timeframe.isdaily
    if i_Session_enabled
        calcHigherTimeframeVWAP(sessionVWAP, "1W", i_Session_showlabel, i_Session_label)
else if timeframe.isweekly
    if i_Session_enabled
        calcHigherTimeframeVWAP(sessionVWAP, "1M", i_Session_showlabel, i_Session_label)
else if timeframe.isintraday
    chartMinutes = timeframe.in_seconds() / 60
    useHD = i_enableHD and chartMinutes > 5 and chartMinutes < 1440
 
    // -------------------------------------------------------------------------
    // NY Open & IB Logic
    // -------------------------------------------------------------------------
    if isMarketOpen
        nyOpenPrice := open
        nyOpenBar := bar_index
        for i = 0 to FIB_SLOTS - 1
            array.set(fibLevels, i, na)
 
    // Initial Balance - self-contained: seeds at its own session open and expands
    // through the IB window, so a custom IB session works for any market/open time.
    if isIBOpen
        ibHigh := high
        ibLow := low
    else if isIBPeriod
        ibHigh := math.max(nz(ibHigh, -1e10), high)
        ibLow := math.min(nz(ibLow, 1e10), low)
 
    // -------------------------------------------------------------------------
    // Opening Range Logic
    // -------------------------------------------------------------------------
    if isOROpen
        orHigh := high
        orLow := low
    else if isORPeriod
        orHigh := math.max(nz(orHigh, -1e10), high)
        orLow := math.min(nz(orLow, 1e10), low)
 
    // -------------------------------------------------------------------------
    // Fib Levels
    //   IB / OR source     : 0 = range low, 1 = range high (slots 0-9 only).
    //   NY Open / PD Close : the level is the 0 line; 1 / -1 = one ATR (fibAtr)
    //                        above / below it, projected Above (slots 0-9),
    //                        Below (slots 10-19), or Both.
    // -------------------------------------------------------------------------
    bool  fibIsLevelSrc = i_fibSource == "NY Open" or i_fibSource == "Previous Day Close"
    float fibAnchorHigh = i_fibSource == "Opening Range" ? orHigh : ibHigh
    float fibAnchorLow  = i_fibSource == "Opening Range" ? orLow  : ibLow
    float fibLevelBase  = i_fibSource == "NY Open" ? nyOpenPrice : prevDayClose
    float fibLevelSpan  = fibAtr
 
    bool[]  fibOn   = array.from(i_f1_on, i_f2_on, i_f3_on, i_f4_on, i_f5_on, i_f6_on, i_f7_on, i_f8_on, i_f9_on, i_f10_on)
    float[] fibVals = array.from(i_f1_val, i_f2_val, i_f3_val, i_f4_val, i_f5_val, i_f6_val, i_f7_val, i_f8_val, i_f9_val, i_f10_val)
 
    bool  lvlReady = not na(fibLevelBase) and not na(fibLevelSpan)
    bool  rngReady = not na(fibAnchorHigh) and not na(fibAnchorLow)
    float fibRange = fibAnchorHigh - fibAnchorLow
    bool  projUp   = i_fibLvlDir != "Below"
    bool  projDown = i_fibLvlDir != "Above"
 
    for i = 0 to 9
        bool  slotOn  = array.get(fibOn, i)
        float slotVal = array.get(fibVals, i)
        float upLev = fibIsLevelSrc
             ? (lvlReady and slotOn and projUp ? fibLevelBase + fibLevelSpan * slotVal : na)
             : (rngReady and slotOn ? fibAnchorLow + fibRange * slotVal : na)
        float dnLev = fibIsLevelSrc and lvlReady and slotOn and projDown ? fibLevelBase - fibLevelSpan * slotVal : na
        array.set(fibLevels, i,      upLev)
        array.set(fibLevels, i + 10, dnLev)
 
    // Update NY Open, PD Close and IB Labels
    if not na(nyOpenPrice) and i_showNYOpen and i_showNYOpenLabel
        nyOpenLab.set_xy(bar_index + i_openIBLabOffset, nyOpenPrice)
        nyOpenLab.set_text(i_nyOpenLabelText)
        nyOpenLab.set_textcolor(i_nyOpenColor)
    else
        nyOpenLab.set_text("")
 
    if not na(prevDayClose) and i_showPDC and i_showPDCLabel and isMarketSession
        pdcLab.set_xy(bar_index + i_openIBLabOffset, prevDayClose)
        pdcLab.set_text(i_pdcLabelText)
        pdcLab.set_textcolor(i_pdcColor)
    else
        pdcLab.set_text("")
 
    if not na(ibHigh) and i_showIB and i_showIBLabel
        ibHighLab.set_xy(bar_index + i_openIBLabOffset, ibHigh)
        ibHighLab.set_text(i_ibHighLabelText)
        ibHighLab.set_textcolor(i_ibColor)
    else
        ibHighLab.set_text("")
 
    if not na(ibLow) and i_showIB and i_showIBLabel
        ibLowLab.set_xy(bar_index + i_openIBLabOffset, ibLow)
        ibLowLab.set_text(i_ibLowLabelText)
        ibLowLab.set_textcolor(i_ibColor)
    else
        ibLowLab.set_text("")
 
    // Update OR Labels
    if not na(orHigh) and i_showORHigh and i_showORHighLabel
        orHighLab.set_xy(bar_index + i_openIBLabOffset, orHigh)
        orHighLab.set_text(i_orHighLabel)
        orHighLab.set_textcolor(i_orHighColor)
    else
        orHighLab.set_text("")
 
    if not na(orLow) and i_showORLow and i_showORLowLabel
        orLowLab.set_xy(bar_index + i_openIBLabOffset, orLow)
        orLowLab.set_text(i_orLowLabel)
        orLowLab.set_textcolor(i_orLowColor)
    else
        orLowLab.set_text("")
 
    // Update Fib Labels and Lines
    color[] fibColors = array.from(i_f1_col, i_f2_col, i_f3_col, i_f4_col, i_f5_col, i_f6_col, i_f7_col, i_f8_col, i_f9_col, i_f10_col)
    fibLineStyleVal = i_fibStyle == "Solid" ? line.style_solid : i_fibStyle == "Dashed" ? line.style_dashed : line.style_dotted
 
    for i = 0 to FIB_SLOTS - 1
        int slot = i % 10                       // slots 10-19 share slot 0-9's value/color
        bool isDown = i >= 10                    // mirrored (below-level) projection
        lab = array.get(fibLabels, i)
        ln  = array.get(fibLines, i)
        lev = array.get(fibLevels, i)
        // Draw the level as a horizontal line anchored at the NY open, extended right.
        // The level value settles once the IB/OR anchor range is complete.
        if not na(lev) and isMarketSession and not na(nyOpenBar)
            line.set_xy1(ln, nyOpenBar, lev)
            line.set_xy2(ln, bar_index, lev)
            line.set_color(ln, array.get(fibColors, slot))
            line.set_style(ln, fibLineStyleVal)
            line.set_width(ln, 1)
            line.set_extend(ln, extend.right)
        else
            line.set_color(ln, transparent)
            line.set_extend(ln, extend.none)
        // Label - below-level projections show a negative ratio (e.g. "-0.618")
        if not na(lev) and i_showFibLabs and isMarketSession
            lab.set_xy(bar_index + i_openIBLabOffset, lev)
            lab.set_textcolor(array.get(fibColors, slot))
            float ratio = array.get(fibVals, slot) * (isDown ? -1.0 : 1.0)
            txt = i_fibLabType == "Level" ? str.tostring(ratio, "#.###") : str.tostring(lev, format.mintick)
            lab.set_text(txt)
        else
            lab.set_text("")
 
    // -------------------------------------------------------------------------
    // Cash VWAP Logic (with 5-min HD precision)
    // -------------------------------------------------------------------------
    var float[] pvArray_hd = array.new_float(0)
    var float[] volArray_hd = array.new_float(0)
    var float[] pv2Array_hd = array.new_float(0)
    var int lastResetDay_hd = -1
    float nyVwapHD = na
    float nyStdevHD = na
 
    if useHD
        // Derive the session-start hour/minute from the IB session input (format "HHMM-HHMM")
        // so the HD reset matches whatever session start the user configured.
        sessStartStr = str.substring(i_ibSession, 0, 4)
        sessStartHour = math.round(str.tonumber(str.substring(sessStartStr, 0, 2)))
        sessStartMin  = math.round(str.tonumber(str.substring(sessStartStr, 2, 4)))
        [hlc3Array, volArray, timeArray] = request.security_lower_tf(syminfo.tickerid, "5", [hlc3, volume, time])
        if array.size(hlc3Array) > 0
            for i = 0 to array.size(hlc3Array) - 1
                barTime = array.get(timeArray, i)
                barHlc3 = array.get(hlc3Array, i)
                barVol = array.get(volArray, i)
                d = dayofmonth(barTime, TIMEZONE)
                isSessStart = (hour(barTime, TIMEZONE) == sessStartHour and minute(barTime, TIMEZONE) == sessStartMin)
                if isSessStart and d != lastResetDay_hd
                    array.clear(pvArray_hd)
                    array.clear(volArray_hd)
                    array.clear(pv2Array_hd)
                    lastResetDay_hd := d
                if barVol > 0
                    array.push(pvArray_hd, barHlc3 * barVol)
                    array.push(volArray_hd, barVol)
                    array.push(pv2Array_hd, barHlc3 * barHlc3 * barVol)
            if array.size(pvArray_hd) > 0
                float sumVol = array.sum(volArray_hd)
                nyVwapHD := sumVol > 0 ? array.sum(pvArray_hd) / sumVol : na
                if not na(nyVwapHD)
                    float varHD = (array.sum(pv2Array_hd) / sumVol) - (nyVwapHD * nyVwapHD)
                    nyStdevHD := math.sqrt(math.max(varHD, 0))
 
    if isMarketOpen
        if activeCashVWAP == 1
            activeCashVWAP := 2
            cashVWAP1.isActive := false, cashVWAP2.isActive := true
            cashVWAP1.lab.set_text(""), cashVWAP1.lab.set_tooltip("")
            resetVWAP(cashVWAP2)
            if useHD and not na(nyVwapHD)
                cashVWAP2.vwap := nyVwapHD
                cashVWAP2.stdev := nyStdevHD
                cashVWAP2.lab.set_xy(bar_index + cashVWAP2.lab_offset, cashVWAP2.vwap)
                cashVWAP2.lab.set_text(i_NY_showlabel ? i_NY_label : "")
            else
                updateVWAP(cashVWAP2, i_NY_showlabel, i_NY_label)
        else
            activeCashVWAP := 1
            cashVWAP1.isActive := true, cashVWAP2.isActive := false
            cashVWAP2.lab.set_text(""), cashVWAP2.lab.set_tooltip("")
            resetVWAP(cashVWAP1)
            if useHD and not na(nyVwapHD)
                cashVWAP1.vwap := nyVwapHD
                cashVWAP1.stdev := nyStdevHD
                cashVWAP1.lab.set_xy(bar_index + cashVWAP1.lab_offset, cashVWAP1.vwap)
                cashVWAP1.lab.set_text(i_NY_showlabel ? i_NY_label : "")
            else
                updateVWAP(cashVWAP1, i_NY_showlabel, i_NY_label)
    else
        if useHD and not na(nyVwapHD)
            cur = cashVWAP1.isActive ? cashVWAP1 : cashVWAP2
            cur.vwap := nyVwapHD
            cur.stdev := nyStdevHD
            cur.lab.set_xy(bar_index + cur.lab_offset, cur.vwap)
            cur.lab.set_text(i_NY_showlabel ? i_NY_label : "")
        else if isMarketSession
            updateVWAP(cashVWAP1, i_NY_showlabel, i_NY_label)
            updateVWAP(cashVWAP2, i_NY_showlabel, i_NY_label)
 
    // -------------------------------------------------------------------------
    // Prev-Day NY VWAP (Option 3): the inactive instance keeps accumulating with
    // today's bars, continuing yesterday's VWAP so it traces a moving line.
    // -------------------------------------------------------------------------
    myVWAP prevInst = cashVWAP1.isActive ? cashVWAP2 : cashVWAP1
    if i_showPrevNY and not na(prevInst.vwap)
        if isMarketSession
            accumVWAP(prevInst)
        prevNYVwap := prevInst.vwap
    else
        prevNYVwap := na
 
    // NY VWAP Bands - computed from the active cash VWAP's volume-weighted stdev
    cashCur = cashVWAP1.isActive ? cashVWAP1 : cashVWAP2
    float nyVwapVal = cashCur.vwap
    float nyStdevVal = cashCur.stdev
    bool showNYBands = isMarketSession and not na(nyVwapVal) and not na(nyStdevVal) and not session.islastbar
    nyUpperBand1 := showNYBands ? nyVwapVal + nyStdevVal * i_nyBandMult1 : na
    nyLowerBand1 := showNYBands ? nyVwapVal - nyStdevVal * i_nyBandMult1 : na
    nyUpperBand2 := showNYBands ? nyVwapVal + nyStdevVal * i_nyBandMult2 : na
    nyLowerBand2 := showNYBands ? nyVwapVal - nyStdevVal * i_nyBandMult2 : na
    nyUpperBand3 := showNYBands ? nyVwapVal + nyStdevVal * i_nyBandMult3 : na
    nyLowerBand3 := showNYBands ? nyVwapVal - nyStdevVal * i_nyBandMult3 : na
 
    // -------------------------------------------------------------------------
    // LOD / HOD Anchored VWAP
    // Anchored to the regular-session (NY cash) low and high. The day extremes
    // reset at the NY market open (not midnight) and are only tracked during the
    // session, so the VWAP re-anchors whenever price prints a new RTH low/high.
    // -------------------------------------------------------------------------
    var float dayLow = na, var float dayHigh = na
    var float lodPV = 0.0, var float lodVol = 0.0
    var float hodPV = 0.0, var float hodVol = 0.0
    bool lodReanchor = false
    bool hodReanchor = false
    bool lodMidSession = false
    bool hodMidSession = false
    if isMarketOpen
        dayLow := low, dayHigh := high
        lodReanchor := true, hodReanchor := true
    else if isMarketSession
        if low < nz(dayLow, 1e10)
            dayLow := low
            lodReanchor := true
            lodMidSession := true
        if high > nz(dayHigh, -1e10)
            dayHigh := high
            hodReanchor := true
            hodMidSession := true
    // LOD VWAP: re-anchor (reset accumulation) on each new session low
    if isMarketSession
        if lodReanchor
            lodPV := hlc3 * volume, lodVol := volume
        else
            lodPV += hlc3 * volume, lodVol += volume
        if hodReanchor
            hodPV := hlc3 * volume, hodVol := volume
        else
            hodPV += hlc3 * volume, hodVol += volume
    lodVwap := lodVol > 0 ? lodPV / lodVol : na
    hodVwap := hodVol > 0 ? hodPV / hodVol : na
    // Break the plotted line at a mid-session re-anchor so the old segment ends and
    // a fresh one starts at the new extreme (no vertical connector between them).
    lodBreak := lodMidSession
    hodBreak := hodMidSession
 
    // -------------------------------------------------------------------------
    // Session VWAP Logic
    // -------------------------------------------------------------------------
    if i_Session_enabled
        if isExtendedSession and not hasExtendedHoursData
            hasExtendedHoursData := true, showSessionVWAP := true
 
    isNewDay = timeframe.change("1D")
    [vwapStd, stdevUpperStd, _] = ta.vwap(hlc3, isNewDay, 1)
    stdevAbsStd = stdevUpperStd - vwapStd
 
    float vwapVal = vwapStd, float stdevAbs = stdevAbsStd
    if useHD
        vH = request.security_lower_tf(syminfo.tickerid, "5", ta.vwap(hlc3, timeframe.change("1D")))
        vwapVal := array.size(vH) > 0 ? array.last(vH) : na
        [_, sUH, _] = ta.vwap(hlc3, timeframe.change("1D"), 1)
        sH = request.security_lower_tf(syminfo.tickerid, "5", sUH)
        stdevAbs := array.size(sH) > 0 ? nz(array.last(sH)) - nz(vwapVal) : na
 
    if i_Session_enabled and showSessionVWAP
        sessionVWAP.vwap := vwapVal
        sessionVWAP.lab.set_xy(bar_index + sessionVWAP.lab_offset, sessionVWAP.vwap)
        sessionVWAP.lab.set_text(i_Session_showlabel ? i_Session_label : "")
 
    showBands = i_Session_enabled and showSessionVWAP and not session.islastbar
    upperBand1 := showBands ? vwapVal + stdevAbs * i_bandMult1 : na
    lowerBand1 := showBands ? vwapVal - stdevAbs * i_bandMult1 : na
    upperBand2 := showBands ? vwapVal + stdevAbs * i_bandMult2 : na
    lowerBand2 := showBands ? vwapVal - stdevAbs * i_bandMult2 : na
    upperBand3 := showBands ? vwapVal + stdevAbs * i_bandMult3 : na
    lowerBand3 := showBands ? vwapVal - stdevAbs * i_bandMult3 : na
 
    // -------------------------------------------------------------------------
    // Session / NY std-dev band labels
    // -------------------------------------------------------------------------
    f_updateBandLab(sessU1Lab, i_showSessBandLabs and i_showBand1 and i_Session_enabled, upperBand1, i_bandMult1, true,  i_sessBandPrefix, i_bandColor1)
    f_updateBandLab(sessL1Lab, i_showSessBandLabs and i_showBand1 and i_Session_enabled, lowerBand1, i_bandMult1, false, i_sessBandPrefix, i_bandColor1)
    f_updateBandLab(sessU2Lab, i_showSessBandLabs and i_showBand2 and i_Session_enabled, upperBand2, i_bandMult2, true,  i_sessBandPrefix, i_bandColor2)
    f_updateBandLab(sessL2Lab, i_showSessBandLabs and i_showBand2 and i_Session_enabled, lowerBand2, i_bandMult2, false, i_sessBandPrefix, i_bandColor2)
    f_updateBandLab(sessU3Lab, i_showSessBandLabs and i_showBand3 and i_Session_enabled, upperBand3, i_bandMult3, true,  i_sessBandPrefix, i_bandColor3)
    f_updateBandLab(sessL3Lab, i_showSessBandLabs and i_showBand3 and i_Session_enabled, lowerBand3, i_bandMult3, false, i_sessBandPrefix, i_bandColor3)
 
    f_updateBandLab(nyU1Lab, i_showNYBandLabs and i_showNYBand1, nyUpperBand1, i_nyBandMult1, true,  i_nyBandPrefix, i_nyBandColor1)
    f_updateBandLab(nyL1Lab, i_showNYBandLabs and i_showNYBand1, nyLowerBand1, i_nyBandMult1, false, i_nyBandPrefix, i_nyBandColor1)
    f_updateBandLab(nyU2Lab, i_showNYBandLabs and i_showNYBand2, nyUpperBand2, i_nyBandMult2, true,  i_nyBandPrefix, i_nyBandColor2)
    f_updateBandLab(nyL2Lab, i_showNYBandLabs and i_showNYBand2, nyLowerBand2, i_nyBandMult2, false, i_nyBandPrefix, i_nyBandColor2)
    f_updateBandLab(nyU3Lab, i_showNYBandLabs and i_showNYBand3, nyUpperBand3, i_nyBandMult3, true,  i_nyBandPrefix, i_nyBandColor3)
    f_updateBandLab(nyL3Lab, i_showNYBandLabs and i_showNYBand3, nyLowerBand3, i_nyBandMult3, false, i_nyBandPrefix, i_nyBandColor3)
 
    // -------------------------------------------------------------------------
    // Prev-Day NY / LOD / HOD VWAP Labels
    // -------------------------------------------------------------------------
    if i_showPrevNY and i_showPrevNYLabel and not na(prevNYVwap) and isMarketSession
        prevNYLab.set_xy(bar_index + i_NY_labelOffset, prevNYVwap)
        prevNYLab.set_text(i_prevNYLabel)
        prevNYLab.set_textcolor(i_prevNYColor)
    else
        prevNYLab.set_text("")
 
    if i_showLOD and i_showLODLabel and not na(lodVwap) and isMarketSession
        lodLab.set_xy(bar_index + i_NY_labelOffset, lodVwap)
        lodLab.set_text(i_lodLabel)
        lodLab.set_textcolor(i_lodColor)
    else
        lodLab.set_text("")
 
    if i_showHOD and i_showHODLabel and not na(hodVwap) and isMarketSession
        hodLab.set_xy(bar_index + i_NY_labelOffset, hodVwap)
        hodLab.set_text(i_hodLabel)
        hodLab.set_textcolor(i_hodColor)
    else
        hodLab.set_text("")
 
// ============================================================================
// DASHBOARD EXECUTION
// ============================================================================
// Pull per-symbol level data as a single packed string per ticker. Requesting one
// string (instead of a 12-value tuple) keeps each security call to ONE plot output,
// avoiding TradingView's 64-output limit.
string dash1 = request.security(i_dashTicker1, timeframe.period, f_calcDashData())
string dash2 = request.security(i_dashTicker2, timeframe.period, f_calcDashData())
string dash3 = request.security(i_dashTicker3, timeframe.period, f_calcDashData())
 
var table monitorTable = table.new(i_dashPos, 10, 4, border_width = i_dashBorderW, border_color = i_dashBorderCol)
 
if barstate.islast and i_showDashboard and timeframe.isintraday
    headers = array.from("Ticker", "NY Open", "NY VWAP", "Overnight", "PD NY", "LOD VWAP", "HOD VWAP", "OR Range", "IB Range", "Bias")
    for j = 0 to 9
        table.cell(monitorTable, j, 0, array.get(headers, j), bgcolor = i_dashHeaderBg, text_color = i_dashHeaderTxt, text_size = i_dashTextSize)
 
    f_fillRow(monitorTable, 1, i_dashTicker1, dash1)
    f_fillRow(monitorTable, 2, i_dashTicker2, dash2)
    f_fillRow(monitorTable, 3, i_dashTicker3, dash3)
 
// ============================================================================
// PLOTS
// ============================================================================
 
// NY Open, PD Close, IB, OR
plot(i_showNYOpen and isMarketSession ? nyOpenPrice : na, "NY Open", i_nyOpenColor, 1, plot.style_linebr, linestyle = f_getStyle(i_nyOpenStyle))
plot(i_showPDC and isMarketSession ? prevDayClose : na, "PD Close", i_pdcColor, i_pdcWidth, plot.style_linebr, linestyle = f_getStyle(i_pdcStyle))
plot(i_showIB and (isMarketSession or isIBPeriod) ? ibHigh : na, "IB High", i_ibColor, i_ibWidth, plot.style_linebr, linestyle = f_getStyle(i_ibStyle))
plot(i_showIB and (isMarketSession or isIBPeriod) ? ibLow : na, "IB Low", i_ibColor, i_ibWidth, plot.style_linebr, linestyle = f_getStyle(i_ibStyle))
plot(i_showORHigh and isMarketSession ? orHigh : na, "OR High", i_orHighColor, i_orHighWidth, plot.style_linebr, linestyle = f_getStyle(i_orHighStyle))
plot(i_showORLow and isMarketSession ? orLow : na, "OR Low", i_orLowColor, i_orLowWidth, plot.style_linebr, linestyle = f_getStyle(i_orLowStyle))
 
// IB/OR Fib levels are drawn as line objects (see fib line logic above), not plots,
// to keep within TradingView's 64-plot limit.
 
// Session VWAP
plot(i_Session_enabled ? sessionVWAP.vwap : na, "Session VWAP", i_Session_color, i_Session_width, plot.style_linebr, display = sessionVWAPdisplay, linestyle = f_getStyle(i_Session_style))
 
// Session Bands
p_u1 = plot(upperBand1, "U1", i_bandColor1, style = plot.style_linebr, display = i_showBand1 and i_Session_enabled ? (i_bandPriceScale1 ? display.pane + display.price_scale : display.pane) : display.none, linestyle = f_getStyle(i_bandStyle1))
p_l1 = plot(lowerBand1, "L1", i_bandColor1, style = plot.style_linebr, display = i_showBand1 and i_Session_enabled ? (i_bandPriceScale1 ? display.pane + display.price_scale : display.pane) : display.none, linestyle = f_getStyle(i_bandStyle1))
fill(p_u1, p_l1, color = i_bandFill1, display = i_showBand1 and i_Session_enabled ? display.all : display.none)
 
p_u2 = plot(upperBand2, "U2", i_bandColor2, style = plot.style_linebr, display = i_showBand2 and i_Session_enabled ? (i_bandPriceScale2 ? display.pane + display.price_scale : display.pane) : display.none, linestyle = f_getStyle(i_bandStyle2))
p_l2 = plot(lowerBand2, "L2", i_bandColor2, style = plot.style_linebr, display = i_showBand2 and i_Session_enabled ? (i_bandPriceScale2 ? display.pane + display.price_scale : display.pane) : display.none, linestyle = f_getStyle(i_bandStyle2))
fill(p_u2, p_l2, color = i_bandFill2, display = i_showBand2 and i_Session_enabled ? display.all : display.none)
 
p_u3 = plot(upperBand3, "U3", i_bandColor3, style = plot.style_linebr, display = i_showBand3 and i_Session_enabled ? (i_bandPriceScale3 ? display.pane + display.price_scale : display.pane) : display.none, linestyle = f_getStyle(i_bandStyle3))
p_l3 = plot(lowerBand3, "L3", i_bandColor3, style = plot.style_linebr, display = i_showBand3 and i_Session_enabled ? (i_bandPriceScale3 ? display.pane + display.price_scale : display.pane) : display.none, linestyle = f_getStyle(i_bandStyle3))
fill(p_u3, p_l3, color = i_bandFill3, display = i_showBand3 and i_Session_enabled ? display.all : display.none)
 
// NY VWAP Bands
nu1 = plot(nyUpperBand1, "NY U1", i_nyBandColor1, style = plot.style_linebr, display = i_showNYBand1 ? (i_nyBandPriceScale1 ? display.pane + display.price_scale : display.pane) : display.none, linestyle = f_getStyle(i_nyBandStyle1))
nl1 = plot(nyLowerBand1, "NY L1", i_nyBandColor1, style = plot.style_linebr, display = i_showNYBand1 ? (i_nyBandPriceScale1 ? display.pane + display.price_scale : display.pane) : display.none, linestyle = f_getStyle(i_nyBandStyle1))
fill(nu1, nl1, color = i_nyBandFill1, display = i_showNYBand1 ? display.all : display.none)
 
nu2 = plot(nyUpperBand2, "NY U2", i_nyBandColor2, style = plot.style_linebr, display = i_showNYBand2 ? (i_nyBandPriceScale2 ? display.pane + display.price_scale : display.pane) : display.none, linestyle = f_getStyle(i_nyBandStyle2))
nl2 = plot(nyLowerBand2, "NY L2", i_nyBandColor2, style = plot.style_linebr, display = i_showNYBand2 ? (i_nyBandPriceScale2 ? display.pane + display.price_scale : display.pane) : display.none, linestyle = f_getStyle(i_nyBandStyle2))
fill(nu2, nl2, color = i_nyBandFill2, display = i_showNYBand2 ? display.all : display.none)
 
nu3 = plot(nyUpperBand3, "NY U3", i_nyBandColor3, style = plot.style_linebr, display = i_showNYBand3 ? (i_nyBandPriceScale3 ? display.pane + display.price_scale : display.pane) : display.none, linestyle = f_getStyle(i_nyBandStyle3))
nl3 = plot(nyLowerBand3, "NY L3", i_nyBandColor3, style = plot.style_linebr, display = i_showNYBand3 ? (i_nyBandPriceScale3 ? display.pane + display.price_scale : display.pane) : display.none, linestyle = f_getStyle(i_nyBandStyle3))
fill(nu3, nl3, color = i_nyBandFill3, display = i_showNYBand3 ? display.all : display.none)
 
// Cash VWAP
cv = cashVWAP1.isActive ? cashVWAP1.vwap : cashVWAP2.vwap
plot(isMarketSession ? cv : na, "Cash VWAP", i_NY_color, i_NY_width, plot.style_linebr, display = cashVWAPdisplay, linestyle = f_getStyle(i_NY_style))
plot(isMarketSession and cashVWAP1.isActive ? cashVWAP1.vwap : na, "C1", i_NY_color, i_NY_width, plot.style_linebr, display = display.pane, linestyle = f_getStyle(i_NY_style))
plot(isMarketSession and cashVWAP2.isActive ? cashVWAP2.vwap : na, "C2", i_NY_color, i_NY_width, plot.style_linebr, display = display.pane, linestyle = f_getStyle(i_NY_style))
 
// Prev-Day NY / LOD / HOD VWAP
plot(i_showPrevNY and isMarketSession ? prevNYVwap : na, "Prev-Day NY VWAP", i_prevNYColor, i_prevNYWidth, plot.style_linebr, linestyle = f_getStyle(i_prevNYStyle))
plot(i_showLOD and isMarketSession and not lodBreak ? lodVwap : na, "LOD VWAP", i_lodColor, i_lodWidth, plot.style_linebr, linestyle = f_getStyle(i_lodStyle))
plot(i_showHOD and isMarketSession and not hodBreak ? hodVwap : na, "HOD VWAP", i_hodColor, i_hodWidth, plot.style_linebr, linestyle = f_getStyle(i_hodStyle))

← 返回列表