DEV Community

Cover image for Building a Multi-Signal TWAP Polymarket Trading Bot
Polymarket Trader & Web3 Dev

Building a Multi-Signal TWAP Polymarket Trading Bot

Combining TWAP deviations, momentum, order flow, and executable liquidity to distinguish meaningful probability changes from temporary market noise.

Bitcoin moves above its recent time-weighted average price. Buying pressure increases. A Polymarket YES contract starts moving higher.

Three signals appear to agree.

But what if all three are simply measuring the same underlying price movement?

The central question behind a Polymarket TWAP multi-signal bot is whether combining multiple observations provides genuinely new information or merely creates an illusion of confidence.


About the Author

Soulcrancerdev specializes in the engineering and quantitative research behind automated prediction-market trading.

Get in touch:

Github: https://github.com/thesoulcrancerdev/poly-trading-strategies

X: https://x.com/soulcrancerdev

Community: https://t.me/+SxEC7bVXYyphNzI5

Telegram: https://t.me/soulcrancerdev

Gmail: mailto:misssilverbeauty0927@gmail.com

Youtube: https://youtube.com/@soulcrancerdev


TWAP measures displacement, not direction

A time-weighted average price provides a reference against which recent price movements can be evaluated.

For equally spaced observations:

TWAP = Σ(price_i) / N
Enter fullscreen mode Exit fullscreen mode

For irregular observations, prices must instead be weighted by their corresponding time intervals.

The normalized deviation is:

deviation = (spot_price - TWAP) / TWAP
Enter fullscreen mode Exit fullscreen mode

Consider a hypothetical BTC observation:

Metric Value
Rolling TWAP $100,000
Current spot $100,250
TWAP deviation +0.25%

The positive deviation indicates that BTC is trading above its recent average. It does not establish whether the movement will continue or reverse.

That distinction is why TWAP alone is an incomplete trading signal.

A locally calculated research TWAP should also remain separate from any official settlement reference defined by the market's resolution rules.

Four signals with different responsibilities

A multi-signal trading system becomes more useful when each component measures a different aspect of market behavior.

Signal Measurement
TWAP deviation Displacement from recent average
Momentum Direction and persistence
Order flow Aggressive buying versus selling
Order-book imbalance Distribution of displayed liquidity

Momentum can be expressed as:

momentum = (price_now - price_previous)
           / price_previous
Enter fullscreen mode Exit fullscreen mode

Signed trade-flow imbalance:

flow = (buy_volume - sell_volume)
       / (buy_volume + sell_volume)
Enter fullscreen mode Exit fullscreen mode

Order-book imbalance:

imbalance = (bid_depth - ask_depth)
            / (bid_depth + ask_depth)
Enter fullscreen mode Exit fullscreen mode

These measurements should use explicitly defined observation windows and comparable liquidity bands.

Order flow measures executed activity. Order-book imbalance measures displayed intentions. Treating them as interchangeable loses valuable information.

The hidden problem with signal agreement

Suppose BTC rises rapidly after a large aggressive purchase.

TWAP deviation increases, momentum becomes positive, and buying volume dominates.

A weighted signal engine may interpret this as three independent confirmations. In reality, one event generated all three observations.

This creates a statistical problem: correlated features can exaggerate apparent confidence.

Before assigning weights, measure feature correlations and evaluate whether removing individual signals materially changes out-of-sample performance.

A weaker but independent signal may contribute more information than another highly correlated momentum indicator.

A small Python experiment

The following synthetic experiment combines normalized signals into a directional score.

signals = {
    "twap": 0.60,
    "momentum": 0.45,
    "order_flow": 0.70,
    "book_imbalance": 0.30,
}

weights = {
    "twap": 0.20,
    "momentum": 0.20,
    "order_flow": 0.35,
    "book_imbalance": 0.25,
}

score = sum(
    signals[name] * weights[name]
    for name in signals
)

threshold = 0.45

print(f"Signal score: {score:.3f}")

if score >= threshold:
    print("Bullish candidate")
elif score <= -threshold:
    print("Bearish candidate")
else:
    print("No signal")
Enter fullscreen mode Exit fullscreen mode

Expected output:

Signal score: 0.530
Bullish candidate
Enter fullscreen mode Exit fullscreen mode

The weights and thresholds are hypothetical.

The score is not a calibrated probability. A separate statistical model would be needed to translate it into an estimated likelihood of the market's defined outcome.

From directional score to executable opportunity

Imagine that a calibrated probability model produces the following hypothetical estimates:

Estimated YES probability:  0.64
Executable YES price:       0.58
Estimated execution costs:  0.02
Uncertainty buffer:         0.015

Adjusted edge:              0.025
Enter fullscreen mode Exit fullscreen mode

The directional signals may be bullish, but the opportunity depends on the price available for execution.

If the ask increases to $0.63, the same forecast no longer produces positive adjusted edge.

The underlying directional signal has not changed. Its economic value has.

Architecture of the multi-signal engine

flowchart TD
    A[Crypto Market Data] --> B[TWAP Deviation]
    A --> C[Momentum]
    A --> D[Trade Flow]
    E[Polymarket Order Book] --> F[Book Imbalance]
    B --> G[Signal Fusion]
    C --> G
    D --> G
    F --> G
    G --> H[Probability Model]
    H --> I[Execution-Aware Edge]
    E --> I
    I --> J[Risk and Position Limits]
    J --> K[Order Manager]

Every signal should carry its observation timestamp, calculation window, and data-freshness status.

Combining a fresh momentum observation with stale order-book data can generate misleading confirmation.

What experienced quantitative developers notice

Signal horizons must match. A five-minute TWAP deviation and a one-second order-flow measurement describe different time scales.

Time remaining changes the interpretation. Identical BTC movements can imply different outcome probabilities depending on proximity to resolution.

Liquidity is conditional. Displayed depth may disappear precisely when a strong signal attracts aggressive orders.

Signal weights can drift. Relationships observed during quiet markets may deteriorate during volatile regimes.

These effects should be tested independently rather than absorbed into one optimized threshold.

Research before deployment

Capture synchronized underlying prices, trades, order-book observations, market definitions, and eventual outcomes.

Evaluate each feature independently, then measure its incremental contribution to the combined model.

Use chronological validation, realistic execution assumptions, and separate testing across volatility regimes. Monitor probability calibration, signal decay, fill quality, and realized execution costs.

The real value of multiple signals

A Polymarket TWAP multi-signal bot should not exist merely to accumulate bullish or bearish indicators.

Its purpose is to distinguish displacement, persistence, executed buying pressure, and available liquidity—and determine whether those observations contain enough independent information to justify an executable trading decision.

The next useful experiment is not adding another indicator. It is removing one and measuring what information the system actually loses.

Trading-risk disclaimer: All numerical examples are hypothetical. Trading involves financial risk. Model errors, liquidity changes, execution costs, slippage, and market-resolution uncertainty can invalidate apparent opportunities. No strategy guarantees profitability.

Top comments (0)