如何在 alert.freq 中使用条件

How to use condition in alert.freq

如果时间范围是 15 分钟然后使用 alert.freq_once_per_bar_close,如果时间范围是每天然后在 alert("message", freq) 中使用 alert.freq_once_per_bar,你能控制吗?

我试过了 alert("message", timeframe.isminutes? alert.freq_once_per_bar_close: alert.freq_once_per_bar) 但出现此错误:

“无法使用参数 'freq'='调用 'operator ?:'(简单字符串)'调用 'alert'。使用了 'simple string' 类型的参数但预计 'input string'"

你需要使用两个 if 块来做到这一点。

f_tfInMinutes() => 
    _tfInMinutes = timeframe.multiplier * (
      timeframe.isseconds ? 1. / 60             :
      timeframe.isminutes ? 1.                  :
      timeframe.isdaily   ? 60. * 24            :
      timeframe.isweekly  ? 60. * 24 * 7        :
      timeframe.ismonthly ? 60. * 24 * 30.4375  : na)

is_15_min = f_tfInMinutes() == 15
is_daily = f_tfInMinutes() == 1440

if (is_15_min and alert_condition)
    alert("message", alert.freq_once_per_bar_close)
    
if (is_daily and alert_condition)
    alert("message", alert.freq_once_per_bar)