Crypto Intraday 1H & 4H High Low - IST

silvypeter · study · 207 行 · 点赞 10 · TradingView 原页

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

Pine Script

//@version=6
indicator("Crypto Intraday 1H & 4H High Low - IST", overlay=true, max_lines_count=500, max_labels_count=500)
 
//==================================================
// USER SETTINGS
//==================================================
 
show1H = input.bool(true, "Show 1H High/Low")
show4H = input.bool(true, "Show 4H High/Low")
showLive = input.bool(true, "Show Developing High/Low")
 
h1Color = input.color(color.blue, "1H Colour")
h4Color = input.color(color.orange, "4H Colour")
 
lineWidth = input.int(2, "Line Width", minval=1, maxval=4)
 
string TZ = "Asia/Kolkata"
 
//==================================================
// TIMEFRAME VALIDATION: 1 TO 15 MINUTES
//==================================================
 
if not timeframe.isintraday or timeframe.in_seconds() < 60 or timeframe.in_seconds() > 900
    runtime.error("Use an intraday chart from 1 minute to 15 minutes.")
 
//==================================================
// IST DAILY ANCHOR: 5:30 AM
//==================================================
 
int mins = hour(time, TZ) * 60 + minute(time, TZ)
 
int anchorToday = timestamp(
     TZ,
     year(time, TZ),
     month(time, TZ),
     dayofmonth(time, TZ),
     5, 30)
 
int anchor = mins >= 330 ? anchorToday : anchorToday - 86400000
 
//==================================================
// 1H VARIABLES
//==================================================
 
var int h1Start = na
var float h1High = na
var float h1Low = na
 
var line h1HighLine = na
var line h1LowLine = na
 
var label h1HighLabel = na
var label h1LowLabel = na
 
//==================================================
// 4H VARIABLES
//==================================================
 
var int h4Start = na
var float h4High = na
var float h4Low = na
 
var line h4HighLine = na
var line h4LowLine = na
 
var label h4HighLabel = na
var label h4LowLabel = na
 
//==================================================
// 1 HOUR HIGH / LOW CALCULATION
//==================================================
 
int bucket1 = anchor +
     int(math.floor((time - anchor) / 3600000)) * 3600000
 
if na(h1Start) or bucket1 != h1Start
 
    // Finalize previous 1H levels
    if not na(h1HighLabel)
        label.set_text(h1HighLabel, "1H H")
        label.set_text(h1LowLabel, "1H L")
 
    // Start new 1H period
    h1Start := bucket1
    h1High := high
    h1Low := low
 
    h1HighLine := na
    h1LowLine := na
    h1HighLabel := na
    h1LowLabel := na
 
    if show1H and showLive
 
        h1HighLine := line.new(
             x1=h1Start, y1=h1High,
             x2=time_close, y2=h1High,
             xloc=xloc.bar_time,
             color=h1Color,
             width=lineWidth)
 
        h1LowLine := line.new(
             x1=h1Start, y1=h1Low,
             x2=time_close, y2=h1Low,
             xloc=xloc.bar_time,
             color=h1Color,
             width=lineWidth)
 
        h1HighLabel := label.new(
             time_close, h1High, "1H H (LIVE)",
             xloc=xloc.bar_time,
             style=label.style_none,
             textcolor=h1Color,
             size=size.tiny)
 
        h1LowLabel := label.new(
             time_close, h1Low, "1H L (LIVE)",
             xloc=xloc.bar_time,
             style=label.style_none,
             textcolor=h1Color,
             size=size.tiny)
 
else
    h1High := math.max(h1High, high)
    h1Low := math.min(h1Low, low)
 
// Update horizontal 1H levels
if show1H and showLive and not na(h1HighLine)
 
    line.set_xy1(h1HighLine, h1Start, h1High)
    line.set_xy2(h1HighLine, time_close, h1High)
 
    line.set_xy1(h1LowLine, h1Start, h1Low)
    line.set_xy2(h1LowLine, time_close, h1Low)
 
    label.set_xy(h1HighLabel, time_close, h1High)
    label.set_xy(h1LowLabel, time_close, h1Low)
 
//==================================================
// 4 HOUR HIGH / LOW CALCULATION
//==================================================
 
int bucket4 = anchor +
     int(math.floor((time - anchor) / 14400000)) * 14400000
 
if na(h4Start) or bucket4 != h4Start
 
    // Finalize previous 4H levels
    if not na(h4HighLabel)
        label.set_text(h4HighLabel, "4H H")
        label.set_text(h4LowLabel, "4H L")
 
    // Start new 4H period
    h4Start := bucket4
    h4High := high
    h4Low := low
 
    h4HighLine := na
    h4LowLine := na
    h4HighLabel := na
    h4LowLabel := na
 
    if show4H and showLive
 
        h4HighLine := line.new(
             x1=h4Start, y1=h4High,
             x2=time_close, y2=h4High,
             xloc=xloc.bar_time,
             color=h4Color,
             width=lineWidth)
 
        h4LowLine := line.new(
             x1=h4Start, y1=h4Low,
             x2=time_close, y2=h4Low,
             xloc=xloc.bar_time,
             color=h4Color,
             width=lineWidth)
 
        h4HighLabel := label.new(
             time_close, h4High, "4H H (LIVE)",
             xloc=xloc.bar_time,
             style=label.style_none,
             textcolor=h4Color,
             size=size.tiny)
 
        h4LowLabel := label.new(
             time_close, h4Low, "4H L (LIVE)",
             xloc=xloc.bar_time,
             style=label.style_none,
             textcolor=h4Color,
             size=size.tiny)
 
else
    h4High := math.max(h4High, high)
    h4Low := math.min(h4Low, low)
 
// Update horizontal 4H levels
if show4H and showLive and not na(h4HighLine)
 
    line.set_xy1(h4HighLine, h4Start, h4High)
    line.set_xy2(h4HighLine, time_close, h4High)
 
    line.set_xy1(h4LowLine, h4Start, h4Low)
    line.set_xy2(h4LowLine, time_close, h4Low)
 
    label.set_xy(h4HighLabel, time_close, h4High)
    label.set_xy(h4LowLabel, time_close, h4Low)

← 返回列表