短時間に数回発生するアラート条件を作成したので、5 ~ 10 分間に数回アラートを受け取ることになりますが、アラートは 1 回だけにして、すべてのアラートの間隔を少なくとも 7 分。つまり、アラート条件が以前に満たされた場合、スクリプトは同じ条件を再度スキャンするまで 7 分間待機する必要があります。
私が持っているもの:
float i_seconds = input.int(420, 'Alert Delay', minval=1, tooltip='Seconds to delay alert condition.')
// ————— Function returning the duration in seconds for which `_cond` is true, per 14 bars.
f_secondsSince(_cond) =>
// bool _cond : condition to test.
varip float _timeBegin = na
varip float _lastTime = na
varip bool _lastCond = false
varip int _barsSince = (ta.barssince(_cond))
if _cond
if not _lastCond
// First occurrence of true `_cond`; save beginnning time.
_timeBegin := timenow
_lastTime := _timeBegin
else if (not _cond)
if (_barsSince<=14)
_timeBegin := _lastTime
else
_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
_return
// —————————— Calcs
// `true` when an alert must be triggered.
varip bool alertBull = na
varip bool alertBear = na
// Conditions of which we test the duration.
bool bullCond = before10AMBull or after10AMBull
bool bearCond = before10AMBear or after10AMBear
// Get duration of each condition, resetting the timing when user has selected to reset timing on new realtime bars.
float secondsUp = f_secondsSince(bullCond, i_reset and barstate.isnew)
float secondsDn = f_secondsSince(bearCond, i_reset and barstate.isnew)
// Trigger alerts if limit delay/duration was reached.
alertBull := (secondsUp > i_seconds)
alertBear := (secondsDn > i_seconds)
// —————————— Alerts
if bullCond and (alertBull or na(alertBull))
alert('Support', alert.freq_all)
if bearCond and (alertBear or na(alertBear))
alert('Resistance', alert.freq_all)