PnL Tracking
PnL Tracking
Profit and Loss (PnL) tracking tells you whether your grid bot is actually making money. Gridera tracks PnL at multiple levels: per trade, per session, and over the bot’s lifetime. Understanding each type helps you evaluate performance accurately and make better decisions about your configuration.
Realized vs Unrealized PnL
The most important distinction in PnL tracking is between realized and unrealized profit.
Realized PnL is profit that has been locked in through completed trades. When the bot buys at $95 and the TP sells at $96, the $1 difference (minus fees) is realized profit. This money is yours regardless of what the price does next. It cannot decrease unless you make new trades that lose money.
Unrealized PnL is the paper profit or loss on positions you currently hold. If the bot bought at $95 and the current price is $93, you have an unrealized loss of $2 per unit. If the price recovers to $97, that becomes an unrealized gain of $2. Unrealized PnL fluctuates constantly with the market price.
The key insight: a grid bot with high realized PnL and temporary unrealized losses is performing well. The realized profits are permanent, while the unrealized losses will likely recover as the price oscillates back through the grid.
Session PnL
Session PnL tracks performance from the moment you start the bot until you stop it. It includes both realized and unrealized components.
Each time you restart the bot, the session PnL resets to zero. This gives you a clean measurement of each run’s performance. Session PnL is useful for evaluating whether a configuration change improved results.
Session PnL data is stored in a session file that updates as trades complete. The dashboard reads this file to display current session metrics.
Lifetime PnL
Lifetime PnL accumulates across all sessions. When you stop and restart the bot, the lifetime tracker preserves previous session results and continues adding to them.
This gives you the true long-term picture of your bot’s profitability. A bot might have several sessions with small losses during trending markets but overall positive lifetime PnL from productive sideways periods. Looking only at individual sessions would miss this bigger picture.
Lifetime PnL is stored in a persistent file that survives bot restarts and updates with each completed trade.
How PnL Is Calculated
For each completed grid trade, the realized PnL calculation is:
Realized PnL = (Sell price - Buy price) x Quantity - Total fees
For a long grid bot that buys at $95 and sells at $96, with 10 units and 0.02% maker fees on each side:
- Gross profit = ($96 - $95) x 10 = $10
- Buy fee = $95 x 10 x 0.0002 = $0.19
- Sell fee = $96 x 10 x 0.0002 = $0.192
- Net realized PnL = $10 - $0.19 - $0.192 = $9.618
Unrealized PnL is calculated as:
Unrealized PnL = (Current price - Entry price) x Position quantity
For a long position entered at $95 with 10 units and current price at $93:
- Unrealized PnL = ($93 - $95) x 10 = -$20
PnL Files
Gridera stores PnL data in two files:
realized_pnl.json: Contains the cumulative realized PnL across all sessions. This file updates each time a TP order fills and a round-trip trade completes. The data includes total realized profit, number of completed trades, and average profit per trade.
session.json: Contains the current session’s PnL data. This resets when the bot restarts. It includes session start time, session realized PnL, trade count, and the most recent trade details.
Both files are written to the pnl/ directory and are read by the dashboard for display.
Reading PnL on the Dashboard
The dashboard presents PnL information in several ways:
Total PnL number: The combined realized and unrealized PnL. This is the headline number but can be misleading during temporary drawdowns. A bot with $50 realized profit and -$30 unrealized shows $20 total, but the $50 is permanent while the -$30 is temporary.
PnL chart: A time-series chart showing how PnL has evolved. Look for a generally upward-trending line with dips during price drops. A healthy grid bot shows a staircase pattern: flat during holds, stepping up when TP orders fill.
Trade history: Individual completed trades with their profit contribution. This lets you see which grid levels are generating the most profit and how frequently trades occur.
Common PnL Patterns
Staircase pattern: Realized PnL steps up with each completed trade while unrealized PnL oscillates. This is the ideal grid bot pattern indicating consistent trade completion.
Sawtooth pattern: PnL rises gradually then drops sharply. This happens when the price trends down through multiple grid levels, accumulating positions that create large unrealized losses. The sharp drops reverse when the price recovers.
Flat line: No trades are completing. The price is either above your entire grid (no buys filling) or below (no TPs filling). Consider adjusting your range.
Steady decline: Both realized and unrealized PnL are trending down. This usually indicates fees are consuming more than the grid spacing generates, or funding costs are eroding profits. Review your fee optimization and spacing.
Summary
- Realized PnL is locked-in profit from completed trades; unrealized PnL fluctuates with current positions and market price.
- Session PnL resets on each restart, while lifetime PnL accumulates across all sessions for long-term performance tracking.
- A healthy grid bot shows a staircase PnL pattern with realized profits stepping up and unrealized PnL oscillating.
Next Step
Learn how to assess and manage risk using the risk panel in Risk Panel Usage.
✨ Was this article helpful?
Ask your questions on Ask on Discord →