زمان، تایمفریمها و سشنها
زمان یک کندل در بازهای از روز، طول تایمفریم، اجزای تقویم در یک منطقهٔ زمانی، روزها و هفتههای قبل، و یک سشن اعلامشده.
همهچیز در این صفحه ساعتِ کندلها را میخواند: یک کندل کجای بازهای از روز است، تایمفریم چقدر طول دارد، روز هفته و ساعت در یک منطقهٔ زمانی، فیلدهای دورههای قبل و عضوهای یک سشن اعلامشده. بازار مصنوعی هیچوقت بسته نمیشود، پس در پایان سشن شکافی وجود ندارد.
بازهای از روز#
زمان کندل درون بازهای از روز، اولین کندل هر روز و آخرین کندل بستهشدهٔ تاریخچه.
// A window of the day, read from the bar's own time. bar.time_in gives the time the bar opens while it lies inside the window and na outside it; bar.close_time_in does the same for the closing time.
// The first bar of each day and the last closed bar of the history are marked as well.
indicator "Window of the day"
edition = 1
display = price
input window: text = "0800-1000", name = "Window (New York time)"
let opens_inside = not is_na(bar.time_in("1h", window, zone = "America/New_York"))
let closes_inside = not is_na(bar.close_time_in("1h", window, zone = "America/New_York"))
chart.background(if opens_inside then color.fade(color.blue, 90) else na, name = "Opens inside")
mark.shape(
bar.is_first_of_day,
name = "First bar of the day",
shape = triangle_up,
place = below,
color = color.green,
)
if bar.is_last_history
label.new(bar.index, high, f"Last closed bar: {bar.index}", style = label_down)
plot(if closes_inside then close else na, name = "Close when the bar ends inside", style = circles)تعداد کندل در روز#
طول کندل نمودار به ثانیه، همین طول به شکل متن تایمفریم، و شمارش کندلهای هر روز.
// The timeframe as numbers and as text. tf.to_seconds is the length of the chart's bar, tf.from_seconds writes a length as a timeframe text,
// and tf.changed is true on the first bar of each new period of a timeframe. This counts the bars of each day and compares them with what a day should hold.
indicator "Bars in a day"
edition = 1
display = pane
let expected = 86400 / tf.to_seconds()
state counted = 0
if tf.changed("D")
counted = 0
counted += 1
if bar.is_last
let t = table.new(top_right, 2, 3, border_color = color.gray, border_width = 1)
table.cell(t, 0, 0, "Chart timeframe", h_align = left)
table.cell(t, 1, 0, tf.id)
table.cell(t, 0, 1, "Four times longer", h_align = left)
table.cell(t, 1, 1, tf.from_seconds(tf.to_seconds() * 4))
table.cell(t, 0, 2, "Intraday", h_align = left)
table.cell(t, 1, 2, if tf.is_intraday then "yes" else "no")
plot(counted, name = "Bars so far today", style = histogram, color = color.teal)
plot(expected, name = "Bars in a whole day", color = color.gray)صبحهای روزهای کاری#
اجزای تقویمی زمان کندل در یک منطقهٔ زمانی، تاریخ شروعی که از عددها ساخته میشود، و نام روزها.
// Calendar parts of a time value, read in a zone. clock.weekday_of and clock.hour_of take the bar's time, clock.timestamp builds the start date of the count,
// and clock.monday and clock.friday name the days. The count grows by one for each working-day morning that starts after the start date.
indicator "Weekday mornings"
edition = 1
display = pane
input start: time = clock.timestamp(2026, 1, 12, zone = "America/New_York"), name = "Count from"
let zone = "America/New_York"
let weekday = clock.weekday_of(bar.time, zone = zone)
let hour = clock.hour_of(bar.time, zone = zone)
let working_day = weekday >= clock.monday and weekday <= clock.friday
let morning = working_day and hour >= 8 and hour < 12
state mornings = 0
if morning and not morning[1] and bar.time >= start
mornings += 1
plot(if morning then 1 else 0, name = "Morning", style = histogram, color = color.blue)
plot(mornings, name = "Mornings counted", color = color.orange)روزها و هفتههای قبل#
فیلدهای روز و هفتهٔ جاری و قبلی: تغییر از دیروز، بخشی از دامنه که تا اینجا طی شده و جایگاه در هفتهٔ گذشته.
// Fields of earlier periods, built from the chart's own bars. current(day) is the trading day that is still forming, prior(day) the last day that finished and prior(week, 2) the week before last.
// This plots the change since yesterday's close, how much of yesterday's range today has used so far, and where the close stands inside last week's range.
indicator "Earlier days and weeks"
edition = 1
display = pane
let change = close - prior(day).close
let range_used = (current(day).high - current(day).low) / (prior(day).high - prior(day).low)
let position = (close - prior(week).low) / (prior(week).high - prior(week).low)
plot(change, name = "Change since yesterday's close", style = histogram, color = color.blue)
plot(range_used, name = "Today's range over yesterday's", color = color.purple)
plot(position, name = "Position in last week's range", color = color.orange)
plot(
prior(week, 2).close - prior(week).close,
name = "Change of the last two weeks",
color = color.gray,
)باکسهای دامنهٔ سشن#
یک سشن اعلامشده و هر شش عضو آن: یک باکس روی هر سشنِ تمامشده، از سقف تا کفش.
// A box over every finished session, from its high to its low. The members of a declared session tell where the bar stands in it:
// .start is true on its first bar, .end on its last, .active while the bar is inside, .index counts the sessions, and .high and .low are the extremes so far.
indicator "Session range boxes"
edition = 1
display = price
max_boxes = 100
session asia = 00:00 .. 08:00 @ "Asia/Tokyo"
state first_bar = 0
if asia.start
first_bar = bar.index
if asia.end
box.new(
first_bar,
asia.high,
bar.index,
asia.low,
border_color = color.purple,
background = color.fade(color.purple, 90),
)
plot(
if asia.active then asia.high - asia.low else na,
name = "Range so far",
style = histogram,
color = color.purple,
)
plot(asia.index, name = "Session number", display = none)متن تایمفریمی که نمودار نمیشناسد#
«1dd» تایمفریم نیست؛ هنگام بررسی اسکریپت رد میشود.
// A mistake on purpose: "1dd" is not a timeframe the chart knows.
indicator "Bars in a day"
edition = 1
display = pane
let expected = 86400 / tf.to_seconds()
state counted = 0
if tf.changed("1dd")
counted = 0
counted += 1
if bar.is_last
let t = table.new(top_right, 2, 3, border_color = color.gray, border_width = 1)
table.cell(t, 0, 0, "Chart timeframe", h_align = left)
table.cell(t, 1, 0, tf.id)
table.cell(t, 0, 1, "Four times longer", h_align = left)
table.cell(t, 1, 1, tf.from_seconds(tf.to_seconds() * 4))
table.cell(t, 0, 2, "Intraday", h_align = left)
table.cell(t, 1, 2, if tf.is_intraday then "yes" else "no")
plot(counted, name = "Bars so far today", style = histogram, color = color.teal)
plot(expected, name = "Bars in a whole day", color = color.gray)زمانی بدون منطقهٔ زمانی#
متن تاریخی که منطقهٔ زمانی ندارد روی هر دستگاه لحظهٔ دیگری است، پس رد میشود.
// A mistake on purpose: a date text with no zone is a different moment on every machine.
indicator "Weekday mornings"
edition = 1
display = pane
input start: time = clock.timestamp("2026-01-12T09:00"), name = "Count from"
let zone = "America/New_York"
let weekday = clock.weekday_of(bar.time, zone = zone)
let hour = clock.hour_of(bar.time, zone = zone)
let working_day = weekday >= clock.monday and weekday <= clock.friday
let morning = working_day and hour >= 8 and hour < 12
state mornings = 0
if morning and not morning[1] and bar.time >= start
mornings += 1
plot(if morning then 1 else 0, name = "Morning", style = histogram, color = color.blue)
plot(mornings, name = "Mornings counted", color = color.orange)سشنی که بهتنهایی خوانده میشود#
سشن همیشه از راه یکی از عضوهایش خوانده میشود، هرگز بهتنهایی.
// A mistake on purpose: a session is read through a member, never alone.
indicator "Session range boxes"
edition = 1
display = price
max_boxes = 100
session asia = 00:00 .. 08:00 @ "Asia/Tokyo"
state first_bar = 0
if asia.start
first_bar = bar.index
if asia.end
box.new(
first_bar,
asia.high,
bar.index,
asia.low,
border_color = color.purple,
background = color.fade(color.purple, 90),
)
plot(
if asia.active then asia.high - asia.low else na,
name = "Range so far",
style = histogram,
color = color.purple,
)
plot(asia, name = "Session number", display = none)