Mean Reversion

Mean Reversion Trading API
for AI Agents

Markets rarely move in straight lines. Prices stretch, overextend, and then snap back toward equilibrium. Mean reversion strategies systematically profit from this rubber-band dynamic โ€” and Purple Flea gives your agents the screener and execution tools to run them at scale.

Get API Key โ†’ Start Building

The Mean Reversion Thesis

Mean reversion is the statistical observation that asset prices oscillate around a long-run average. When prices deviate significantly from that mean โ€” due to panic selling, liquidity crunches, or retail overreaction โ€” they tend to revert. The opportunity is to buy when prices are irrationally low relative to the mean, and sell when they are irrationally high.

In perpetual futures markets, this manifests clearly: extreme negative funding rates mean the market is heavily short. Shorts need to be covered eventually. RSI below 30 signals that selling pressure has exhausted itself. Price sitting more than 3% below VWAP means institutional algorithms will soon step in as buyers. Your agent can act on these signals before the crowd reacts.

Unlike momentum trading, which requires trend-following conviction, mean reversion strategies have shorter hold times, tighter profit targets, and high win rates. The risk is getting caught in a genuine trending move where the mean keeps shifting downward โ€” which is why strict stops are non-negotiable.

Purple Flea's screener can scan all 275 markets simultaneously for oversold conditions in real time. What would take a human trader hours of chart analysis, your agent completes in milliseconds โ€” then executes a limit order at an even better price while the market is still in panic mode.

Four Mean Reversion Signals

Each signal independently indicates oversold conditions. Stack two or more for high-conviction entries.

๐Ÿ“‰
RSI Below 30 (Oversold)
The 14-period RSI falling below 30 indicates that recent losses have been disproportionate to historical volatility. The market has sold aggressively and buyers are statistically likely to step in. RSI below 20 is extreme and often marks capitulation lows.
rsi_14 < 30
๐Ÿ’ง
Price >3% Below VWAP
VWAP (Volume-Weighted Average Price) is the anchor that institutional algorithms use for fair value. When price falls more than 3% below VWAP, algo buyers tend to step in aggressively. This is one of the cleanest mean reversion signals in liquid crypto markets.
price_vs_vwap_pct < -2
๐Ÿ’ธ
Negative Funding Rate
In perpetual futures, negative funding means shorts are paying longs โ€” the crowd is positioned bearishly. Extreme negative funding (-0.05% per 8h or worse) means the market is overcrowded with shorts that must eventually be covered, creating powerful buying pressure.
funding_rate_pct < -0.01
๐Ÿ“Š
Bollinger Band Lower Touch
When price touches the lower Bollinger Band (2 standard deviations below the 20-day moving average), it is statistically unusual โ€” only about 5% of candles should reach this level. In range-bound markets, this provides a high-probability mean reversion entry point.
bb_lower_touch = true

Python: Scanning and Executing MR Setups

The example below scans for markets where multiple oversold signals have aligned, then enters limit orders slightly below the current price to capture even better fills during continued panic selling:

# Install: pip install purpleflea
import purpleflea

screener = purpleflea.ScreenerClient(api_key="YOUR_KEY")
trader = purpleflea.TradingClient(api_key="YOUR_KEY")

# Scan for oversold MR setups
setups = screener.scan(filters=[
    {"metric": "rsi_14", "condition": "below", "value": 30},
    {"metric": "price_vs_vwap_pct", "condition": "below", "value": -2},
    {"metric": "funding_rate_pct", "condition": "below", "value": -0.01},
], sort_by="rsi_14", limit=5)

for s in setups:
    order = trader.place_order(
        market=s['market'], side="buy",
        notional_usd=150, order_type="limit",
        price=s['current_price'] * 0.995 # Buy 0.5% below current
    )
    # Fixed stop at 3% below entry
    trader.set_stop_loss(order['position_id'], stop_type="fixed", distance_pct=3)
    print(f"MR entry {s['market']}: RSI={s['rsi_14']:.1f}")

Why limit orders? In mean reversion, patience is a competitive advantage. Using a limit order 0.5% below current price captures better fills during the final flush. If the order doesn't fill within 2 hours, cancel it โ€” the setup has stale conditions.

Risk Management for Mean Reversion

Mean reversion has a higher win rate than momentum but faces a unique risk: the rare occasions when it fails tend to be catastrophic. A trending market can keep going lower far beyond what any indicator suggests. These rules keep your agent solvent through those events:

Critical Rules

  • Never average down โ€” adding to a losing position in a trending market compounds losses exponentially. If the first entry is wrong, exit.
  • Fixed stops, always โ€” set a hard stop at 3% below entry before any other action. Mean reversion stops need to be wider than momentum stops to avoid noise-driven exits.
  • Trending markets kill MR โ€” check the broader market trend before entering. If BTC has fallen 15%+ in 24h, do not enter mean reversion trades on altcoins.
  • Position size conservatively โ€” mean reversion setups are more frequent, so reduce per-trade size and rely on quantity of trades for returns.

When to Skip the Setup

  • BTC down more than 10% in 24 hours โ€” systemic risk, not mean reversion opportunity.
  • Market-wide funding rate extremely negative (<-0.1%) โ€” suggests systemic deleveraging, not a local dip.
  • News catalyst is driving the move โ€” earnings, hacks, or regulatory announcements can permanently reprice an asset.
  • Volume is declining during the dip โ€” weak selling but also weak buying interest; the bounce may be shallow.
  • Market has been in a downtrend for more than 5 consecutive days โ€” mean is shifting lower, not something to revert to.

MR Signal Comparison

Different mean reversion signals have different strengths. Understanding which to weight most heavily helps your agent prioritize setups:

Signal Reliability Best Market Type Lead Time
RSI < 30 High Range-bound, low vol 1โ€“4 hours
Price vs VWAP >3% High Liquid markets (>$50M OI) 30 min โ€“ 2 hours
Negative Funding Medium Perp markets with high OI 4โ€“24 hours
Bollinger Band Lower Medium Sideways, mean-reverting 2โ€“8 hours
275
Markets scannable for oversold conditions
4
Stackable mean reversion signals
0.02%
Maker fee for limit order entries
24/7
Continuous scanning โ€” never miss a setup
20%
Referral commission on trading fees
<50ms
Order execution latency

Building Your Mean Reversion Agent

A fully functional mean reversion agent can be built in an afternoon. The key is getting the screener parameters right and testing them on historical data before deploying live capital.

  1. Get your API key at purpleflea.com/quick-register. New agents can claim $1 USDC free from the faucet.
  2. Backtest your signal stack โ€” use the backtesting API to determine which combination of RSI, VWAP, and funding signals has the best historical performance on the markets you care about.
  3. Start with limit orders โ€” begin with limit orders at 0.5% below current price to reduce taker fees and improve average entry.
  4. Add trend filter โ€” add a macro filter (e.g., BTC RSI above 40) before enabling mean reversion entries to avoid catching falling knives in downtrends.
  5. Scale gradually โ€” start with $50 per trade, validate live performance over 50 trades, then scale position size.

Combine with momentum: The best agents switch strategy based on market regime. Use mean reversion in ranging markets and momentum in trending markets. See our blog post on Momentum vs Mean Reversion for a regime-detection framework.

Ready to Build

Start Your Mean Reversion
Agent Today

Access 275 markets, real-time screener, limit order API, and backtesting. New agents get $1 USDC free to start exploring.

Get API Key โ†’ Validate First โ†’

Related Pages

Agent Screener โ†’ Trading API โ†’ Limit Order API โ†’ Momentum Strategy โ†’ Backtesting API โ†’ MR vs Momentum Blog โ†’