Position Manager
Lexicon Core Definition
The position manager is the trading bot module responsible for stateful risk calculations — computing position size, enforcing stop-loss placement, and tracking the daily loss limit across a session.
Analysis Breakdown
Frequent Queries
What is the position manager module in a trading bot?
The position manager is the bot module responsible for all stateful risk calculations — those requiring knowledge of current account balance, cumulative session P&L, or open position details. Its three primary responsibilities are: computing the mathematically correct position size to ensure per-trade risk limits are precisely respected, calculating and storing the stop-loss price when a trade opens, and tracking cumulative session losses against the daily loss limit to stop new entries when the limit is reached. These responsibilities are separated from signal logic because they depend on account state rather than just indicator values and current price conditions.
How does the position manager calculate position size in J21's bot?
J21's position sizing formula is: position size = (account balance × per-trade risk percentage) ÷ stop distance in price. For example, a £10,000 account with 0.5% per-trade risk and a £200 stop distance from entry produces a position size of £50 ÷ £200 = 0.25 units. This formula ensures the loss equals exactly £50 if the stop triggers, regardless of the stop's distance from entry — mathematically enforcing the per-trade risk rule. Account balance and risk percentage are read from the exchange balance and config.py respectively at the time of each trade entry calculation.
How does the daily loss limit work inside J21's position manager module?
J21's DailyLossTracker class implements the daily loss limit with two methods. `record_trade(pnl)` is called after each trade closes, adding the result to the running session total. `limit_hit()` is checked at the start of each main loop cycle before evaluating entry signals — if cumulative session loss has reached the configured limit percentage of account balance, it returns True and the loop skips all entry signal evaluation. The daily loss limit resets at session start via `reset_daily()`. This implementation enforces the stop unconditionally — the bot cannot override it regardless of subsequent market conditions or perceived opportunities.
Calibration Check
Position sizing in a trading bot just means choosing how much to trade — any fixed amount per trade qualifies.
Professional position sizing is a mathematical calculation that enforces a specific loss amount if the stop-loss triggers, not an arbitrary fixed trade size. The formula — account balance × risk percentage ÷ stop distance — produces the exact unit quantity ensuring a stop hit costs precisely the configured risk amount. Trading fixed amounts regardless of stop distance means trades with wide stops risk far more than intended while trades with tight stops risk far less, creating inconsistent and uncontrolled loss exposure across different trade setups — the opposite of systematic risk management.
The position manager and position state perform the same function and can be combined in one module.
Position state and the position manager serve distinct functions. Position state is a simple data container — a dictionary tracking whether the bot holds a trade, the entry price, and the stop-loss price. The position manager is the calculation engine that uses account balance and session P&L to compute position sizes, enforce stop placement, and track the daily loss limit. Position state holds data; the position manager performs calculations on that data plus account-level context. Combining them creates a module with both storage and financial calculation responsibilities, harder to test and debug than cleanly separated alternatives.
The daily loss limit in the position manager is optional for experienced traders who have good self-discipline.
The daily loss limit's value as coded module comes precisely from being non-negotiable — the bot cannot feel frustration, override rules under emotional pressure, or convince itself one more trade is justified. For a manual trader, enforcing the daily loss limit requires willpower under emotional stress. For a bot, enforcing it requires calling `limit_hit()` — zero willpower required. The coded limit enforces the same discipline J20 teaches manually but removes the human failure mode entirely. Omitting it re-introduces the revenge trading risk that algorithmic trading is specifically designed to structurally eliminate.