创建延迟的 Tradingview 警报

时间:2021-05-09 13:34:55

标签: pine-script

我想在收到条件后创建一个有一定延迟的警报。

指标重绘了很多。我不想等酒吧关门。所以我想创建一个系统,其中脚本在定义的时间(1-2 秒)后检查以查看触发警报的条件是否仍然存在并相应地创建警报。

我应该如何处理看电视的时间?

1 个答案:

答案 0 :(得分:0)

您可以使用 varip 在实时栏中对条件的持续时间进行计时。

This 展示了一些用例,包括您的:

f_secondsSince(_cond, _resetCond) =>
    // bool _cond     : condition to test.
    // bool _resetCond: when `true`, the duration resets.
    varip float _timeBegin = na
    varip bool  _lastCond  = false
    if _resetCond
        // Reset time if required.
        _timeBegin := _cond ? timenow : na
    else if _cond
        if not _lastCond
            // First occurrence of true `_cond`; save beginnning time.
            _timeBegin := timenow
    else
        // Condition is not true; reset beginning time.
        _timeBegin := na
    // Remember the last state of the `_cond` so we can detect transitions.
    _lastCond := _cond
    // Return seconds since beginning of condition, or `na`.
    float _return = (timenow - _timeBegin) / 1000