我已经创建了可以在很短的时间内多次满足的警报条件,因此我将在 5-10 分钟内收到多次警报 - 但我更喜欢只有一个警报,并且所有警报的间隔为至少 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)