LVLUP | Overnight Zones

lsaucedabusiness · study · 144 行 · 点赞 3 · TradingView 原页

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

Pine Script

//@version=6
indicator("LVLUP | Overnight Session", overlay=true, max_boxes_count=100, max_lines_count=200, max_labels_count=200)
 
// ─────────────────────────────────────
// SETTINGS
// ─────────────────────────────────────
 
sessionInput = input.session("1700-0829", "Overnight Session")
timezoneInput = input.string("America/Chicago", "Timezone")
 
boxColor = input.color(color.rgb(143, 165, 143), "Sage Green")
boxTransparency = input.int(85, "Box Transparency", minval=0, maxval=100)
 
showHighLow = input.bool(true, "Show Overnight High / Low")
showLabels = input.bool(true, "Show High / Low Labels")
 
levelColor = input.color(color.rgb(143, 165, 143), "High / Low Line Color")
lineWidth = input.int(2, "Line Width", minval=1, maxval=4)
 
// ─────────────────────────────────────
// SESSION DETECTION
// ─────────────────────────────────────
 
inSession = not na(time(timeframe.period, sessionInput, timezoneInput))
 
newSession = inSession and not inSession[1]
sessionEnded = not inSession and inSession[1]
 
// ─────────────────────────────────────
// SESSION VARIABLES
// ─────────────────────────────────────
 
var float overnightHigh = na
var float overnightLow = na
 
var box sessionBox = na
var line highLine = na
var line lowLine = na
 
var label highLabel = na
var label lowLabel = na
 
// ─────────────────────────────────────
// NEW SESSION
// ─────────────────────────────────────
 
if newSession
    overnightHigh := high
    overnightLow := low
 
    sessionBox := box.new(
         left=bar_index,
         top=high,
         right=bar_index,
         bottom=low,
         bgcolor=color.new(boxColor, boxTransparency),
         border_color=color.new(boxColor, 30)
         )
 
    if not na(highLine)
        line.delete(highLine)
    if not na(lowLine)
        line.delete(lowLine)
 
    if not na(highLabel)
        label.delete(highLabel)
    if not na(lowLabel)
        label.delete(lowLabel)
 
    highLine := na
    lowLine := na
    highLabel := na
    lowLabel := na
 
// ─────────────────────────────────────
// UPDATE SESSION RANGE
// ─────────────────────────────────────
 
if inSession
    overnightHigh := math.max(nz(overnightHigh, high), high)
    overnightLow := math.min(nz(overnightLow, low), low)
 
    if not na(sessionBox)
        box.set_right(sessionBox, bar_index)
        box.set_top(sessionBox, overnightHigh)
        box.set_bottom(sessionBox, overnightLow)
 
// ─────────────────────────────────────
// SESSION COMPLETE
// ─────────────────────────────────────
 
if sessionEnded and showHighLow
    highLine := line.new(
         bar_index - 1,
         overnightHigh,
         bar_index,
         overnightHigh,
         color=levelColor,
         width=lineWidth
         )
 
    lowLine := line.new(
         bar_index - 1,
         overnightLow,
         bar_index,
         overnightLow,
         color=levelColor,
         width=lineWidth
         )
 
    if showLabels
        highLabel := label.new(
             bar_index,
             overnightHigh,
             "ONH",
             style=label.style_label_left,
             color=levelColor,
             textcolor=color.white
             )
 
        lowLabel := label.new(
             bar_index,
             overnightLow,
             "ONL",
             style=label.style_label_left,
             color=levelColor,
             textcolor=color.white
             )
 
// ─────────────────────────────────────
// EXTEND HIGH / LOW LEVELS
// ─────────────────────────────────────
 
if not inSession and not na(highLine)
    line.set_x2(highLine, bar_index)
    line.set_x2(lowLine, bar_index)
 
    if not na(highLabel)
        label.set_x(highLabel, bar_index)
 
    if not na(lowLabel)
        label.set_x(lowLabel, bar_index)
// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © lsaucedabusiness

← 返回列表