“最近 n 天"的最高点,而不是“n 天前"的最高点 [英] Highest high "of the last n days", not "n days ago"

查看:47
本文介绍了“最近 n 天"的最高点,而不是“n 天前"的最高点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我想将今天的收盘价与过去 4 天的最高价进行比较,格式是什么?我用过

If I want to compare the close of today with the high of the last 4 days, what is the format? I have used

_hi = close > high[4] ? 1 : 0

但这仅计算 4 天前的高点,而不是两者之间的天数.我试过了

But that only counts the high 4 days ago, not the days in between. I have tried

_hi = close > high[1,2,3,4] ? 1 : 0

错误信息

推荐答案

你可以使用 highest() 来达到这个目的.

You can use highest() for that purpose.

highest(source, length) → series

你需要小心.<代码>关闭 >highest(close, 4) 永远不可能是 true.因为,如果当前柱的收盘价是这 4 个柱中最高的,highest() 将返回当前柱的收盘价.因此,该检查将是 close >关闭,这永远不会是真的.

You need to be careful though. close > highest(close, 4) can never be true. Because, if the current bar's close price is the highest among those 4 bars, highest() will return current bar's close price. Therefore, that check would be close > close, which can never be true.

您可以执行 close >high(nz(close[1]), 4)close == high(close, 5) (它是 5,因为当前柱也是包括.但您想比较前 4 个小节).

You can either do close > highest(nz(close[1]), 4) or close == highest(close, 5) (It is 5, because current bar is also included. But you want to compare the previous 4 bars).

看看下面的代码和图表.一种是使用 close >high(nz(close[1]), 4) 另一个是使用 close == high(close, 5).如您所见,输出是相同的.

Have a look at the following code and chart. One is using close > highest(nz(close[1]), 4) and the other one is using close == highest(close, 5). As you can see, the output is identical.

//@version=3
study(title="Compare 2", overlay=true)

_hi = close > highest(nz(close[1]), 4)
plotshape(series=_hi, title="_hi", text="hi", style=shape.triangleup, location=location.belowbar, color=green, size=size.small, transp=40)

这篇关于“最近 n 天"的最高点,而不是“n 天前"的最高点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆