Most trend labels should say nothing
Every price page I open has a small arrow next to the ticker, green or red, with a percentage beside it. The arrow is always sure of itself, even when the chart behind it is a mess, and the reason is simple enough. It co
Every price page I open has a small arrow next to the ticker, green or red, with a
percentage beside it. The arrow is always sure of itself, even when the chart behind it is
a mess, and the reason is simple enough. It compares two prices, today's and the one from
some weeks back, and the shape in between never enters the maths.
I wanted a badge that only speaks when the shape earns it. So I built one. It's a small
web component: one script tag on the page, one tag per asset, and it draws the last three
months of prices with a single word on top. Bullish, bearish, or neutral. The word I care
about is the third one.
It takes 63 daily closes, about three months, and scores the shape of them: how steady the
move was, how straight the path was, how far it wandered on the way, and where the latest
close sits inside its own range. Then it asks the question you'd ask of any measurement.
Is this move bigger than the noise it's sitting in? A move has to be large and steady at
once. Clear one of those and fail the other, and the label stays neutral.
Most windows come back neutral. That's the design, not a lazy threshold. Three months of a
normal stock is mostly noise, and noise is exactly what the test is built to catch. A
badge that says bullish every time today's price is higher than the price in August tells
you nothing you couldn't read off the chart in two seconds. It just dresses that up as a
judgement, and the shape gets a verdict it didn't earn.
So a lot of assets get nothing.
The honest answer, for a great many instruments, is that there's no clear trend to report,
and the card says so in a plain word rather than inventing one.
Some people will find that useless, and they're not wrong for their own style. If you
trade weekly swings you don't need a three month verdict, and this isn't for you. But if
you run a fund page or a monthly note to clients, a badge that admits when nothing is
happening saves you the awkward job of explaining a green arrow on a chart that plainly
went sideways.
It isn't a forecast either. It labels prices that already happened. Nothing in it predicts
the next three months. Every card prints a short line saying that, because these cards get
screenshotted out of context and dropped somewhere the surrounding sentence is gone.
There's no market data inside it either, on purpose. The tag points at prices you already
have, as JSON, CSV, a plain list of numbers, or data you hand it from JavaScript, so you
keep whatever source you already trust and whatever rights you already have to show it.
The file is 42 KB with no dependencies.
The rest of it is ordinary component work. Light and dark that follows the visitor,
colours and font and corners you can set in CSS, ::part() when you need to reach further,
any currency, a price readout on hover or touch, and an optional refresh that re-reads your
price file on a timer.
One file was the point. Most charting libraries want a framework and a build step before
you draw anything, and a price card shouldn't cost that. One file plus one tag runs on a
static host with no server at all, which is where a lot of small finance sites actually
live.
The price is $15.20, once, for unlimited sites of your own and client sites too, as long
as you don't resell the widget itself.
It's a small thing. But a label that knows when to shut up beats one that's always
talking, and working out when to shut up turned out to be most of the work.
If you want the version that is already a component rather than a porting job, it is here: https://juniverse8031.gumroad.com/l/trend-badge?utm_source=devto&utm_medium=article&utm_campaign=trend-badge-v1
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.