簡體   English   中英

我不想用三角形顯示每個樞軸高點/低點,如果我選中該框,它只顯示最近的最近高點和最近的低點

[英]I want to instead of showing every Pivot High/Low with the triangle, if i check the box it show just the last recent high and recent low

showRecentOnly = input(title="Pivots Highs & Lows", defval=false)

lb = input(defval=5, title='Left Bars')
rb = input(defval=5, title='Right Bars')
 
mb = lb + rb + 1

highestbars_1 = ta.highestbars(mb)
iff_1 = highestbars_1 == -lb ? high[lb] : na
plotshape(not na(high[mb]) ? iff_1 : na, title='Triangle Pivot High', style=shape.triangledown, location=location.abovebar, color=color.new(color.red, 60), size=size.tiny, offset=-lb)

lowestbars_1 = ta.lowestbars(mb)
iff_2 = lowestbars_1 == -lb ? low[lb] : na
plotshape(not na(low[mb]) ? iff_2 : na, title='Triangle Pivot Low', style=shape.triangleup, location=location.belowbar, color=color.new(color.green, 60), size=size.tiny, offset=-lb)

如果我們只繪制最后一個高點和低點的三角形,那么當出現新的高點/低點時我們也必須刪除它們,並且無法使用 pinescript 刪除形狀。 我們只能刪除線和框等。所以在這里我做了一個版本,您可以單擊復選框以顯示最新樞軸高點的線並取消選中以查看以前的情況

//@version=5
indicator("test",overlay=true)
lb = input(defval=5, title='Left Bars')
rb = input(defval=5, title='Right Bars')
showlastonly=input(defval=false)
mb = lb + rb + 1

var lasthighbarindex=0
var lastlowbarindex=0
var h=0.0
var l=0.0

highestbars_1 = ta.highestbars(mb)
plotshape((not showlastonly) and (highestbars_1 == -lb), title='Triangle Pivot High', style=shape.triangledown, location=location.abovebar, color=color.new(color.red, 60), size=size.tiny, offset=-lb)
if (highestbars_1 == -lb)
    lasthighbarindex:=lb
    h:=high[lb]
else
    lasthighbarindex:=lasthighbarindex+1
lowestbars_1 = ta.lowestbars(mb)
plotshape((not showlastonly) and (lowestbars_1 == -lb), title='Triangle Pivot Low', style=shape.triangleup, location=location.belowbar, color=color.new(color.green, 60), size=size.tiny, offset=-lb)
if (lowestbars_1 == -lb)
    lastlowbarindex:=lb
    l:=low[lb]
else
    lastlowbarindex:=lastlowbarindex+1
if showlastonly and barstate.islast
    linehigh=line.new(bar_index-lasthighbarindex,h,bar_index,h,color=color.red)
    linelow=line.new(bar_index-lastlowbarindex,l,bar_index,l,color=color.green)
    line.delete(id=linehigh[1])
    line.delete(id=linelow[1])

檢查前 檢查

暫無
暫無

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

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