LDO-2day v1.2

LordDrake · study · 59 行 · 点赞 16 · TradingView 原页

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

Pine Script

// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// LDO-2day v1.2 — two leap-frogging daily range boxes (idea: Anton)
// v1.2: version in the legend; toggle for the box background shading. v1.1: line width, line style and label size inputs; inputs grouped. v1.0: first build.
// Each completed day gets a box spanning its high/low, starting at that day's open
// and extending 48 h forward. When a day closes, the oldest box is replaced by the new one.
//@version=6
indicator("LDO-2day v1.2", overlay = true, max_boxes_count = 10)
 
// ── Inputs
G_BOX = "Boxes"
G_LBL = "Day label"
extHours  = input.int(48, "Box length (hours)", minval = 1, maxval = 240, group = G_BOX)
colA      = input.color(color.new(#1B9E4B, 90), "Box A  fill", inline = "a", group = G_BOX)
bordA     = input.color(#1B9E4B,                 "line",       inline = "a", group = G_BOX)
colB      = input.color(color.new(#2962FF, 90), "Box B  fill", inline = "b", group = G_BOX)
bordB     = input.color(#2962FF,                 "line",       inline = "b", group = G_BOX)
showFill  = input.bool(true, "Shade box background", group = G_BOX)
lineWidth = input.int(1, "Line width", minval = 1, maxval = 5, group = G_BOX)
lineStyle = input.string("Solid", "Line style", options = ["Solid", "Dashed", "Dotted"], group = G_BOX)
showLabel = input.bool(true, "Show day label in box", group = G_LBL)
labelCol  = input.color(color.new(#B2B5BE, 0), "Label colour", group = G_LBL)
labelSize = input.string("Small", "Label size", options = ["Tiny", "Small", "Normal", "Large"], group = G_LBL)
 
lnStyle = lineStyle == "Dashed" ? line.style_dashed : lineStyle == "Dotted" ? line.style_dotted : line.style_solid
lbSize  = labelSize == "Tiny" ? size.tiny : labelSize == "Normal" ? size.normal : labelSize == "Large" ? size.large : size.small
 
// ── Daily range tracking (day boundary = the symbol's daily session; crypto = 00:00 UTC)
var float dHi    = na
var float dLo    = na
var int   dStart = na
var int   dCount = 0
var box   older  = na
var box   newer  = na
 
newDay = timeframe.change("1D")
 
// Day just closed: the oldest box makes way, the new one leap-frogs in front
if newDay and not na(dStart)
    box.delete(older)
    older := newer
    useA = dCount % 2 == 0
    newer := box.new(left = dStart, top = dHi, right = dStart + extHours * 3600000, bottom = dLo,
         xloc = xloc.bar_time, border_color = useA ? bordA : bordB, border_width = lineWidth, border_style = lnStyle,
         bgcolor = showFill ? (useA ? colA : colB) : color(na),
         text = showLabel ? str.format_time(dStart, "EEE dd MMM", syminfo.timezone) : "",
         text_color = labelCol, text_size = lbSize,
         text_halign = text.align_left, text_valign = text.align_bottom)
    dCount += 1
 
if newDay or na(dStart)
    dHi    := high
    dLo    := low
    dStart := time("1D")
else
    dHi := math.max(dHi, high)
    dLo := math.min(dLo, low)
 
if barstate.islast and not timeframe.isintraday
    runtime.error("LDO-2day needs an intraday chart (e.g. 15m, 1h, 4h).")

← 返回列表