如何根据过去 x 条中出现的 1 个条件绘制不同的形状(PineScript、TradingView)

How to plot different shapes based on the occurrences of 1 condition over the past x bars (PineScript, TradingView)

非常感谢您的帮助...我正在尝试根据过去 50 根柱线中出现的相同情况绘制不同的形状

我有一个条件,当这个条件为真时,我在图表上叠加 plotshape();这很好用。我要实现的目标摘要:

-condition/plotshape1 不是最近 50 根柱线中的第三个实例吗?然后继续绘制plotshape1

-condition/plotshape1 的第三个实例是否在最近 50 根柱内?然后绘制 plotshape2 而不是 plotshape1

一个问题是它会连续绘制在每根蜡烛上方,直到 50 个柱中不再有 3 个实例。我明白为什么会这样,但我的修复尝试产生了更多问题:

// "condition" is my input var

// running count of instances in last 50 bars
countcondition = math.sum(condition ? 1 : 0, 50)

// identify number of occurrences whether 3 or less
Three = countcondition > 2
NotThree = countcondition <= 2

// My attempt to stop the continuous printing above every candle
var Pos = 0
// save it to a new number when occurs
if Three and Pos <= 0
    Pos := 1

// assign var for plotshape - even if this worked it would plot both shapes on the 3rd occurrence
Plotshape1 = condition   // works as expected
Plotshape2 = Pos == 1 and (Pos != 1)[1]  // not working, plots are incorrect

plotshape(Plotshape1, title="1-2 times", style=shape.triangleup, location=location.belowbar, color=#00E676, size=size.small, text="Plot1")
plotshape(Plotshape2, title="3rd time", style=shape.triangleup, location=location.belowbar, color=#FF5252, size=size.small, text="Plot2")
Plotshape1 = NotThree
Plotshape2 = Three and not Three[1]