计算自第一次发生以来的柱数

Calculate the number of bars since the first time happened

Pine-script 中,如何计算自 第一次 条件在 当天?

我使用了 bar_index 变量,但我不知道如何为当天设置它!

HighCrossColor = color.white
int barssincePDH = 0
if high >= PD_High
    HighCrossColor := color.green
    barssincePDH := bar_index
else
    HighCrossColor := color.gray

您可以手动计算柱数并在新的一天重置计数器。

//@version=5
indicator("My Script")

newDay = ta.change(time("D")) > 0

var startCounting = false
var condCnt = 0

if (ta.crossunder(ta.rsi(close, 14), 50))
    startCounting := true

condCnt := startCounting ? condCnt + 1 : 0

if newDay
    startCounting := false
    condCnt := 0

plot(condCnt)
bgcolor(newDay ? color.new(color.green, 60) : na)