如何在Pine脚本中获取每日的最高和最低时间?

huangapple go评论63阅读模式
英文:

How to get daily high and low time in pine script?

问题

我正在尝试找出如何获取每日的最高价和最低价的时间,以便将其应用于较低时间框架的条件。
实际上,我想找出较低或较高水平中哪个在时间上更远或更接近。
在下面的代码中,期望的部分是空的,我不知道如何获取这些时间值。
如果您能的话,请为我提供指导。

//@version=5
indicator('HiLo', overlay=true, shorttitle='HiLo')
    
//获取最高价和最低价
isess = session.regular
t = ticker.new(syminfo.prefix, syminfo.ticker, session=isess)

todayHigh = request.security(t, 'D', high[0], gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
todayLow = request.security(t, 'D', low[0], gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)

//如何获取todayHigh和todayLow的时间?
//在此提前感谢

todayHighTime = 
todayLowTime =
英文:

I'm trying to figure out how to get the daily high and low time so I can apply it to my conditions on the lower time frame.<br>
Actually, I want to find out which of the lower or upper levels is more distant or closer in time.<br>
In the code below, the desired section is empty and I don't know how to get those time values.
Please guide me if you can.

//@version=5
indicator(&#39;HiLo&#39;, overlay=true, shorttitle=&#39;HiLo&#39;)
    
//Get High&amp;Low Price
isess = session.regular
t = ticker.new(syminfo.prefix, syminfo.ticker, session=isess)

todayHigh = request.security(t, &#39;D&#39;, high[0], gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
todayLow = request.security(t, &#39;D&#39;, low[0], gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)

//How To Get todayHigh and todayLow Time?
//Thank you in advance

todayHighTime = 
todayLowTime =

////////////

答案1

得分: 1

跟踪每日最高价和最低价。对于这一点,您不需要使用 security() 函数。

以下是 high 价格的示例。

//@version=5
indicator("My script", overlay=true)

var float high_price = na
var int high_time = na

is_new_day = ta.change(time("D"))
bgcolor(is_new_day ? color.new(color.blue, 85) : na)

if (is_new_day)
    high_price := high
    high_time := time
else
    if (high > high_price)
        high_price := high
        high_time := time

plot(high_price)

请注意,time 返回的是UNIX格式的时间。

英文:

Track the daily high and low yourself. You don't need a security() function for this.

Here is an example for the high price.

//@version=5
indicator(&quot;My script&quot;, overlay=true)

var float high_price = na
var int high_time = na

is_new_day = ta.change(time(&quot;D&quot;))
bgcolor(is_new_day ? color.new(color.blue, 85) : na)

if (is_new_day)
    high_price := high
    high_time := time
else
    if (high &gt; high_price)
        high_price := high
        high_time := time

plot(high_price)

Please note that time returns time in UNIX format.

huangapple
  • 本文由 发表于 2023年2月19日 01:15:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/75495024.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定