Session Liquidity Levels - Pad

Maverick_Investor · study · 309 行 · 点赞 29 · TradingView 原页

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

Pine Script

//@version=6
indicator("Session Liquidity Levels - Pad", overlay=true)
 
// ============================================================================
// SETTINGS
// ============================================================================
 
// ----- General
groupGeneral = "General Settings"
 
lineWidth = input.int(
     2,
     "Line Width",
     minval = 1,
     maxval = 5,
     group = groupGeneral)
 
showLabels = input.bool(
     true,
     "Show Labels",
     group = groupGeneral)
 
 
// ----- Sessions
groupSessions = "Session Times - New York Time"
 
asiaSession = input.session(
     "1900-0000",
     "Asia Session",
     group = groupSessions)
 
londonSession = input.session(
     "0200-0500",
     "London Session",
     group = groupSessions)
 
nySession = input.session(
     "0930-1600",
     "New York Session",
     group = groupSessions)
 
 
// ----- Visibility
groupVisibility = "Show / Hide Sessions"
 
showAsia = input.bool(
     true,
     "Show Asia Levels",
     group = groupVisibility)
 
showLondon = input.bool(
     true,
     "Show London Levels",
     group = groupVisibility)
 
showNY = input.bool(
     true,
     "Show New York Levels",
     group = groupVisibility)
 
 
// ----- Colors
groupColors = "Line Colors"
 
asiaHighColor = input.color(
     color.new(color.aqua, 0),
     "Asia High",
     group = groupColors)
 
asiaLowColor = input.color(
     color.new(color.aqua, 0),
     "Asia Low",
     group = groupColors)
 
londonHighColor = input.color(
     color.new(color.orange, 0),
     "London High",
     group = groupColors)
 
londonLowColor = input.color(
     color.new(color.orange, 0),
     "London Low",
     group = groupColors)
 
nyHighColor = input.color(
     color.new(color.fuchsia, 0),
     "NY High",
     group = groupColors)
 
nyLowColor = input.color(
     color.new(color.fuchsia, 0),
     "NY Low",
     group = groupColors)
 
 
// ============================================================================
// TIMEZONE
// ============================================================================
 
string tz = "America/New_York"
 
 
// ============================================================================
// SESSION DETECTION
// ============================================================================
 
inAsia = not na(time(timeframe.period, asiaSession, tz))
inLondon = not na(time(timeframe.period, londonSession, tz))
inNY = not na(time(timeframe.period, nySession, tz))
 
 
// ============================================================================
// ASIA
// ============================================================================
 
var float asiaCurrentHigh = na
var float asiaCurrentLow = na
 
var float lastAsiaHigh = na
var float lastAsiaLow = na
 
asiaStart = inAsia and not inAsia[1]
asiaEnd = not inAsia and inAsia[1]
 
if asiaStart
    asiaCurrentHigh := high
    asiaCurrentLow := low
 
if inAsia
    asiaCurrentHigh := math.max(nz(asiaCurrentHigh, high), high)
    asiaCurrentLow := math.min(nz(asiaCurrentLow, low), low)
 
if asiaEnd
    lastAsiaHigh := asiaCurrentHigh
    lastAsiaLow := asiaCurrentLow
 
 
// ============================================================================
// LONDON
// ============================================================================
 
var float londonCurrentHigh = na
var float londonCurrentLow = na
 
var float lastLondonHigh = na
var float lastLondonLow = na
 
londonStart = inLondon and not inLondon[1]
londonEnd = not inLondon and inLondon[1]
 
if londonStart
    londonCurrentHigh := high
    londonCurrentLow := low
 
if inLondon
    londonCurrentHigh := math.max(nz(londonCurrentHigh, high), high)
    londonCurrentLow := math.min(nz(londonCurrentLow, low), low)
 
if londonEnd
    lastLondonHigh := londonCurrentHigh
    lastLondonLow := londonCurrentLow
 
 
// ============================================================================
// NEW YORK
// ============================================================================
 
var float nyCurrentHigh = na
var float nyCurrentLow = na
 
var float lastNYHigh = na
var float lastNYLow = na
 
nyStart = inNY and not inNY[1]
nyEnd = not inNY and inNY[1]
 
if nyStart
    nyCurrentHigh := high
    nyCurrentLow := low
 
if inNY
    nyCurrentHigh := math.max(nz(nyCurrentHigh, high), high)
    nyCurrentLow := math.min(nz(nyCurrentLow, low), low)
 
if nyEnd
    lastNYHigh := nyCurrentHigh
    lastNYLow := nyCurrentLow
 
 
// ============================================================================
// PLOTS
// ============================================================================
 
plot(
     showAsia ? lastAsiaHigh : na,
     title = "Asia High",
     color = asiaHighColor,
     linewidth = lineWidth,
     style = plot.style_stepline)
 
plot(
     showAsia ? lastAsiaLow : na,
     title = "Asia Low",
     color = asiaLowColor,
     linewidth = lineWidth,
     style = plot.style_stepline)
 
plot(
     showLondon ? lastLondonHigh : na,
     title = "London High",
     color = londonHighColor,
     linewidth = lineWidth,
     style = plot.style_stepline)
 
plot(
     showLondon ? lastLondonLow : na,
     title = "London Low",
     color = londonLowColor,
     linewidth = lineWidth,
     style = plot.style_stepline)
 
plot(
     showNY ? lastNYHigh : na,
     title = "NY High",
     color = nyHighColor,
     linewidth = lineWidth,
     style = plot.style_stepline)
 
plot(
     showNY ? lastNYLow : na,
     title = "NY Low",
     color = nyLowColor,
     linewidth = lineWidth,
     style = plot.style_stepline)
 
 
// ============================================================================
// LABELS
// ============================================================================
 
var label asiaHighLabel = na
var label asiaLowLabel = na
var label londonHighLabel = na
var label londonLowLabel = na
var label nyHighLabel = na
var label nyLowLabel = na
 
if barstate.islast
 
    label.delete(asiaHighLabel)
    label.delete(asiaLowLabel)
    label.delete(londonHighLabel)
    label.delete(londonLowLabel)
    label.delete(nyHighLabel)
    label.delete(nyLowLabel)
 
    if showLabels and showAsia and not na(lastAsiaHigh)
        asiaHighLabel := label.new(
             bar_index,
             lastAsiaHigh,
             "ASIA H",
             style = label.style_label_left,
             color = asiaHighColor,
             textcolor = color.white)
 
    if showLabels and showAsia and not na(lastAsiaLow)
        asiaLowLabel := label.new(
             bar_index,
             lastAsiaLow,
             "ASIA L",
             style = label.style_label_left,
             color = asiaLowColor,
             textcolor = color.white)
 
    if showLabels and showLondon and not na(lastLondonHigh)
        londonHighLabel := label.new(
             bar_index,
             lastLondonHigh,
             "LONDON H",
             style = label.style_label_left,
             color = londonHighColor,
             textcolor = color.white)
 
    if showLabels and showLondon and not na(lastLondonLow)
        londonLowLabel := label.new(
             bar_index,
             lastLondonLow,
             "LONDON L",
             style = label.style_label_left,
             color = londonLowColor,
             textcolor = color.white)
 
    if showLabels and showNY and not na(lastNYHigh)
        nyHighLabel := label.new(
             bar_index,
             lastNYHigh,
             "NY H",
             style = label.style_label_left,
             color = nyHighColor,
             textcolor = color.white)
 
    if showLabels and showNY and not na(lastNYLow)
        nyLowLabel := label.new(
             bar_index,
             lastNYLow,
             "NY L",
             style = label.style_label_left,
             color = nyLowColor,
             textcolor = color.white)

← 返回列表