[Chrona] Session

ChronaIndicators · study · 49 行 · 点赞 3 · TradingView 原页

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

Pine Script

//@version=6
// Chrona Session ID — names the current trading session by New York time
// (America/New_York, handles DST automatically). Chart colours, thin frame,
// position and size chosen in the settings.
// Only the last bar is ever shown, so calc_bars_count keeps the historical run
// to a handful of bars instead of the whole chart.
indicator("[Chrona] Session", overlay = true, calc_bars_count = 10)
 
G_TBL   = "Session table"
posIn   = input.string("Bottom right", "Position", options = ["Top left", "Top center", "Top right", "Middle left", "Middle center", "Middle right", "Bottom left", "Bottom center", "Bottom right"], group = G_TBL,
     tooltip = "Tables from different indicators stack on top of each other when they share a corner. Move this one if it lands on another indicator's table.")
szIn    = input.string("Small", "Text size", options = ["Tiny", "Small", "Normal"], group = G_TBL)
sessCol = input.color(#dec38a, "Session colour", group = G_TBL)
 
string tblPos = switch posIn
    "Top left"       => position.top_left
    "Top center"     => position.top_center
    "Top right"      => position.top_right
    "Middle left"    => position.middle_left
    "Middle center"  => position.middle_center
    "Middle right"   => position.middle_right
    "Bottom left"    => position.bottom_left
    "Bottom center"  => position.bottom_center
    => position.bottom_right
string tblSz = szIn == "Tiny" ? size.tiny : szIn == "Normal" ? size.normal : size.small
 
var table t = table.new(tblPos, 1, 1, frame_width = 1, border_width = 0)
if barstate.islast
    tz  = "America/New_York"
    // timenow, not time: a bar's open time names the wrong session on 1h and
    // above (a daily bar opens at midnight, so it would always read Asia).
    mod = hour(timenow, tz) * 60 + minute(timenow, tz)   // minutes since ET midnight
    // ET session windows over the Globex day (18:00 ET open). First match wins.
    // Each Pre- window is the hour (90 min for NY) before that session opens.
    sess = mod < 60   ? "Asia"       :  // 00:00–01:00
         mod < 120    ? "Pre-London" :  // 01:00–02:00
         mod < 480    ? "London"     :  // 02:00–08:00
         mod < 570    ? "Pre-NY"     :  // 08:00–09:30
         mod < 720    ? "AM"         :  // 09:30–12:00
         mod < 780    ? "Lunch"      :  // 12:00–13:00
         mod < 900    ? "PM"         :  // 13:00–15:00
         mod < 960    ? "Power"      :  // 15:00–16:00
         mod < 1020   ? "Post"       :  // 16:00–17:00
         mod < 1080   ? "Pre-Asia"   :  // 17:00–18:00
         "Asia"                         // 18:00–24:00
    table.set_frame_color(t, color.new(chart.fg_color, 70))
    table.cell(t, 0, 0, sess, text_color = sessCol, text_size = tblSz,
         text_halign = text.align_center, bgcolor = chart.bg_color)
    table.cell_set_tooltip(t, 0, 0, "Current session — New York time")

← 返回列表