簡體   English   中英

Pinescript - 情節發生在每個柱上,而不僅僅是最高和最低

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

我試圖用 plotshape 表示最后 140 個中的最高和最低直方圖條。 我的代碼工作有點過於熱情,因為它繪制在每個條上,而不僅僅是最高和最低。

我已經玩了一段時間並尋找答案但沒有成功。 如果你有空的話,會喜歡一些建議。

謝謝阿里

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()lowest()函數返回series 然后你用一個條件“和”這個結果。 看起來像這樣: 150 and true 因此, UPpeakDNpeak變量在一段時間內保持真實。

您可以做的是,檢查AOval的當前值是否等於最后 140 個柱中的最高/最低值。 這樣,您就會知道那個點是峰值。

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

在此處輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM