Galla's 90min Cycle

rolandwalker2013 · study · 190 行 · 点赞 2 · TradingView 原页

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

Pine Script

//1234/call
//@version=6
indicator("ICT Session Boxes V2", overlay=true, max_boxes_count=500, max_lines_count=500, max_labels_count=500)
 
//==================================================
// COLORS
//==================================================
 
londonColor = color.yellow
nyAmColor   = color.green
nyPmColor   = color.gray
tokyoColor  = color.red
 
//==================================================
// TIME
//==================================================
 
h = hour(time)
m = minute(time)
 
//==================================================
// SESSION CHANGE DETECTION
//==================================================
 
newSession =
     (h == 0 and m == 0) or
     (h == 6 and m == 0) or
     (h == 12 and m == 0) or
     (h == 18 and m == 0)
 
//==================================================
// VARIABLES
//==================================================
 
var box currentBox = na
var label currentLabel = na
 
var float sessionHigh = na
var float sessionLow = na
 
var string sessionName = ""
var color sessionColor = color.white
 
var int sessionStartBar = na
 
// Store divider bars for current session
var int[] dividerBars = array.new_int()
 
//==================================================
// FINISH PREVIOUS SESSION
//==================================================
 
finishSession() =>
 
    if not na(currentBox)
 
        box.set_top(currentBox, sessionHigh)
        box.set_bottom(currentBox, sessionLow)
 
        int dividerCount = array.size(dividerBars)
 
        if dividerCount > 0
 
            for i = 0 to dividerCount - 1
 
                int dividerBar = array.get(dividerBars, i)
 
                line.new(
                     x1 = dividerBar,
                     y1 = sessionLow,
                     x2 = dividerBar,
                     y2 = sessionHigh,
                     color = color.red,
                     width = 1)
 
//==================================================
// START NEW SESSION
//==================================================
 
if newSession
 
    finishSession()
 
    array.clear(dividerBars)
 
    if h == 0
        sessionName := "London"
        sessionColor := londonColor
 
    else if h == 6
        sessionName := "NY AM"
        sessionColor := nyAmColor
 
    else if h == 12
        sessionName := "NY PM"
        sessionColor := nyPmColor
 
    else
        sessionName := "Tokyo"
        sessionColor := tokyoColor
 
    sessionStartBar := bar_index
 
    sessionHigh := high
    sessionLow := low
 
    currentBox := box.new(
         left = bar_index,
         top = high,
         right = bar_index,
         bottom = low,
         border_color = sessionColor,
         border_width = 1,
         bgcolor = color.new(sessionColor, 90))
 
    currentLabel := label.new(
         x = bar_index,
         y = high,
         text = sessionName,
         style = label.style_none,
         textcolor = sessionColor,
         size = size.small)
 
    // Session start marker
    array.push(dividerBars, bar_index)
 
//==================================================
// UPDATE ACTIVE SESSION
//==================================================
 
if not na(currentBox)
 
    sessionHigh := math.max(sessionHigh, high)
    sessionLow := math.min(sessionLow, low)
 
    box.set_right(currentBox, bar_index)
    box.set_top(currentBox, sessionHigh)
    box.set_bottom(currentBox, sessionLow)
 
    if not na(currentLabel)
 
        label.set_y(currentLabel, sessionHigh)
 
        centerBar = math.floor((sessionStartBar + bar_index) / 2)
 
        label.set_x(currentLabel, centerBar)
 
//==================================================
// INTERNAL 90-MINUTE DIVIDERS
//==================================================
 
internalDivider =
     (h == 1  and m == 30) or
     (h == 3  and m == 0 ) or
     (h == 4  and m == 30) or
 
     (h == 7  and m == 30) or
     (h == 9  and m == 0 ) or
     (h == 10 and m == 30) or
 
     (h == 13 and m == 30) or
     (h == 15 and m == 0 ) or
     (h == 16 and m == 30) or
 
     (h == 19 and m == 30) or
     (h == 21 and m == 0 ) or
     (h == 22 and m == 30)
 
if internalDivider
    array.push(dividerBars, bar_index)
 
//==================================================
// SESSION END MARKERS
//==================================================
 
sessionEnd =
     (h == 6 and m == 0) or
     (h == 12 and m == 0) or
     (h == 18 and m == 0) or
     (h == 0 and m == 0)
 
if sessionEnd
    array.push(dividerBars, bar_index)
 
//==================================================
// LAST BAR ON CHART
//==================================================
 
if barstate.islast
    finishSession()

← 返回列表