Trading Alarm Clock Alerts

A custom indicator created by Second Half Software on TrendSpider. You can import this custom indicator into your TrendSpider account. Don't have TrendSpider? Create an account first, then import the custom indicator.

Chart featuring the Trading Alarm Clock Alerts indicator

An indicator for the Trading Alarm Clock app (Get the app: https://tradingalarmclock.com). It watches up to three symbols (by default ES1!, NQ1! and YM1!: the E-mini S&P 500, Nasdaq-100 and Dow futures) and raises one signal, Wake, at a candle close when any of them has moved past the threshold you set since the prior day's close, inside the hours you choose. Make it the condition of a Multi-Factor Alert (Wake → Signal emerged) sent to your Trading Alarm Clock webhook. If the alert reaches the app inside your wake window, your phone rings an early wake with the alert's Note as its text. The early wake needs a subscription and Alarms allowed on your phone. Setup: tradingalarmclock.com/config. Not financial advice. S&P 500, Nasdaq-100, Dow Jones and TrendSpider are trademarks of their owners; we are not affiliated with or endorsed by them.

Source code

This indicator had been implemented by Second Half Software in JavaScript on TrendSpider. Check out the developer documentation to learn more about JS on TrendSpider.

// Trading Alarm Clock Alerts — the TrendSpider version.
// © 2026 Second Half Software LLC. All rights reserved.
//
// Watches up to three symbols and raises one signal, "Wake", on any candle
// inside a time window you set where a symbol has moved past its own
// threshold since the prior day's close. Each slot chooses how its threshold
// is measured: Percent (of the prior day's close), ATR (multiples of the
// prior day's daily ATR) or Price (points).
//
// TrendSpider scripts cannot send text, so the alert's own Note is what
// reaches the webhook: create a Multi-Factor Alert on this indicator with the
// condition "Wake — Signal emerged", and write a Note that says what moved.
// Runs on any chart; the chart's symbol does not matter.

// The full name in the chart legend and an alert's condition line (Sam,
// 2026-11-10), though it leaves room for fewer of the settings shown there.
describe_indicator('Trading Alarm Clock Alerts', 'price', { shortName: 'Trading Alarm Clock Alerts' });

// ── Symbols ─────────────────────────────────────────────────────────────────
// Three slots, each a pick from the list below; "Off" switches the slot off.
// Three because three is what is verified to work in an alert. Each slot
// makes two requests: with three symbols (six) the alert fired; with four
// (eight) it showed no error and evaluated "no" at every check (watched
// 2026-11-10, #1338). Seven is untested, and whether the limit counts
// requests or the run's time is not established. DEFAULTS is the slot count.
//
// A list, not a text box, because TrendSpider's input() has no free-text
// kind: a number, or a string that must be one of a list of options. A bare
// string default is refused at load — "Default value for Symbol 1 must be a
// number" (2026-09-15). So the tickers a user can watch are the ones here.
// Continuous futures are spelled the TradingView way, ROOT1! — probed on
// 2026-09-15: "@NQ" and "NQ" are refused by request.history(), "NQ1!" loads
// 324 daily bars. The rest are ETFs that track the same markets for anyone
// without futures data. Add a symbol by adding it to this list.
const OFF = 'Off';
const SYMBOLS = [
  OFF,
  // Index futures
  'ES1!', 'NQ1!', 'YM1!', 'RTY1!',
  // Metals
  'GC1!', 'SI1!', 'HG1!', 'PL1!',
  // Energy
  'CL1!', 'NG1!', 'RB1!', 'HO1!',
  // Rates
  'ZB1!', 'ZN1!', 'ZF1!', 'ZT1!',
  // Currencies
  '6E1!', '6J1!', '6B1!', '6A1!', '6C1!', 'DX1!',
  // Crypto futures
  'BTC1!', 'ETH1!',
  // Grains
  'ZC1!', 'ZS1!', 'ZW1!',
  // ETFs for the same markets
  'SPY', 'QQQ', 'DIA', 'IWM', 'GLD', 'SLV', 'USO', 'UNG', 'TLT', 'UUP', 'BITO',
];
const DEFAULTS = ['ES1!', 'NQ1!', 'YM1!']; // the S&P 500, the Nasdaq, the Dow
const TYPES = ['Percent', 'ATR', 'Price'];
const slots = [];
for (let i = 1; i <= DEFAULTS.length; i++) {
  const symbol = input(`Symbol ${i}`, DEFAULTS[i - 1], SYMBOLS);
  const type = input(`Symbol ${i} alert type`, 'Percent', TYPES);
  const threshold = input(`Symbol ${i} threshold`, 0.5, { min: 0.0001 });
  if (symbol !== OFF) slots.push({ symbol, type, threshold });
}
const atrLength = input('Daily ATR length', 14, { min: 1, max: 100 });

// ── Timing window ───────────────────────────────────────────────────────────
const startHour = input('Start hour (24h)', 6, { min: 0, max: 23 });
const startMin = input('Start minute', 0, { min: 0, max: 59 });
const endHour = input('End hour (24h)', 8, { min: 0, max: 23 });
const endMin = input('End minute', 0, { min: 0, max: 59 });
const TIMEZONES = [
  'America/New_York', 'America/Chicago', 'America/Denver', 'America/Phoenix', 'America/Los_Angeles',
  'America/Anchorage', 'Pacific/Honolulu', 'America/Toronto', 'America/Vancouver', 'America/Mexico_City',
  'America/Sao_Paulo', 'UTC', 'Europe/London', 'Europe/Paris', 'Europe/Zurich', 'Europe/Amsterdam',
  'Asia/Dubai', 'Asia/Kolkata', 'Asia/Singapore', 'Asia/Hong_Kong', 'Asia/Tokyo', 'Australia/Sydney',
];
const timezone = input('Timezone', 'America/Los_Angeles', TIMEZONES);
const DAYS = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'];
const dayOn = DAYS.map((d) => input(`Run on ${d}`, d === 'Sat' || d === 'Sun' ? 'No' : 'Yes', ['Yes', 'No']) === 'Yes');
const testFire = input('Send a test alert now', 'No', ['Yes', 'No']) === 'Yes';
// Diagnostic: which spelling of the first symbol TrendSpider's data will
// serve. The platform hides request.history()'s reason, so this tries the
// plausible spellings one by one and reports every result as the script's
// error text (the one output that reaches the editor) and in the console.
// It found ROOT1! on 2026-09-15; kept for the next symbol that will not load.
// Run it on a chart, not in an alert: its seven requests are more than an
// alert is known to run.
const probeSpellings = input('Probe spellings', 'No', ['Yes', 'No']) === 'Yes';

// ── Data ────────────────────────────────────────────────────────────────────
// Two requests per slot: the symbol on the chart's own resolution (the live
// price, candle by candle) and its daily bars (the prior close and the prior
// day's ATR).
const moment = library('moment-timezone');

// What this chart calls itself, in the browser console (F12 → Console).
// TrendSpider's own symbol spelling is what request.history() accepts, and a
// futures chart is the quickest way to read it for the continuous contracts.
console.log('TAC Alerts: chart ticker', current.ticker, 'resolution', current.resolution);

// A failed request surfaces as "history: [object Object]" and nothing else
// (2026-09-15). Name the symbol and the reason, so the next failure says
// which slot it was and why.
function describe(e) {
  if (e && typeof e.message === 'string') return e.message;
  if (typeof e === 'string') return e;
  try { return JSON.stringify(e); } catch (_) { return String(e); }
}
async function history(symbol, resolution) {
  try {
    return await request.history(symbol, resolution);
  } catch (e) {
    // A string, not an Error: TrendSpider's sandbox forbids `new` (2026-09-15).
    throw `Could not load ${symbol} at resolution ${resolution}: ${describe(e)}`;
  }
}

if (probeSpellings && slots.length) {
  const root = slots[0].symbol.replace(/^@/, '').replace(/1!$/, '');
  const candidates = ['@' + root, root, root + '1!', root + '=F', 'CME:' + root, '/' + root, root + '.F'];
  const report = [];
  for (const c of candidates) {
    try {
      const h = await request.history(c, 'D');
      report.push(`${c}: OK (${h && h.close ? h.close.length : 0} daily bars)`);
    } catch (e) {
      report.push(`${c}: ${describe(e)}`);
    }
  }
  const text = `Spelling probe for ${root} — chart ticker is "${current.ticker}": ` + report.join(' | ');
  console.log('TAC Alerts:', text);
  throw text;
}

// One request at a time, never Promise.all. Fired together, fourteen requests
// (seven symbols, the old default) stalled from a cold cache and the platform
// killed the run at ~30 s ("Request timeout"); one at a time they loaded in
// ~3 s (watched 2026-10-01, #21). A warm cache hides it, so a quick retest
// will not catch a regression.
const results = [];
for (const slot of slots) {
  const live = await history(slot.symbol, current.resolution);
  const daily = await history(slot.symbol, 'D');
  results.push({ slot, live, daily });
}

// The prior day's close, for each candle of the chart: the close of the last
// daily bar that finished before that candle's day. Landed onto the chart's
// time series so every chart candle looks up one number.
function priorDailyValues(daily, series) {
  // series[i] belongs to daily bar i; shift by one so bar i carries bar i-1's value.
  const shifted = series.map((_, i) => (i > 0 ? series[i - 1] : null));
  return interpolate_sparse_series(land_points_onto_series(daily.time, shifted, time, 'ge'), 'constant');
}

// Is this chart candle inside the wake window, in the chosen timezone?
const inWindow = time.map((t) => {
  const m = moment.unix(t).tz(timezone);
  const day = (m.isoWeekday() + 6) % 7; // Mon=0 … Sun=6, matching DAYS
  if (!dayOn[day]) return false;
  const mins = m.hours() * 60 + m.minutes();
  return mins >= startHour * 60 + startMin && mins < endHour * 60 + endMin;
});

// ── The signal ──────────────────────────────────────────────────────────────
// For each slot, a boolean per chart candle: has it crossed its threshold?
const crossed = results.map(({ slot, live, daily }) => {
  const prevClose = priorDailyValues(daily, daily.close);
  const dailyAtr = atr(daily.high, daily.low, daily.close, atrLength);
  const prevAtr = priorDailyValues(daily, dailyAtr);
  const liveClose = interpolate_sparse_series(land_points_onto_series(live.time, live.close, time, 'ge'), 'constant');
  return for_every(liveClose, prevClose, prevAtr, (px, prev, a) => {
    if (px == null || prev == null || !prev) return false;
    const move = Math.abs(px - prev);
    const points =
      slot.type === 'Percent' ? (prev * slot.threshold) / 100 : slot.type === 'ATR' ? (a == null ? NaN : a * slot.threshold) : slot.threshold;
    return Number.isFinite(points) && move >= points;
  });
});

const anyCrossed = time.map((_, i) => crossed.some((s) => s[i]));
const wake = for_every(anyCrossed, inWindow, (c, w) => c && w);

// The test switch: the last two candles alternate by the clock, one raised and
// one not, regardless of window and thresholds. Two alerts on "Wake — Signal
// emerged" fired at the second check after this was saved (2026-11-10,
// #1338); raising the last candle, or the last two, did not fire it. Why, and
// which candle an alert judges, is not established. Switch it back off.
if (testFire && wake.length > 1) {
  const n = wake.length, step = time[n - 1] - time[n - 2];
  for (let k = n - 2; k < n; k++) wake[k] = Math.floor(time[k] / step) % 2 === 0;
}

register_signal(wake, 'Wake');

// A mark on the chart where the signal is true, so the window and thresholds
// can be read by eye before an alert is created.
paint(
  wake.map((w) => (w ? '⏰' : null)),
  { style: 'labels_above', color: 'white', backgroundColor: '#F2AC3C', backgroundBorderRadius: 9 },
);