简体   繁体   English

Pinescript - 情节发生在每个柱上,而不仅仅是最高和最低

[英]Pinescript -Plot happening on every bar, not just highest and lowest

I am trying to have the highest and lowest histogram bars in the last 140 indicated with a plotshape.我试图用 plotshape 表示最后 140 个中的最高和最低直方图条。 My code is working a bit too enthusiastically because it is plotting on every bar instead of just the highest and lowest.我的代码工作有点过于热情,因为它绘制在每个条上,而不仅仅是最高和最低。

I have played around with it for a while and searched for answers with no success.我已经玩了一段时间并寻找答案但没有成功。 Would love some suggestions please if you have some time to spare.如果你有空的话,会喜欢一些建议。

Thanks Ali谢谢阿里

study("Oscillator (AO)")
nLengthSlow = input(34, minval=1, title="Length Slow")
nLengthFast = input(5, minval=1, title="Length Fast")
xSMA1_hl2 = sma(hl2, nLengthFast)
xSMA2_hl2 = sma(hl2, nLengthSlow)

//indicator
AOval = xSMA1_hl2 - xSMA2_hl2

// Determine colour
lineColour = (AOval > AOval[1]) and (AOval > 0) ? lime :
            (AOval < AOval[1]) and (AOval > 0) ? green :
                (AOval > AOval[1]) and (AOval < 0) ? red :
                maroon

UPpeak = highest(AOval, 140) and (AOval > 0)
DNpeak = lowest(AOval, 140) and (AOval < 0)

plot(AOval, style=histogram, linewidth=3, color=lineColour)

plotshape(UPpeak, title="UPpeak", text="3", style=shape.circle, location=location.bottom, color=blue, size=size.auto, transp=60)
plotshape(DNpeak, title="DNpeak", text="3", style=shape.circle, location=location.bottom, color=orange, size=size.auto, transp=60)

highest() and lowest() functions return series . highest()lowest()函数返回series You then "and" this result with a condition.然后你用一个条件“和”这个结果。 Which looks like this: 150 and true .看起来像这样: 150 and true As a result, UPpeak or DNpeak variables stay true for some period.因此, UPpeakDNpeak变量在一段时间内保持真实。

What you can do is, check if the current value of AOval is equal to the highest/lowest within the last 140 bars.您可以做的是,检查AOval的当前值是否等于最后 140 个柱中的最高/最低值。 This way, you would know that that bar at that point is the peak.这样,您就会知道那个点是峰值。

UPpeak = (AOval == highest(AOval, 140)) and (AOval > 0)
DNpeak = (AOval == lowest(AOval, 140)) and (AOval < 0)

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Pinescript 最高/最低比较 - Pinescript Highest / Lowest Comparision PineScript 中的多时间帧变量使用最高(),最低() - Multi timeframe variable in PineScript using highest(), lowest() 根据先前蜡烛的数量查找最高或最低价格 - Pinescript - Find the highest or the lowest price based on the number of previous candles - Pinescript Pinescript:如何获得最高,最低,sma,不包括特定时间范围? - Pinescript: How to get highest, lowest, sma, excluding specific timeframe? 如何在pinescript中最低点之后的下一个最高点 - How to next highest point after the days lowest low in pinescript 如何在pinescript中获得特定时间范围的最高点和最低点 - How to get the highest high and the lowest low of specific timeframe in pinescript 两个区域之间的 PineScript 最高条 - PineScript Highest Bar between two zones Pinescript:我可以根据仅从当前柱派生的值打开/关闭 plot 系列吗 - Pinescript: Can I turn on/off a plot series based on a value derived from just the current bar PineScript 'ta.lowest' 和 'ta.highest' 在 'if' 条件下显示错误值 - PineScript 'ta.lowest' and 'ta.highest' shows wrong value when in 'if' condition PineScript Highest-High 和 Lowest-Low 显示 Current-High 和 Current-Low - PineScript Highest-High and Lowest-Low showing Current-High and Current-Low
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM