London & New York Session Highs (CDT)

Strechthathole4me · study · 102 行 · 点赞 13 · TradingView 原页

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

Pine Script

//@version=6
indicator("London & New York Session Highs (CDT)", overlay=true)
 
// ─────────────────────────────────────────────
// SETTINGS
// ─────────────────────────────────────────────
 
string TZ = "America/Chicago"
 
// London session: 2:00 AM - 5:00 AM Central Time
string londonSession = input.session("0200-0500", "London Session")
 
// New York session: 7:00 AM - 10:00 AM Central Time
string newYorkSession = input.session("0700-1000", "New York Session")
 
showLondon = input.bool(true, "Show London High")
showNewYork = input.bool(true, "Show New York High")
 
londonColor = input.color(color.blue, "London High Color")
newYorkColor = input.color(color.red, "New York High Color")
 
lineWidth = input.int(2, "Line Width", minval=1, maxval=5)
 
// ─────────────────────────────────────────────
// SESSION DETECTION
// ─────────────────────────────────────────────
 
inLondon = not na(time(timeframe.period, londonSession, TZ))
inNewYork = not na(time(timeframe.period, newYorkSession, TZ))
 
// Detect the first candle of each session
newLondonSession = inLondon and not inLondon[1]
newNewYorkSession = inNewYork and not inNewYork[1]
 
// ─────────────────────────────────────────────
// LONDON HIGH
// ─────────────────────────────────────────────
 
var float londonHigh = na
var line londonLine = na
 
if newLondonSession
    londonHigh := high
    
    if showLondon
        londonLine := line.new(
             bar_index,
             londonHigh,
             bar_index,
             londonHigh,
             color=londonColor,
             width=lineWidth
         )
 
else if inLondon
    londonHigh := math.max(londonHigh, high)
 
    if showLondon and not na(londonLine)
        line.set_y1(londonLine, londonHigh)
        line.set_y2(londonLine, londonHigh)
 
// Extend London high after session ends
if showLondon and not na(londonLine)
    line.set_x2(londonLine, bar_index)
 
// ─────────────────────────────────────────────
// NEW YORK HIGH
// ─────────────────────────────────────────────
 
var float newYorkHigh = na
var line newYorkLine = na
 
if newNewYorkSession
    newYorkHigh := high
    
    if showNewYork
        newYorkLine := line.new(
             bar_index,
             newYorkHigh,
             bar_index,
             newYorkHigh,
             color=newYorkColor,
             width=lineWidth
         )
 
else if inNewYork
    newYorkHigh := math.max(newYorkHigh, high)
 
    if showNewYork and not na(newYorkLine)
        line.set_y1(newYorkLine, newYorkHigh)
        line.set_y2(newYorkLine, newYorkHigh)
 
// Extend New York high after session ends
if showNewYork and not na(newYorkLine)
    line.set_x2(newYorkLine, bar_index)
 
// ─────────────────────────────────────────────
// SESSION BACKGROUND
// ─────────────────────────────────────────────
 
bgcolor(inLondon ? color.new(londonColor, 92) : na)
bgcolor(inNewYork ? color.new(newYorkColor, 92) : na)

← 返回列表