如何获得特定日期的收盘价

编程入门 行业动态 更新时间:2024-10-23 11:16:50
本文介绍了如何获得特定日期的收盘价的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我下面的代码在我输入的日期的收盘价处绘制了一条水平线.但是,它仅适用于图表上的每日"时间范围.我需要它在任何时间范围内工作(主要是 15 分钟时间范围).对于任何其他时间范围,它不会绘制实际收盘价.相反,它绘制了最后一根蜡烛的收盘价.

My code below plots a horizontal line at the close price of a date entered by me. However it works only with 'Daily' time frame on chart. I need it to work in any time frame(Mainly 15 minute time frame). For any other time frame, it doesn't plot the actual closing price. Instead it plots the closing price of the last candle.

我尝试了安全功能,但无法在 if 条件下使用它.但如果条件是我验证我输入的日期的要求.

I tried the security function, but I cannot use it inside if condition. But if condition is my requirement to validate the date entered by me.

//@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)

推荐答案

试试这个例子作为参考:

Try to use this example as a reference:

//@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)

www.pinecoders/faq_and_code/#how-can-i-plot-a-value-starting-n-monthsyears-back

更多推荐

如何获得特定日期的收盘价

本文发布于:2023-10-25 21:58:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1528226.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:收盘价   如何获得   日期

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!