PnL Tracking

🟢 Iniciante · 2025-03-28

PnL Tracking

Lucros e Perdas (PnL) tracking tells you se your grid bot is actually making money. Gridera tracks PnL at multiple levels: per trade, per session, and over o bot’s lifetime. Understanding each type te ajuda a evaluate performance accurately and make better decisions about sua configuracao.

Realized vs UnPnL realizado

A distincao mais importante in PnL tracking is between realized and unrealized profit.

Realized PnL is lucro que foi garantido atraves de operacoes concluidas. When o bot compra at $95 and the TP sells at $96, the $1 difference (minus fees) is realized profit. This money is yours independentemente de what o preco does next. It cannot decrease a menos que you make new trades that lose money.

UnPnL realizado is the paper profit or loss on positions you currently hold. If o bot bought at $95 and the preco atual is $93, voce tem an unrealized loss of $2 per unit. If o preco recovers to $97, that becomes an unrealized gain of $2. UnPnL realizado fluctuates constantly with o mercado price.

A chave insight: a grid bot with high PnL realizado and temporary unrealized losses is performing well. The realized profits are permanent, enquanto o unrealized losses will likely recover as o preco oscila back atraves do grid.

Session PnL

Session PnL tracks performance from the moment you start o bot until you stop it. It includes ambos realized and unrealized components.

Each time you restart o bot, the session PnL resets to zero. This gives you a clean measurement of each run’s performance. Session PnL is useful for evaluating se 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. Quando voce stop and restart o bot, the lifetime tracker preserves previous session results and continues adding to them.

This gives you the true long-term picture of seu bot’s profitability. A bot might have several sessions with small losses during mercado com tendencias 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 PnL realizado 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 PnL realizado = $10 - $0.19 - $0.192 = $9.618

UnPnL realizado e calculado as:

UnPnL realizado = (Current price - Entry price) x Position quantity

For a long position entered at $95 with 10 units and preco atual at $93:

  • UnPnL realizado = ($93 - $95) x 10 = -$20

PnL Files

Gridera stores PnL data in two files:

realized_pnl.json: Contains the cumulative PnL realizado across all sessions. This file updates cada vez que 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 o bot restarts. It includes session start time, session PnL realizado, trade count, and o mais 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 PnL nao realizado. 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 enquanto o -$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 nivel de grids are generating o mais profit and how frequently trades occur.

Common PnL Patterns

Staircase pattern: Realized PnL steps up with each completed trade while PnL nao realizado oscillates. This is the ideal grid bot pattern indicating consistent trade completion.

Sawtooth pattern: PnL rises gradually then drops sharply. This happens quando o preco trends down through multiple nivel de grids, accumulating positions that create large unrealized losses. The sharp drops reverse quando o preco recovers.

Flat line: No trades are completing. O preco is either above your entire grid (no buys filling) or below (no TPs filling). Consider adjusting your range.

Steady decline: Both realized and PnL nao realizado are trending down. The geralmente indicates fees are consuming mais que o grid spacing generates, or funding costs are eroding profits. Review your fee optimization and spacing.

Resumo

  • Realized PnL is locked-in profit from completed trades; PnL nao realizado 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 PnL nao realizado oscillating.

Proximo Passo

Learn how to assess and manage risk using o risco panel in Risk Panel Usage.

✨ Este artigo foi util?

Faca suas perguntas no Discord →