Calculations › Market Trends
Show a 7-day moving average trend for the stock market benchmark, last 90 days
The query
-- graph market-wide: 7-day moving average trend for the stock market benchmark, last 90 days
WITH daily AS (
SELECT to_timestamp(tp.datetime)::date AS date, AVG(tp.price) AS avg_price
FROM ticketprice tp JOIN ticketname tn ON tn.id = tp.ticketnameid
WHERE tn.tickettype = 'stock'
AND tp.datetime >= EXTRACT(EPOCH FROM (NOW() - INTERVAL '90 days'))::bigint
GROUP BY 1
)
SELECT date, AVG(avg_price) OVER (ORDER BY date ROWS BETWEEN 6 PRECEDING AND CURRENT ROW) AS moving_avg_7d
FROM daily ORDER BY date;
Runs against Cryptobi's market tables — ticketname (symbols),
ticketprice (daily prices and volume) and symbolmetadata
(sector, exchange, market cap and other reference fields).
Current output
| Date | Moving Avg 7d |
|---|---|
| 2026-07-03 | 121.11 |
| 2026-07-06 | 128.38 |
| 2026-07-07 | 130.52 |
| 2026-07-08 | 131.03 |
| 2026-07-09 | 131.52 |
| 2026-07-10 | 131.82 |
| 2026-07-13 | 131.94 |
| 2026-07-14 | 133.63 |
| 2026-07-15 | 133.30 |
| 2026-07-16 | 133.07 |
| 2026-07-17 | 133.01 |
| 2026-07-20 | 132.81 |
| 2026-07-21 | 132.75 |
| 2026-07-22 | 132.90 |
| 2026-07-23 | 132.80 |
Live output, first 15 rows, refreshed periodically. Model estimates are trend projections from recent prices, not financial advice.
Run this on your own holdings, change it, or write your own in SQL or Python — then put it on a dashboard or have it emailed on a schedule. Free, no credit card.
Sign Up Free