Skip to content

Guide

This walkthrough takes you from zero to a backtested, optimized algorithm. By the end, you’ll have created an algorithm, run a backtest, interpreted the results, and improved it with optimization.

Choose the asset and exchange you want to trade. Reversion supports Hyperliquid perpetual futures and HIP-3 XYZ DEX perpetual markets for tradfi assets.

Start with a liquid market like BTC/USDC or ETH/USDC — these have tight spreads and deep orderbooks, which means more reliable backtests.

Before building an algorithm, explore how indicators behave on your chosen market. This helps you pick the right signals and thresholds.

For example, test RSI on ETH 4-hour candles:

  • Indicator: RSI
  • Period: 14 bars (56 hours on 4h timeframe)
  • Signal: value_below_threshold with threshold 30 (oversold → buy signal)

Use the explore_indicator tool or the charting UI to visualize signals against price data. Look for:

  • Does the signal trigger at reasonable points?
  • How often does it fire? (too frequent = noisy, too rare = missed opportunities)
  • Does it align with price reversals?

An algorithm needs at minimum:

  1. TypeLONG, SHORT, or BOTH
  2. Entry condition — when to open a position
  3. Exit condition — when to close it
  4. Position sizing — how much capital per trade
  5. Starting capital — the initial USD balance

This algorithm buys when RSI is oversold and sells when it’s overbought:

SettingValue
TypeLONG
Long EntryRSI below 30 (required)
Long ExitRSI above 70 (required)
Stop Loss5% trailing
Position Size50% of equity (REL)
Order TypeMARKET
Starting Capital$1,000
TimeoutCOOLDOWN_ONLY, 3 bars

Conditions use two groups:

  • Required — ALL indicators in this group must be true (AND logic)
  • Optional — at least ONE indicator must be true (OR logic)

Both groups must be satisfied for the condition to trigger. This lets you build layered rules like:

Enter when RSI is oversold (required) AND either Bollinger Band is touched OR volume spikes (optional)

See Algorithms → Conditions for the full reference.

Add risk management to your exit condition:

  • Stop Loss — exit at a fixed USD amount (ABS) or percentage (REL) below entry
  • Take Profit — exit at a fixed amount or percentage above entry
  • Trailing Stop — SL level follows price as it moves in your favor
  • Dynamic — SL/TP modulated by an indicator value (DYN)

Three modes:

ModeDescriptionExample
ABSFixed USD amount per trade$500 per trade
RELPercentage of current equity50% of equity
DYNDriven by an indicator valueATR-scaled sizing

You can create algorithms through:

  • Web app — the algorithm builder UI
  • MCP agentcreate_algorithm tool via natural language
  • APIPOST /algo/configs

The platform saves your config and assigns an algoId. Each subsequent edit creates a new version — previous versions are preserved and can be backtested independently.

With your algorithm created, run a backtest to see how it would have performed:

ParameterDescription
algoIdYour algorithm’s ID
versionWhich version to test (latest by default)
symbolTrading pair (e.g., BTC/USDC)
startTimeBacktest start date
endTimeBacktest end date
capitalScalerMultiplier for starting capital (default: 1.0)

The backtest runs asynchronously — you’ll get a runId to check results.

Once the backtest completes, check these metrics first:

MetricWhat It Tells YouGood Range
Win Rate% of trades that were profitable> 40% (depends on R:R)
Profit FactorGross profit / gross loss> 1.5
Sharpe RatioRisk-adjusted return (annualized)> 1.0
Sortino RatioLike Sharpe but only penalizes downside> 1.5
Max DrawdownLargest peak-to-trough decline< 20%
Calmar RatioAnnualized return / max drawdown> 1.0
Avg Trade DurationHow long positions are heldDepends on strategy

Plot the equity curve (plot_backtest) to visually inspect:

  • Is the curve consistently rising, or does all profit come from a few lucky trades?
  • Are drawdowns sharp and frequent, or gradual and recoverable?
  • Does the strategy stall in certain market regimes?

The algo metrics include a usefulness score (0–100) for each indicator. This tells you how much each indicator contributes to the strategy:

  • High score — the indicator is driving meaningful entries/exits
  • Low score — the indicator is rarely triggered or always agrees with other signals (consider removing it)

Also check near-miss analysis — how close conditions came to triggering without actually firing. This can reveal if thresholds need tweaking.

Based on your results, adjust:

  • Thresholds — if RSI 30/70 doesn’t work, try 25/75 or 35/65
  • Indicators — swap underperforming indicators (low usefulness scores) for alternatives
  • Position sizing — if drawdowns are too large, reduce position size
  • Timeframe — try different candle intervals (1h, 4h, 1d)
  • Stop loss — tighten or loosen SL; try trailing stops

Each change creates a new version. Backtest again and compare.

Once you have a working strategy, use Bayesian optimization to systematically search for the best parameters:

  1. Define parameter space — which parameters to vary and their bounds
  2. Choose a scoring function — what to maximize (Sharpe, profit factor, custom)
  3. Run optimization — the engine tries different parameter combinations using Optuna TPE
  4. Validate — run rolling cross-validation to ensure the optimized params aren’t overfit

When you’re confident in your strategy:

  1. Create a run with isBacktest: false
  2. The algorithm executes live using the same state machine as backtesting
  3. Monitor via get_account_overview or the web app
  4. Stop anytime by updating run status to STOPPED

The live engine uses the same indicator evaluation and condition logic as the backtester — what you tested is what runs.

  • Algorithms — full reference for all algorithm config options
  • Backtesting — deep dive into metrics and the simulation pipeline
  • Optimization — Bayesian optimization and cross-validation