Daily trend-flip system

One mechanical rule,
checked once a day.

Adelmo trades perpetual futures on OKX with a single rule. Ten seconds after the daily candle closes, it computes one direction per pair. If that direction flipped, it acts. Nothing else moves the book — no discretion, no forecasts, no intraday noise.

The rule

Two exponential averages of the same series, and the line where they would cross. Everything the bot does follows from which side of that line price sits on.

ohlc4 = (open + high + low + close) / 4
AP    = EMA(ohlc4, 2)

fast  = EMA(AP, 12)      K1 = 2/13
slow  = EMA(AP, 26)      K2 = 2/27

        slow·(1−K2) − fast·(1−K1)
X   =  ───────────────────────────
                K1 − K2

direction = AP > X ? long : short
  1. 16:00
    UTC, every day

    Ten seconds after OKX closes its 1D candles, one direction is computed per monitored pair and written to a snapshot.

  2. Compare to yesterday

    If today’s direction differs from the previous candle’s, that pair has flipped. No flip, no action — most days nothing happens.

  3. Act on the flip

    Any armed trigger on that pair closes a position now fighting the trend, and opens one in the new direction, sized by a fixed USD notional.

Why this rule

Two properties fall out of the algebra rather than being tuned in. Both are asserted by a test in the repository.

01 — it leads the cross

A day earlier than the EMAs

Rearranging the two EMA updates for the point where they meet gives exactly the X formula. So X is the value AP would need next bar to make fast and slow equal — comparing AP against it fires when the crossover is about to happen, instead of confirming it a day late.

02 — it resists whipsaw

The line runs away from price

Once a trend is established the gap between the averages drives X far from the market, so ordinary noise cannot reach it. A flip only becomes possible when the averages genuinely converge.

fast 20% above slowX below zero
fast 20% below slowX ~3x price
03 — the edge is shape, not accuracy

Losing most of the time is the design

A low win rate is not a defect here. Flipping out of a position that turned caps each loser quickly, while a position that keeps running is never closed for being profitable. Returns come from the size of the few that work, not the count.

and where it hurts

Markets that go sideways

The same hysteresis that ignores noise inside a trend cannot help when the averages sit converged. Price oscillates across the line, the direction flips repeatedly, and each flip pays fees to end up flat. That is the standing cost of the payoff shape above — not a bug to be tuned away.

What it will not do

The constraints matter more than the entries. These are enforced in code, not by convention.

no

Fire twice on one candle

A trigger records the candle it acted on, so a manual re-run or a worker restart cannot double-trade.

no

Trade the moment you save

Arming a trigger seeds it with the current candle, so it can only ever act on a future flip — never on the one already formed.

no

Trust its own database

Live OKX positions are the source of truth for exposure. The database records what happened; it never decides what is open.

no

Exceed the exposure cap

Combined notional is checked against a percentage of equity before any open. Closes are never blocked — reducing risk is always allowed.

no

Guess

No AI signals, no news feed, no sentiment. The direction is arithmetic on closed candles and nothing else.

no

Trade intraday

One decision per pair per day. Between closes the engine only keeps market data warm and reconciles fills.