ALNY Session Highs & Lows - 2 Days [GondalAM]

gondalam · study · 128 行 · 点赞 8 · TradingView 原页

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

Pine Script

//@version=6
indicator("Asia, London & New York Session Highs and Lows - Today & Yesterday [GondalAM]",
     shorttitle="ALNY 2D HL", overlay=true, max_lines_count=12, max_labels_count=12)
 
const string CHICAGO = "America/Chicago"
const string LONDON = "Europe/London"
const string NEW_YORK = "America/New_York"
const int DAY_MS = 86400000
 
bool showAsia = input.bool(true, "Show Asia", group="Asia", display=display.none)
color asiaColor = input.color(color.yellow, "Line and label color", group="Asia", display=display.none)
 
bool showLondon = input.bool(true, "Show London", group="London", display=display.none)
color londonColor = input.color(#2196F3, "Line and label color", group="London", display=display.none)
 
bool showNewYork = input.bool(true, "Show New York", group="New York", display=display.none)
color nyColor = input.color(#CE93D8, "Line and label color", group="New York", display=display.none)
 
string yesterdayStyleInput = input.string("Dashed", "Yesterday's line style",
     options=["Dashed", "Dotted", "Solid"], group="Display", display=display.none)
int lineWidth = input.int(1, "Line thickness", minval=1, maxval=3,
     group="Display", display=display.none)
int labelInset = input.int(3, "Move labels left by bars", minval=0, maxval=30,
     group="Display", display=display.none)
 
string yesterdayStyle = switch yesterdayStyleInput
    "Dotted" => line.style_dotted
    "Solid" => line.style_solid
    => line.style_dashed
 
int chicagoMinute = hour(time, CHICAGO) * 60 + minute(time, CHICAGO)
int londonMinute = hour(time, LONDON) * 60 + minute(time, LONDON)
int nyMinute = hour(time, NEW_YORK) * 60 + minute(time, NEW_YORK)
int chicagoWeekday = dayofweek(time, CHICAGO)
 
bool afterReopen = chicagoMinute >= 17 * 60
bool beforeClose = chicagoMinute < 16 * 60
bool eveningTrading = afterReopen and chicagoWeekday <= dayofweek.thursday
bool daytimeTrading = beforeClose and chicagoWeekday >= dayofweek.monday and chicagoWeekday <= dayofweek.friday
bool inGlobex = timeframe.isintraday and (eveningTrading or daytimeTrading)
 
bool inAsia = inGlobex and (afterReopen or londonMinute < 8 * 60)
bool inLondon = inGlobex and not inAsia and nyMinute < 9 * 60 + 30
bool inNewYork = inGlobex and not inAsia and not inLondon
 
// Evening bars belong to the next CME trading date.
int chicagoDateKey = timestamp("UTC", year(time, CHICAGO), month(time, CHICAGO),
     dayofmonth(time, CHICAGO), 0, 0)
int tradingDayKey = chicagoDateKey + (afterReopen ? DAY_MS : 0)
 
var int activeTradingDay = na
bool newTradingDay = inGlobex and (na(activeTradingDay) or tradingDayKey != activeTradingDay)
 
if newTradingDay
    activeTradingDay := tradingDayKey
 
int labelBarTime = nz(time[labelInset], time)
int latestBarEnd = nz(time_close, time)
 
drawLevel(bool visible, float price, int wickTime, string caption, color levelColor, bool yesterday) =>
    var line level = na
    var label tag = na
 
    if barstate.islast
        if visible and not na(price) and not na(wickTime)
            int endTime = math.max(wickTime + 1, latestBarEnd)
            int labelTime = math.max(wickTime, labelBarTime)
 
            if na(level)
                level := line.new(wickTime, price, endTime, price,
                     xloc=xloc.bar_time, extend=extend.none, color=levelColor,
                     style=yesterday ? yesterdayStyle : line.style_solid, width=lineWidth)
                tag := label.new(labelTime, price, caption,
                     xloc=xloc.bar_time, yloc=yloc.price,
                     style=label.style_label_down, color=color.new(levelColor, 100),
                     textcolor=levelColor, size=size.small)
            else
                line.set_xy1(level, wickTime, price)
                line.set_xy2(level, endTime, price)
                label.set_xy(tag, labelTime, price)
        else if not na(level)
            line.delete(level)
            label.delete(tag)
            level := na
            tag := na
 
    level
 
trackSession(bool enabled, bool inWindow, string sessionName, color levelColor) =>
    var float todayHigh = na
    var float todayLow = na
    var int todayHighTime = na
    var int todayLowTime = na
 
    var float yesterdayHigh = na
    var float yesterdayLow = na
    var int yesterdayHighTime = na
    var int yesterdayLowTime = na
 
    if newTradingDay
        yesterdayHigh := todayHigh
        yesterdayLow := todayLow
        yesterdayHighTime := todayHighTime
        yesterdayLowTime := todayLowTime
        todayHigh := na
        todayLow := na
        todayHighTime := na
        todayLowTime := na
 
    if inWindow
        if na(todayHigh) or high > todayHigh
            todayHigh := high
            todayHighTime := time
 
        if na(todayLow) or low < todayLow
            todayLow := low
            todayLowTime := time
 
    bool visible = enabled and timeframe.isintraday
 
    drawLevel(visible, todayHigh, todayHighTime, sessionName + " High Today", levelColor, false)
    drawLevel(visible, todayLow, todayLowTime, sessionName + " Low Today", levelColor, false)
    drawLevel(visible, yesterdayHigh, yesterdayHighTime, sessionName + " High Yesterday", levelColor, true)
    drawLevel(visible, yesterdayLow, yesterdayLowTime, sessionName + " Low Yesterday", levelColor, true)
 
trackSession(showAsia, inAsia, "Asia", asiaColor)
trackSession(showLondon, inLondon, "London", londonColor)
trackSession(showNewYork, inNewYork, "New York", nyColor)

← 返回列表