ClickAPIs
Examples · RSI(2) mean reversion with a time stop

Examples / Advanced

RSI(2) mean reversion with a time stop

Level 4 · AdvancedPOST/v1/backtest

What it answers

A short-term mean-reversion rule: buy when the 2-day RSI is deeply oversold inside a long-term uptrend, sell when it recovers above 70 or after 10 bars, whichever comes first.

Request

Input POST /v1/backtest
{
  "symbol": "SPY",
  "entry": "rsi(2) < 10 and close > sma(200)",
  "exit": "rsi(2) > 70",
  "max_bars": 10,
  "start_date": "2005-01-01",
  "fee_bps": 1,
  "slippage_bps": 2,
  "benchmark": "SPY"
}
Open in playground

Response

Output 200 OK
{
  "ok": true,
  "data": {
    "symbol": "SPY",
    "start": "2005-01-03",
    "end": "2026-11-12",
    "rules": {
      "entry": "rsi(2) < 10 and close > sma(200)",
      "exit": "rsi(2) > 70",
      "side": "long",
      "initial_capital": 10000,
      "position_size": 1.0,
      "stop_loss": null,
      "take_profit": null,
      "trailing_stop": null,
      "max_bars": 10,
      "cooldown_bars": 0,
      "fill": "next_open",
      "fee_bps": 1.0,
      "slippage_bps": 2.0
    },
    "stats": {
      "initial_capital": 10000.0,
      "final_equity": 13217.21,
      "net_profit": 3217.21,
      "total_return": 0.321721,
      "cagr": 0.012792,
      "max_drawdown": -0.150303,
      "sharpe": 0.229227,
      "sortino": 0.305048,
      "trades": 206,
      "win_rate": 0.436893,
      "avg_trade_return": 0.001597,
      "median_trade_return": -0.001845,
      "avg_trade_pnl": 15.62,
      "best_trade_return": 0.067842,
      "worst_trade_return": -0.055442,
      "avg_win": 248.85,
      "avg_loss": -165.34,
      "profit_factor": 1.167743,
      "avg_bars_held": 5.9,
      "exposure": 0.21996,
      "total_fees": 491.76,
      "total_slippage": 983.51,
      "buy_hold_return": 8.319246,
      "buy_hold_max_drawdown": -0.551908,
      "benchmark": "SPY",
      "benchmark_return": 8.319246,
      "benchmark_max_drawdown": -0.551908,
      "excess_return": -7.997525
    },
    "trades": [
      {
        "entry_date": "2005-01-04",
        "exit_date": "2005-01-05",
        "side": "long",
        "entry_price": 81.286,
        "exit_price": 80.0965,
        "shares": 123.022487,
        "pnl": -148.31,
        "return": -0.014831,
        "fees": 1.99,
        "bars": 1,
        "exit_reason": "exit_rule"
      },
      {
        "entry_date": "2005-01-06",
        "exit_date": "2005-01-24",
        "side": "long",
        "entry_price": 79.9213,
        "exit_price": 78.9785,
        "shares": 123.267345,
        "pnl": -118.17,
        "return": -0.011995,
        "fees": 1.96,
        "bars": 11,
        "exit_reason": "max_bars"
      },
      {
        "entry_date": "2005-01-25",
        "exit_date": "2005-02-09",
        "side": "long",
        "entry_price": 78.896,
        "exit_price": 81.2327,
        "shares": 123.371406,
        "pnl": 286.3,
        "return": 0.029414,
        "fees": 1.98,
        "bars": 11,
        "exit_reason": "max_bars"
      },
      {
        "entry_date": "2005-02-23",
        "exit_date": "2005-03-10",
        "side": "long",
        "entry_price": 80.2552,
        "exit_price": 81.7567,
        "shares": 124.849386,
        "pnl": 185.43,
        "return": 0.018506,
        "fees": 2.02,
        "bars": 11,
        "exit_reason": "max_bars"
      },
      {
        "entry_date": "2005-03-22",
        "exit_date": "2005-03-23",
        "side": "long",
        "entry_price": 80.1917,
        "exit_price": 79.2003,
        "shares": 127.260605,
        "pnl": -128.2,
        "return": -0.012562,
        "fees": 2.03,
        "bars": 1,
        "exit_reason": "exit_rule"
      },
      "… 198 more items …",
      {
        "entry_date": "2026-09-02",
        "exit_date": "2026-09-11",
        "side": "long",
        "entry_price": 760.7088,
        "exit_price": 762.6764,
        "shares": 17.621266,
        "pnl": 31.99,
        "return": 0.002386,
        "fees": 2.68,
        "bars": 6,
        "exit_reason": "exit_rule"
      },
      {
        "entry_date": "2026-10-15",
        "exit_date": "2026-10-30",
        "side": "long",
        "entry_price": 766.4032,
        "exit_price": 761.2277,
        "shares": 17.532074,
        "pnl": -93.42,
        "return": -0.006952,
        "fees": 2.68,
        "bars": 11,
        "exit_reason": "max_bars"
      },
      {
        "entry_date": "2026-11-02",
        "exit_date": "2026-11-03",
        "side": "long",
        "entry_price": 759.6019,
        "exit_price": 752.5795,
        "shares": 17.566073,
        "pnl": -126.01,
        "return": -0.009444,
        "fees": 2.66,
        "bars": 1,
        "exit_reason": "exit_rule"
      }
    ],
    "trades_truncated": false,
    "open_trade": null,
    "equity_curve": [
      {
        "date": "2005-01-03",
        "equity": 10000.0,
        "drawdown": 0.0,
        "benchmark": 10000.0
      },
      {
        "date": "2005-01-21",
        "equity": 9711.25,
        "drawdown": -0.028875,
        "benchmark": 9707.98
      },
      {
        "date": "2005-02-09",
        "equity": 10019.81,
        "drawdown": 0.0,
        "benchmark": 9918.68
      },
      {
        "date": "2005-03-01",
        "equity": 10210.43,
        "drawdown": -0.001709,
        "benchmark": 10077.62
      },
      {
        "date": "2005-03-18",
        "equity": 10205.25,
        "drawdown": -0.013177,
        "benchmark": 9892.8
      },
      "… 417 more items …",
      {
        "date": "2026-10-23",
        "equity": 13322.51,
        "drawdown": -0.084544,
        "benchmark": 93638.49
      },
      {
        "date": "2026-11-11",
        "equity": 13217.21,
        "drawdown": -0.09178,
        "benchmark": 93618.78
      },
      {
        "date": "2026-11-12",
        "equity": 13217.21,
        "drawdown": -0.09178,
        "benchmark": 93192.46
      }
    ],
    "monthly_returns": [
      {
        "year": 2026,
        "months": [
          0.023161,
          -0.016484,
          -0.024833,
          0.0,
          0.0,
          -0.020236,
          -0.014314,
          -0.000485,
          0.002386,
          -0.006952,
          -0.009444,
          null
        ],
        "total": -0.066019
      },
      {
        "year": 2025,
        "months": [
          -0.003766,
          -0.026515,
          0.0,
          0.0,
          0.005253,
          0.0,
          0.0,
          0.003996,
          0.005772,
          0.039352,
          0.040252,
          0.008395
        ],
        "total": 0.073321
      },
      {
        "year": 2024,
        "months": [
          0.016028,
          0.013729,
          0.0,
          -0.031283,
          0.006918,
          0.027583,
          -0.00656,
          -0.057645,
          0.050019,
          -0.019854,
          0.032081,
          -0.008762
        ],
        "total": 0.017587
      },
      {
        "year": 2023,
        "months": [
          0.0,
          0.004511,
          -0.024051,
          9.6e-5,
          0.030536,
          0.030973,
          0.0,
          -0.02319,
          -0.025857,
          -0.016124,
          0.0,
          0.0
        ],
        "total": -0.02477
      },
      {
        "year": 2022,
        "months": [
          -0.03659,
          0.0,
          0.0,
          0.0,
          0.0,
          0.0,
          0.0,
          0.0,
          0.0,
          0.0,
          0.0,
          0.0
        ],
        "total": -0.03659
      },
      "… 14 more items …",
      {
        "year": 2007,
        "months": [
          0.003513,
          -0.012239,
          -0.019487,
          0.026664,
          0.011668,
          0.011508,
          -0.00109,
          -0.000429,
          0.0,
          0.038569,
          -0.024821,
          0.0
        ],
        "total": 0.032581
      },
      {
        "year": 2006,
        "months": [
          0.032935,
          -0.009116,
          0.026605,
          -0.00852,
          -0.016868,
          0.005675,
          0.0,
          0.023569,
          0.0,
          0.0,
          0.047071,
          0.017208
        ],
        "total": 0.122937
      },
      {
        "year": 2005,
        "months": [
          -0.01658,
          0.03318,
          -0.008212,
          -0.014553,
          0.0,
          -0.008133,
          0.0,
          4.3e-5,
          0.03237,
          -0.026876,
          0.0,
          0.01472
        ],
        "total": 0.004127
      }
    ],
    "notes": [
      "Rules are evaluated on each bar's close; with fill=next_open orders fill at the next bar's open (no look-ahead). Daily prices are split- and dividend-adjusted.",
      "Trade prices include slippage; pnl is net of fees on both legs."
    ],
    "interval": "1day"
  },
  "meta": {
    "op": "backtest",
    "units": 9,
    "cost_usd": 0.0,
    "billing": "internal",
    "free_call": false,
    "free_calls_left": 0,
    "balance_usd": 5.0,
    "ms": 45,
    "interval": "1day",
    "data_as_of": "2026-11-12",
    "partial_last_bar": false
  }
}

How to read it

High win rate, short holding periods and low exposure are the signature of this rule; check avg_trade against fees. max_bars caps the time in a losing trade (exit_reason max_bars).

Parameters and limits: Backtest reference. Analytics, not advice.