WIF/USDT · 15-minute bars · 21 Sep 2026 · 09:00–14:45 UTC

Insight on EMA and leg calculation

How My Coin Classifier Uses an EMA to Find Where a Leg Starts

Closes with the EMA laid over them. Hollow red dots are closes that fell below the EMA. The dotted teal line is a plain average of the same number of latest closes, for comparison. The last bar (14:45) was still forming when this was scored.
20

One update, step by step

Each new close pulls the EMA a fixed fraction of the way toward it. That fraction is α = 2 ÷ (span + 1). Slide to any bar. The dashed line on the chart is the gap between the old EMA and the new close, and the orange dot sits α of the way up it.

Where the weight goes

The final EMA value is a weighted mix of all 24 closes. Recent bars count most and each older one counts 1 − α of the one after it. The first bar is special: the EMA starts at that close, so whatever weight hasn't decayed yet stays on it.

Share of the final EMA contributed by each bar. The bars add up to 100%. At span 20 the seed close (09:00, 0.2090) still carries about 10%, and it is the lowest close of the window, so it pulls the EMA down a little.

What the classifier does with it

Three checks in opportunity_payload.py read the EMA. Values update with the span above. At span 20 they match the live payload: EMA 0.22492, slope +2.35%, leg start at bar 0.

SUI/USDT · 15-minute bars · 20 Sep 2026 · 11:15–17:00 UTC

From EMA to leg start

The EMA is only a yardstick. To find where the current up-leg began, the classifier walks backward from the newest bar and counts closes that sit below the EMA. Three in a row means the previous leg ended there, and the leg is everything from that point on. WIF never dipped below its EMA three bars running, so this section uses a window where it did.

run = 0
for i from newest bar back to oldest:
    if close[i] < ema[i]:  run = run + 1
    else:                  run = 0
    if run == 3:           leg_start = i ; stop
(never reaches 3: leg_start = 0, the whole window is the leg)
Top: closes and EMA. The teal band is the leg. On the right, the leg's full range is split into the part already given back (red) and the part still held (teal). Bottom: the same 24 bars as cells. The scan reads them right to left, and the number under each is the running count of consecutive closes below the EMA.
20

SUI/USDT · same 24 bars · the leg from bar 7 (13:00 → 17:00, 17 bars)

Verticality: one big bar, or a staircase?

Once the leg is found, the classifier asks what shape it has. Two numbers answer that, both measured over the leg only. One says how much of the climb came from a single bar. The other says how straight the climb is on a log-price line. Slide the blend to turn this leg into a steady climb and watch both numbers move.

1 · How much of the climb came from one bar?

Top: the return of each bar in the leg. Middle: only the up-bars, stacked side by side into one bar that stands for all the gains. Bottom: the highlighted bar's slice of that total is the max_single_bar_share. At 45% or more the classifier calls the leg vertical.

2 · How straight is the climb?

Top: closes on a log price scale, so a steady percentage climb would be a straight line. The orange line is the best straight fit and the thin grey lines are the gaps to it. Bottom: logprice_r2 measures how small those gaps are, from 0 (no line at all) to 1 (a perfect line).
WIF bars are Binance 15m klines from a live run at 14:49 UTC on 21 Sep 2026. SUI bars are the Binance 15m klines for 11:15–17:00 UTC on 20 Sep 2026, fetched with the script's backtest mode so the numbers stay fixed. The EMA is seeded with the first close of the 24-bar window, the same as pandas ewm(span, adjust=False). That is why the seed keeps weight at the end of a short window.

License

Author: G_DEV

Link: https://gdevwebsite.pages.dev/posts/ema-and-leg-calculation/

License: CC BY-NC-SA 4.0

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. Please attribute the source, use non-commercially, and maintain the same license.