Trading journal calculations

Build custom trading journal session performance metrics that run only in your browser and power the session Report tab and custom report layouts. Manage them at Calculations — they never leave your browser when a session performance table runs.

Who this is for

Use calculations when built-in metrics are not enough — for example win rate your way, expectancy, or a custom risk score. You write a small JavaScript function; EndureTrade runs it against the trades on that session and shows the result in the performance table.

Function shape

Your source must define function calculate(params) and return a non-empty array of number or string values. Single-value table cells show the last array element.

function calculate(params) {
  // params: trades for this session (already filtered by long/short/all)
  console.log('trade count', params.trades.length);
  return [params.trades.length];
}

Data you receive

calculate receives capital and a list of trades. There is no separate side field — the performance tab filters long/short/all and passes that subset as params.trades.

interface CalculationParams {
  capital: number;
  trades: Trade[];
}

interface Trade {
  id: string; // uuid
  userId: string;
  sessionId: string;
  tradeNumber: number;
  symbol: string;
  direction: 'long' | 'short';
  positionSize: number;
  entryPrice: number;
  openedAt: string; // ISO 8601 UTC
  /** Omit while the position is still open. */
  exitPrice?: number;
  closedAt?: string;
  profitLoss?: number;
  note?: string;
  tags?: string[];
  entryMethod?: string;
  exitMethod?: string;
  stopLoss?: number;
  takeProfit?: number;
  favorableExcursion?: number;
  adverseExcursion?: number;
  timeframe?: string;
  createdAt: string;
  updatedAt: string;
  messages?: Array<{ id: string; content?: string; createdAt: string }>;
}

Built-in helpers

The calculation sandbox automatically provides these functions — you do not paste them into your source_code. They are available in the calculation tester and on session performance cards. Expand each function to see its full implementation.

Testing and logs

In the calculation form tester, use console.log, console.warn, or console.error. Captured lines appear in a Logs section under the result (they are not shown on the session performance table).

Prefer console for debug output. You can also put intermediate strings in the return array — the performance table still displays only the last element:

function calculate(params) {
  var closed = (params.trades || []).filter(function (t) {
    return typeof t.profitLoss === 'number';
  });
  // last value is the cell display; earlier strings are visible in the tester Result JSON
  return ['closed=' + closed.length, closed.length];
}

Errors and timeout

Thrown errors become { ok: false, error: "…" }. Invalid returns use Invalid return type. Runs that exceed your timeout (Settings → Preferences, default 5000 ms) are stopped and return Calculation timed out.

Results appear on the session Report layouts tab — bind metric, graph, and table cards to these calculations. Prefer a file backup? See the Calculations import guide.