pine-script - 在时间范围内绘制框/矩形
问题描述
我试图在一段时间内的价格范围内画一个框。我成功地绘制了盒子,但是很难跟踪价格。
关键事项:
- 我只想画最新的盒子,而不是全部历史
- 使用 max_lines_count 不应该是一个选项,因为我将其用作更大指标的一部分。
这是我的代码
//@version=4
study("Box over range", overlay=true)
showRange = input(title="Show Range", type=input.bool, defval=true)
rangeTime = input(title="Session Time", type=input.session, defval="1800-0259")
extendUntil = input(title="Session Time", type=input.session, defval="0300-1700")
resolutionInMinutes() =>
resInMinutes = timeframe.multiplier * (
timeframe.isseconds ? 1. / 60 :
timeframe.isminutes ? 1. :
timeframe.isdaily ? 60. * 24 :
timeframe.isweekly ? 60. * 24 * 7 :
timeframe.ismonthly ? 60. * 24 * 30.4375 : na)
f_timeFrom(_from, length, _units) =>
int _timeFrom = na
_unit = str.replace_all(_units, "s", "")
_timeFrom := int(time + (resolutionInMinutes() * 60 * 1000 * length))
linelength = 9 //(temporary length)
inSession = not na(time(timeframe.period, rangeTime))
startTime = inSession and not inSession[1] ? time : na
endTime = f_timeFrom("bar", linelength, "chart")
line lowHLine = na
line topHLine = na
line leftVLine = na
line rightHLine = na
// Build the Box
if not na(startTime)
highestPoint = high
lowestPoint = low
//x1, y1, x2, y2
lowHLine = line.new(startTime, lowestPoint, endTime, lowestPoint, xloc=xloc.bar_time, color=color.blue, style=line.style_solid, width = 1)
topHLine = line.new(startTime, highestPoint, endTime, highestPoint, xloc=xloc.bar_time, color=color.blue, style=line.style_solid, width = 1)
leftVLine = line.new(startTime, highestPoint, startTime, lowestPoint, xloc=xloc.bar_time, color=color.blue, style=line.style_solid, width = 1)
rightHLine = line.new(endTime, highestPoint, endTime, lowestPoint, xloc=xloc.bar_time, color=color.blue, style=line.style_solid, width = 1)
line.delete(lowHLine[1])
line.delete(topHLine[1])
line.delete(leftVLine[1])
line.delete(rightHLine[1])
//Track price
if inSession
lineHigh = line.get_y2(topHLine)
if high > lineHigh
line.set_y1(topHLine, high)
line.set_y2(topHLine, high)
轨道价格只是一个粗略的代码,显然我明白为什么它不起作用,但我找不到一个优雅的解决方案。谢谢
解决方案
推荐阅读
- javascript - 在 javascript/nodejs 中使用 token 顺序调用 API
- youtrack - 带有冲刺名称的蓝色徽章
- javascript - 如果我们有极长的水平滚动页面,如何在最后一个元素的末尾添加边距/填充,即空间?
- reactjs - 反应错误边界和延迟计算
- r - 在 R 中拆分多个日期和时间变量并计算时间平均值
- java - 数据库修改时的 Firestore ExceptionInInitializerError
- mysql - 在 Tkinter GUI 中显示 MySql 数据的最佳方式
- c# - 如何获取 Windows 窗体使用的真实字体?
- csvhelper - CSV Helper 将科学记数法转换为 String 类型
- angular - Angular - 如何在不调用 getValue 的情况下更新函数中的 BehaviorSubject 存储值中的字段