pine-script - 如何获得特定日期的收盘价
问题描述
我下面的代码在我输入的日期的收盘价处绘制了一条水平线。但是,它仅适用于图表上的“每日”时间范围。我需要它在任何时间范围内工作(主要是 15 分钟时间范围)。对于任何其他时间范围,它不会绘制实际收盘价。相反,它绘制最后一根蜡烛的收盘价。
我尝试了安全功能,但我不能在 if 条件下使用它。但是,如果条件是我要求验证我输入的日期。
//@version=4
study("How to get actual close price for a specific date", overlay=true)
text = input(false, type=input.bool, title="---------------------Select Date--------------------------")
startDate = input(title="Date", type=input.integer,
defval=12, minval=1, maxval=31)
startMonth = input(title="Month", type=input.integer,
defval=5, minval=1, maxval=12)
startYear = input(title="Year", type=input.integer,
defval=2021, minval=1800, maxval=2100)
Time_start = timestamp(syminfo.timezone, startYear, startMonth, startDate, 00, 00)
Time_end = timestamp(syminfo.timezone, startYear, startMonth, startDate, 23, 59)
pinDateRange = time >= Time_start and time <= Time_end
var pclose = 0.00
if pinDateRange
pclose := close
// pclose := security(syminfo.tickerid, 'D', close)
plot(pclose, title="Close Price of Selected Date", color=#F94D00, linewidth=1, style=plot.style_stepline, offset=-9999, trackprice=true)
解决方案
尝试使用此示例作为参考:
//@version=4
study("Plot value starting n months/years back", "", true)
monthsBack = input(3, minval = 0)
yearsBack = input(0, minval = 0)
fromCurrentDateTime = input(false, "Calculate from current Date/Time instead of first of the month")
targetDate = time >= timestamp(
year(timenow) - yearsBack,
month(timenow) - monthsBack,
fromCurrentDateTime ? dayofmonth(timenow) : 1,
fromCurrentDateTime ? hour(timenow) : 0,
fromCurrentDateTime ? minute(timenow) : 0,
fromCurrentDateTime ? second(timenow) : 0)
beginMonth = not targetDate[1] and targetDate
var float valueToPlot = na
if beginMonth
valueToPlot := high
plot(valueToPlot)
bgcolor(beginMonth ? color.green : na)
https://www.pinecoders.com/faq_and_code/#how-can-i-plot-a-value-starting-n-monthsyears-back
推荐阅读
- python - 我的编译器一直显示此错误“TypeError: add_node() missing 1 required positional argument: 'data'”
- mp4 - 如何从解析的 sidx 框中计算不同片段的字节范围值
- python - json.loads() 没有转换成字典
- vb.net - 左连接两个数据表 - 没有 SQL 和没有 LINQ
- influxdb - 高效地将大型时间序列数据加载到 InfluxDB
- python - “unicodeescape”编解码器无法解码位置 2-3 中的字节:截断 \UXXXXXXXX 转义
- r - UseMethod(“group_by_”)中的错误:没有适用于“group_by_”的适用方法应用于类“c('matrix','character')的对象
- java - 在 tabbedPanel 中集成 Papplet(应用程序)
- c# - 该程序被 Asp.net core 2.0 中的组策略阻止,使用 Wkhtmltopdf.NetCore
- java - Fragment 列表已更改,但 ViewPager 加载已实例化的 Fragment