NIFTY Intraday 15M, 1H & 4H High Low

silvypeter · study · 145 行 · 点赞 12 · TradingView 原页

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

Pine Script

//@version=6
indicator("NIFTY Intraday 15M, 1H & 4H High Low", overlay=true, max_lines_count=500, max_labels_count=500)
 
// Settings
string TZ = "Asia/Kolkata"
 
bool show15M = input.bool(true, "Show 15 Minute High/Low")
bool show1H = input.bool(true, "Show 1 Hour High/Low")
bool show4H = input.bool(true, "Show 4 Hour High/Low")
 
color m15Color = input.color(color.purple, "15M Color")
color h1Color = input.color(color.blue, "1H Color")
color h4Color = input.color(color.orange, "4H Color")
 
int lineWidth = input.int(2, "Line Width", minval=1, maxval=4)
 
// Require an intraday chart of 15 minutes or less
if not timeframe.isintraday or timeframe.in_seconds() > 900
    runtime.error("Use an intraday chart of 15 minutes or less.")
 
// Draw horizontal levels
drawLevel(int x1, int x2, float price, color clr, string txt) =>
    line.new(x1=x1, y1=price, x2=x2, y2=price,
      xloc=xloc.bar_time, color=clr, width=lineWidth)
    label.new(x=x2, y=price, text=txt,
      xloc=xloc.bar_time, style=label.style_none,
      textcolor=clr, size=size.tiny)
 
// Indian market session
int mins = hour(time, TZ) * 60 + minute(time, TZ)
bool inSession = mins >= 555 and mins < 930
 
int today = year(time, TZ) * 10000 + month(time, TZ) * 100 + dayofmonth(time, TZ)
 
int sessionStart = timestamp(TZ, year(time, TZ), month(time, TZ), dayofmonth(time, TZ), 9, 15)
int sessionEnd = timestamp(TZ, year(time, TZ), month(time, TZ), dayofmonth(time, TZ), 15, 30)
 
// Current 15-minute candle
var int m15Start = na
var float m15High = na
var float m15Low = na
 
// Current 1H candle
var int dayKey = na
var int h1Start = na
var float h1High = na
var float h1Low = na
 
// Current 4H candle
var int h4Start = na
var float h4High = na
var float h4Low = na
 
// Reset at the beginning of a new day
if na(dayKey) or today != dayKey
    dayKey := today
 
    m15Start := na
    m15High := na
    m15Low := na
 
    h1Start := na
    h1High := na
    h1Low := na
 
    h4Start := na
    h4High := na
    h4Low := na
 
if inSession
 
    // Calculate 15M bucket: 9:15, 9:30, 9:45...
    int m15Bucket = sessionStart + int(math.floor((mins - 555) / 15)) * 900000
 
    // New 15-minute candle
    if na(m15Start) or m15Bucket != m15Start
        if not na(m15Start) and show15M
            drawLevel(m15Start, m15Start + 900000, m15High, m15Color, "15M H")
            drawLevel(m15Start, m15Start + 900000, m15Low, m15Color, "15M L")
 
        m15Start := m15Bucket
        m15High := high
        m15Low := low
    else
        m15High := math.max(m15High, high)
        m15Low := math.min(m15Low, low)
 
    // Calculate 1H bucket: 9:15, 10:15, 11:15...
    int h1Bucket = sessionStart + int(math.floor((mins - 555) / 60)) * 3600000
 
    // New 1H candle
    if na(h1Start) or h1Bucket != h1Start
        if not na(h1Start) and show1H
            drawLevel(h1Start, h1Start + 3600000, h1High, h1Color, "1H H")
            drawLevel(h1Start, h1Start + 3600000, h1Low, h1Color, "1H L")
 
        h1Start := h1Bucket
        h1High := high
        h1Low := low
    else
        h1High := math.max(h1High, high)
        h1Low := math.min(h1Low, low)
 
    // Calculate 4H bucket: 9:15 and 13:15
    int h4Bucket = sessionStart + int(math.floor((mins - 555) / 240)) * 14400000
 
    // New 4H candle
    if na(h4Start) or h4Bucket != h4Start
        if not na(h4Start) and show4H
            drawLevel(h4Start, h4Start + 14400000, h4High, h4Color, "4H H")
            drawLevel(h4Start, h4Start + 14400000, h4Low, h4Color, "4H L")
 
        h4Start := h4Bucket
        h4High := high
        h4Low := low
    else
        h4High := math.max(h4High, high)
        h4Low := math.min(h4Low, low)
 
    // Finalize last candles at 3:30 PM
    if time_close >= sessionEnd
 
        if show15M and not na(m15Start)
            drawLevel(m15Start, sessionEnd, m15High, m15Color, "15M H")
            drawLevel(m15Start, sessionEnd, m15Low, m15Color, "15M L")
 
        m15Start := na
        m15High := na
        m15Low := na
 
        if show1H and not na(h1Start)
            drawLevel(h1Start, sessionEnd, h1High, h1Color, "1H H")
            drawLevel(h1Start, sessionEnd, h1Low, h1Color, "1H L")
 
        h1Start := na
        h1High := na
        h1Low := na
 
        if show4H and not na(h4Start)
            drawLevel(h4Start, sessionEnd, h4High, h4Color, "4H H")
            drawLevel(h4Start, sessionEnd, h4Low, h4Color, "4H L")
 
        h4Start := na
        h4High := na
        h4Low := na

← 返回列表