Skip to content

Sessions

Sessions track cumulative profit per trading pair and automatically gate new entries based on performance thresholds. When a pair reaches its profit target, sessions block new entries. When a pair hits the loss floor, sessions block new entries. Sessions never close positions or cancel orders — they only prevent new entries.

Sessions are per-symbol — each trading pair (BTCUSDT, ETHUSDT, etc.) has its own independent session with its own profit tracking and counters.

How It Works

Every time a position closes, the session records the trade profit and updates cumulative totals:

Trade closes → accumulate profit → check thresholds
  ├── cumulative profit >= session_profit_max → block new entries
  ├── cumulative profit <= session_profit_min → block new entries
  └── entry activations >= session_strat_max → block new entries

Sessions are cumulative — profit accumulates until the session is cleared (by timeout, count limits, or manual reset). There is no rolling window.

Enabling Sessions

Add any of session_profit_max, session_profit_min, or session_strat_max to your strategy parameters. If none of these keys are present, sessions are disabled.

json
{
  "session_profit_max": 50.0,
  "session_profit_min": -30.0,
  "session_strat_max": 20,
  "session_timeout_h": 4.0
}

Profit Gating

Two thresholds decide whether new entries are allowed:

  • Profit max — block entries when cumulative profit reaches or exceeds this amount
  • Profit min — block entries when cumulative profit drops to or below this amount (negative)
Cumulative profit:  +$55   →  above $50 max  →  entries blocked
Cumulative profit:  -$35   →  below -$30 min →  entries blocked
Cumulative profit:  +$20   →  between limits  →  entries allowed

Profit gating can be delayed until a minimum number of activations via session_strat_min. This lets the session "warm up" before applying profit limits.

ParameterTypeDefaultDescription
session_profit_maxUSD0.0Block entries when cumulative profit >= max. 0 = disabled
session_profit_minUSD0.0Block entries when cumulative profit <= min. 0 = disabled
session_strat_mincount0Minimum activations before profit gating applies. 0 = immediate

Activation Limit

session_strat_max limits how many entries the bot can make per session. Each time the bot enters a position, the activation counter increments. Once it reaches the max, new entries are blocked.

session_strat_max = 10

  Entry #1  →  strat_count = 1   →  allowed
  Entry #9  →  strat_count = 9   →  allowed
  Entry #10 →  strat_count = 10  →  blocked (at max)
ParameterTypeDefaultDescription
session_strat_maxcount0Max entry activations per session. 0 = unlimited

Session Clearing

Sessions can be cleared (reset to zero) by several mechanisms:

Timeout

After session_timeout_h hours from the session start, the session is automatically cleared on the next check. This effectively creates trading windows.

session_timeout_h = 4.0

  Session starts at 10:00
  Trades accumulate profit...
  14:00 → session clears → fresh start

Reset on Minus

When session_reset_on_minus is enabled, the session clears immediately whenever cumulative profit goes negative. This gives the pair a fresh start after a losing streak.

Count Limits

  • session_plus_count — clear session after N winning trades (profit > 0)
  • session_minus_count — clear session after N losing trades (profit < 0)
  • session_orders — clear session after N total trades (regardless of direction)
ParameterTypeDefaultDescription
session_timeout_hhours0.0Clear session after N hours. 0 = disabled
session_reset_on_minusboolfalseClear session when profit goes negative. Set to 1 to enable
session_plus_countcount0Clear after N winning trades. 0 = disabled
session_minus_countcount0Clear after N losing trades. 0 = disabled
session_orderscount0Clear after N total trades. 0 = disabled

Per-Pair Configuration

By default, all pairs use the same session config (from your strategy parameters). You can register per-pair overrides with different thresholds.

Per-pair configs use first-wins semantics: the first strategy to register a config for a given symbol owns that symbol's session. Later registrations for the same symbol are silently ignored.

Shared Across Strategies

The session manager is shared via Arc<SessionManager> across all strategies in a bot. If two strategies both trade BTCUSDT, they share the same session state for that pair. A loss from one strategy counts toward the other's cumulative total.

This is intentional — sessions track pair performance, not strategy performance.

Complete Example

A config that blocks trading after $50 profit or $30 loss, resets every 4 hours, and clears after 3 consecutive losses:

json
{
  "session_profit_max": 50.0,
  "session_profit_min": -30.0,
  "session_strat_max": 20,
  "session_timeout_h": 4.0,
  "session_minus_count": 3,
  "session_reset_on_minus": 0
}

What this does:

  • Accumulates profit cumulatively (no rolling window)
  • Blocks new entries when profit reaches $50 (take the win)
  • Blocks new entries when loss reaches -$30 (stop the bleeding)
  • Clears session every 4 hours for a fresh start
  • Clears session after 3 losing trades in a row
  • Allows up to 20 entries per session
  • Existing positions always close normally

Adaptive Order Sizing

Sessions can automatically adjust order sizes based on consecutive session outcomes. This uses a dual-counter model:

  • c_plus — counts consecutive profitable session cycles (profit reached max → session cleared)
  • c_minus — counts consecutive negative session cycles (loss reached min → session cleared)

When one counter increments, the other resets to 0.

Reward Sizing (Linear)

After each profitable session cycle, order size increases linearly:

new_size = old_size × (1 + session_increase_order / 100)

Capped at session_increase_order_max% of original size (default 500% = 5x).

Penalty Sizing (Exponential)

After each negative session cycle, order size decreases exponentially:

new_size = old_size / (1 + session_reduce_order / 100)

Floored at session_reduce_order_min% of original size (default 10% = 0.1x).

Threshold Scaling

  • session_strat_increase_max — scales session_strat_max higher after consecutive wins (makes it harder to hit the activation limit)
  • session_strat_reduce_min — scales session_strat_min lower after consecutive losses (applies profit gating sooner)
ParameterTypeDefaultDescription
session_increase_order%0.0Size increase step per profitable session cycle. 0 = disabled
session_increase_order_max%500.0Max size as % of original (5x). Cap for reward sizing
session_reduce_order%0.0Size decrease step per negative session cycle. 0 = disabled
session_reduce_order_min%10.0Min size as % of original (0.1x). Floor for penalty sizing
session_strat_increase_max%0.0Scale strat_max harder after wins. 0 = disabled
session_strat_reduce_min%0.0Scale strat_min easier after losses. 0 = disabled
session_profit_hour_prev_minUSD0.0Minimum order notional (USDT). Blocks entries below threshold. 0 = disabled

All Parameters

ParameterTypeDefaultDescription
session_profit_maxUSD0.0Block entries when cumulative profit >= max. 0 = disabled. Any of profit_max, profit_min, or strat_max required to enable sessions
session_profit_minUSD0.0Block entries when cumulative profit <= min (negative). 0 = disabled
session_strat_maxcount0Max entry activations per session. 0 = unlimited
session_strat_mincount0Min activations before profit gating applies. 0 = immediate
session_reset_on_minusbool0Clear session when profit goes negative. 1 = enabled
session_timeout_hhours0.0Clear session after N hours. 0 = disabled
session_plus_countcount0Clear session after N winning trades. 0 = disabled
session_minus_countcount0Clear session after N losing trades. 0 = disabled
session_orderscount0Clear session after N total trades. 0 = disabled
session_increase_order%0.0Size increase step per profitable session cycle. 0 = disabled
session_increase_order_max%500.0Max size as % of original (5x)
session_reduce_order%0.0Size decrease step per negative session cycle. 0 = disabled
session_reduce_order_min%10.0Min size as % of original (0.1x)
session_strat_increase_max%0.0Scale strat_max harder after wins. 0 = disabled
session_strat_reduce_min%0.0Scale strat_min easier after losses. 0 = disabled
session_profit_hour_prev_minUSD0.0Minimum order notional. Blocks entries when order size < threshold. 0 = disabled

tradectl — Automate Crypto Trading