90M Quarters [Nifty/Sensex IST] - 5M Only

officialksinhakk · study · 69 行 · 点赞 6 · TradingView 原页

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

Pine Script

//@version=6
indicator("90M Quarters [Nifty/Sensex IST] - 5M Only", shorttitle="90M Qtrs", overlay=true, max_boxes_count=500, max_labels_count=500)
 
const string TZ = "Asia/Kolkata"
 
// ───────── Inputs ─────────
var string G1 = "Quarter Timings (IST)"
q1s = input.session("0930-1100", "Q1", group=G1)
q2s = input.session("1100-1230", "Q2", group=G1)
q3s = input.session("1230-1400", "Q3", group=G1)
q4s = input.session("1400-1530", "Q4", group=G1)
 
var string G2 = "Colors"
c1 = input.color(color.new(color.gray,  95), "Q1 Fill", group=G2)
c2 = input.color(color.new(color.red,   95), "Q2 Fill", group=G2)
c3 = input.color(color.new(color.green, 95), "Q3 Fill", group=G2)
c4 = input.color(color.new(color.blue,  95), "Q4 Fill", group=G2)
txtCol = input.color(color.new(color.blue, 30), "Label Text", group=G2)
 
var string G3 = "Display"
showLabel = input.bool(true, "Show Label", group=G3)
 
var string G4 = "Labels"
t1 = input.string("Q1 - 90M", "Q1 Text", group=G4)
t2 = input.string("Q2 - 90M", "Q2 Text", group=G4)
t3 = input.string("Q3 - 90M", "Q3 Text", group=G4)
t4 = input.string("Q4 - 90M", "Q4 Text", group=G4)
 
// ───────── Only 5-minute chart ─────────
bool is5m = timeframe.isintraday and timeframe.period == "5"
 
// ───────── Quarter detection (IST, chart timezone independent) ─────────
int qid = not is5m ? 0 :
     not na(time(timeframe.period, q1s, TZ)) ? 1 :
     not na(time(timeframe.period, q2s, TZ)) ? 2 :
     not na(time(timeframe.period, q3s, TZ)) ? 3 :
     not na(time(timeframe.period, q4s, TZ)) ? 4 : 0
 
color fillCol = qid == 1 ? c1 : qid == 2 ? c2 : qid == 3 ? c3 : c4
string qTxt   = qid == 1 ? t1 : qid == 2 ? t2 : qid == 3 ? t3 : t4
 
// ───────── State ─────────
var box   bx  = na
var label lb  = na
var float hi  = na
var float lo  = na
var int   sbT = na
 
bool newQ = qid > 0 and qid != nz(qid[1])
 
if newQ
    hi  := high
    lo  := low
    sbT := time
    bx := box.new(sbT, high, time_close, low, xloc=xloc.bar_time, border_color=na, border_width=0, bgcolor=fillCol)
    if showLabel
        lb := label.new(sbT, low, qTxt, xloc=xloc.bar_time, style=label.style_label_up, color=color.new(color.white, 100), textcolor=txtCol, size=size.small)
 
else if qid > 0
    hi := math.max(hi, high)
    lo := math.min(lo, low)
 
// ───────── Live update while quarter is forming ─────────
if qid > 0
    box.set_top(bx, hi)
    box.set_bottom(bx, lo)
    box.set_right(bx, time_close)
    if showLabel
        label.set_xy(lb, int((sbT + time_close) / 2), lo)

← 返回列表