V3.5 - Same-Time Volume Comparison | By ArtOfNoise

alwalston · study · 224 行 · 点赞 4 · 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/
// © alwalston
 
//@version=6
indicator("V3.5 - Same-Time Volume Comparison | By Art Lee",
     shorttitle="ArtOfNoise",
     overlay=true)
//--------------------------------------------------
// SETTINGS
//--------------------------------------------------
sessionInput = input.session("0930-1600:23456", "Trading Session")
timezoneInput = input.string("America/New_York", "Session Time Zone")
 
showDashboard = input.bool(true, "Show Volume Dashboard")
 
//--------------------------------------------------
// DASHBOARD COLOR SETTINGS
//--------------------------------------------------
dashboardTextColor = input.color(color.white, "Dashboard Font Color", group="Dashboard Colors")
 
dashboardBgColor = input.color(color.rgb(55, 55, 55), "Dashboard Background", group="Dashboard Colors")
 
headerBgColor = input.color(color.navy, "Header Background", group="Dashboard Colors")
 
positiveBgColor = input.color(color.green, "Positive Volume Background", group="Dashboard Colors")
 
negativeBgColor = input.color(color.red, "Negative Volume Background", group="Dashboard Colors")
 
neutralBgColor = input.color(color.orange, "Neutral Volume Background", group="Dashboard Colors")
 
//--------------------------------------------------
// TIMEFRAME CHECK
//--------------------------------------------------
supportedTF = timeframe.isminutes and (timeframe.multiplier == 5 or timeframe.multiplier == 30 or timeframe.multiplier == 60)
 
//--------------------------------------------------
// SESSION DETECTION
//--------------------------------------------------
inSession = not na(time(timeframe.period, sessionInput, timezoneInput))
newSession = inSession and (bar_index == 0 or not inSession[1])
 
//--------------------------------------------------
// VOLUME ARRAYS
//--------------------------------------------------
var array<float> currentSession = array.new_float()
var array<float> previousSession = array.new_float()
 
var float cumulativeVolume = 0.0
 
//--------------------------------------------------
// RESET AND SAVE PREVIOUS SESSION
//--------------------------------------------------
if newSession
    if array.size(currentSession) > 0
        previousSession := array.copy(currentSession)
 
    array.clear(currentSession)
    cumulativeVolume := 0.0
 
//--------------------------------------------------
// BUILD CURRENT SESSION CUMULATIVE VOLUME
//--------------------------------------------------
if inSession
    cumulativeVolume += nz(volume, 0)
    array.push(currentSession, cumulativeVolume)
 
//--------------------------------------------------
// SAME-TIME PREVIOUS SESSION COMPARISON
//--------------------------------------------------
currentBarIndex = array.size(currentSession) - 1
 
previousSameTime = array.size(previousSession) > currentBarIndex and currentBarIndex >= 0 ? array.get(previousSession, currentBarIndex) : na
 
previousFullSession = array.size(previousSession) > 0 ? array.get(previousSession, array.size(previousSession) - 1) : na
 
//--------------------------------------------------
// VOLUME DIFFERENCE
//--------------------------------------------------
volumeDifference = not na(previousSameTime) ? cumulativeVolume - previousSameTime : na
 
//--------------------------------------------------
// RELATIVE VOLUME CHANGE (%)
//--------------------------------------------------
relativeVolumeChange = not na(previousSameTime) and previousSameTime > 0 ?
     ((cumulativeVolume - previousSameTime) / previousSameTime) * 100 : na
 
//--------------------------------------------------
// VOLUME STRENGTH
//--------------------------------------------------
strength =
     na(relativeVolumeChange) ? "WAITING" :
     relativeVolumeChange >= 25 ? "VERY STRONG" :
     relativeVolumeChange >= 10 ? "STRONG" :
     relativeVolumeChange > -10 ? "NORMAL" :
     relativeVolumeChange > -25 ? "WEAK" :
     "VERY WEAK"
 
//--------------------------------------------------
// DISPLAY TEXT
//--------------------------------------------------
volumeText = str.tostring(cumulativeVolume, format.volume)
 
previousText = na(previousSameTime) ? "N/A" :
     str.tostring(previousSameTime, format.volume)
 
yesterdayText = na(previousFullSession) ? "N/A" :
     str.tostring(previousFullSession, format.volume)
 
differenceText = na(volumeDifference) ? "N/A" :
     (volumeDifference >= 0 ? "+" : "") +
     str.tostring(volumeDifference, format.volume)
 
relativeChangeText = na(relativeVolumeChange) ? "N/A" :
     (relativeVolumeChange >= 0 ? "+" : "") +
     str.tostring(relativeVolumeChange, "#.##") + "%"
 
//--------------------------------------------------
// CUSTOMIZABLE HIGHLIGHT COLORS
//--------------------------------------------------
relativeChangeColor = na(relativeVolumeChange) ? neutralBgColor :
     relativeVolumeChange > 0 ? positiveBgColor :
     relativeVolumeChange < 0 ? negativeBgColor :
     neutralBgColor
 
strengthColor = na(relativeVolumeChange) ? neutralBgColor :
     relativeVolumeChange >= 10 ? positiveBgColor :
     relativeVolumeChange <= -10 ? negativeBgColor :
     neutralBgColor
 
//--------------------------------------------------
// DASHBOARD STYLE
//--------------------------------------------------
boldWhite = dashboardTextColor
cellBackground = dashboardBgColor
headerColor = headerBgColor
 
//--------------------------------------------------
// DASHBOARD
//--------------------------------------------------
var table dashboard = table.new(position.top_right, 2, 9, border_width=1)
 
if barstate.islast and showDashboard
 
    table.cell(dashboard, 0, 0, "VOLUME COMPARISON",
         bgcolor=headerColor, text_color=boldWhite,
         text_formatting=text.format_bold)
 
    table.cell(dashboard, 1, 0, "LIVE",
         bgcolor=headerColor, text_color=boldWhite,
         text_formatting=text.format_bold)
 
    table.cell(dashboard, 0, 1, "Chart Timeframe",
         bgcolor=cellBackground, text_color=boldWhite,
         text_formatting=text.format_bold)
 
    table.cell(dashboard, 1, 1, timeframe.period + " min",
         bgcolor=cellBackground, text_color=boldWhite,
         text_formatting=text.format_bold)
 
    table.cell(dashboard, 0, 2, "Yesterday Full Session",
         bgcolor=cellBackground, text_color=boldWhite,
         text_formatting=text.format_bold)
 
    table.cell(dashboard, 1, 2, yesterdayText,
         bgcolor=cellBackground, text_color=boldWhite,
         text_formatting=text.format_bold)
 
    table.cell(dashboard, 0, 3, "Today Cumulative",
         bgcolor=cellBackground, text_color=boldWhite,
         text_formatting=text.format_bold)
 
    table.cell(dashboard, 1, 3, volumeText,
         bgcolor=cellBackground, text_color=boldWhite,
         text_formatting=text.format_bold)
 
    table.cell(dashboard, 0, 4, "Prior Session Same Time",
         bgcolor=cellBackground, text_color=boldWhite,
         text_formatting=text.format_bold)
 
    table.cell(dashboard, 1, 4, previousText,
         bgcolor=cellBackground, text_color=boldWhite,
         text_formatting=text.format_bold)
 
    table.cell(dashboard, 0, 5, "Volume Difference",
         bgcolor=cellBackground, text_color=boldWhite,
         text_formatting=text.format_bold)
 
    table.cell(dashboard, 1, 5, differenceText,
         bgcolor=cellBackground, text_color=boldWhite,
         text_formatting=text.format_bold)
 
    table.cell(dashboard, 0, 6, "RELATIVE VOLUME CHANGE",
         bgcolor=cellBackground, text_color=boldWhite,
         text_formatting=text.format_bold)
 
    table.cell(dashboard, 1, 6, relativeChangeText,
         bgcolor=relativeChangeColor, text_color=boldWhite,
         text_formatting=text.format_bold)
 
    table.cell(dashboard, 0, 7, "Volume Strength",
         bgcolor=cellBackground, text_color=boldWhite,
         text_formatting=text.format_bold)
 
    table.cell(dashboard, 1, 7, strength,
         bgcolor=strengthColor, text_color=boldWhite,
         text_formatting=text.format_bold)
 
    statusText = not supportedTF ? "USE 5m / 30m / 1H" :
         na(previousSameTime) ? "WAITING FOR MATCH" :
         "COMPARISON ACTIVE"
 
    table.cell(dashboard, 0, 8, "Status",
         bgcolor=cellBackground, text_color=boldWhite,
         text_formatting=text.format_bold)
 
    table.cell(dashboard, 1, 8, statusText,
         bgcolor=cellBackground, text_color=boldWhite,
         text_formatting=text.format_bold)
 
//--------------------------------------------------
// HIDE DASHBOARD WHEN DISABLED
//--------------------------------------------------
if barstate.islast and not showDashboard
    table.clear(dashboard, 0, 0, 1, 8)

← 返回列表