MetaAPI Risk Metrics Mapping

Complete mapping of Risk Metrics Spec to MetaAPI endpoints and fields

Legend

Available Field is available directly from MetaAPI
Partial Field can be calculated from MetaAPI data
Missing Field is not provided by MetaAPI - requires storage/tracking
⚠️ Important: Some metrics require additional storage and tracking beyond what MetaAPI provides. Fields marked as "Missing" need to be stored in your database or calculated from historical data.

I. Limits & Risk Budgets

1 Max Daily Loss (MDL) Partial
Definition: Maximum permitted loss within a trading day.
MDL_USD = startOfMonthBalance * MDL_RATE

Required Fields:

startOfMonthBalance - MISSING
Implementation: MetaAPI does not provide start-of-month balance. You must:
1. Store balance at 00:00 first day of month (database or cache)
2. Or reconstruct from account history using readDealsByTimeRange()
MDL_RATE - MISSING
Implementation: This is a configuration value (e.g., 0.05 for 5%). Store in database/config file.
2 Max Monthly Loss (MML) Partial
Definition: Maximum permitted loss within the current month.
MML_USD = startOfMonthBalance * MML_RATE

Required Fields:

startOfMonthBalance - MISSING
Implementation: Same as MDL - store at month start or reconstruct from history.
MML_RATE - MISSING
Implementation: Configuration value (e.g., 0.10 for 10%). Store in database/config.
3 Overall Drawdown (ODD) Partial
Definition: Total drawdown budget vs. base capital/peak.
ODD_USD = peakBalance * DD_RATE (or peakNav * DD_RATE for fund policy)

MetaAPI Endpoints:

GET connection.readAccountInformation()

Required Fields:

accountInformation.balance - AVAILABLE
// Get current balance
const accountInfo = await connection.readAccountInformation();
const currentBalance = accountInfo.balance;
accountInformation.equity - AVAILABLE
// Get current equity (NAV)
const equity = accountInfo.equity;
peakBalance - MISSING
Implementation: Track and update when new peak reached. Store in database and compare with current balance on each update.
peakNav - MISSING
Implementation: Track peak equity value. Update when equity > current peakNav.
startingCapital - MISSING
Implementation: Store initial account balance when first deployed. Fallback for ODD calculation if no peak balance.
DD_RATE - MISSING
Implementation: Configuration value (e.g., 0.10 for 10%). Store in database/config.
4 Risk Exposure (USD) Available
Definition: Total open risk converted to USD (risk-to-SL preferred).
riskPerPosition = |entryPrice - stopLoss| * contractValuePerPoint * volume
riskExposureUsd = Σ riskPerPosition

MetaAPI Endpoints:

GET connection.readPositions()
GET connection.readSymbolSpecification(symbol)

Required Fields:

positions[].openPrice - AVAILABLE
positions[].stopLoss - AVAILABLE
Note: stopLoss may be undefined if not set. Handle missing SL per your policy (exclude or estimate via ATR).
positions[].volume - AVAILABLE
contractValuePerPoint - PARTIAL
Calculation: From symbol specification:
contractValuePerPoint = tickValue / tickSize
Get from: readSymbolSpecification(symbol).tickValue and .tickSize
// Calculate contract value per point
const spec = await connection.readSymbolSpecification(symbol);
const contractValuePerPoint = spec.tickValue / spec.tickSize;

// Calculate risk per position
const priceDistance = Math.abs(position.openPrice - (position.stopLoss || 0));
const riskPerPosition = priceDistance * contractValuePerPoint * position.volume;
5-7 Current/Monthly/Overall Risk Load (%) Partial
Definition: Risk loads as percentages of budgets.
currentRiskLoad = riskExposureUsd / mdlUsd
monthlyRiskLoad = riskExposureUsd / remainingMonthlyBudgetUsd
overallRiskLoad = riskExposureUsd / remainingOverallBudgetUsd

All Required Fields:

riskExposureUsd - AVAILABLE
Calculated from positions (see metric #4)
mdlUsd, remainingMonthlyBudgetUsd, remainingOverallBudgetUsd - PARTIAL
Depend on metrics 1-3 and realized loss MTD (see metric #10)

II. Capital & P/L Metrics

8 Balance Available
Definition: Account balance excluding floating P/L. Reset: New month; or per policy when ODD hit.

MetaAPI Endpoint:

GET connection.readAccountInformation()

Field Mapping:

accountInformation.balance - AVAILABLE
const accountInfo = await connection.readAccountInformation();
const balance = accountInfo.balance;
9 Equity (NAV) Available
Definition: equity = balance + floatingPL

MetaAPI Endpoint:

GET connection.readAccountInformation()

Field Mapping:

accountInformation.equity - AVAILABLE
const accountInfo = await connection.readAccountInformation();
const equity = accountInfo.equity;

// Floating P/L can be calculated:
const floatingPL = accountInfo.equity - accountInfo.balance;
10 Realized Loss MTD Available
Definition: Sum of closed negative P/L since start of month.
realizedLossMtd = Σ max(0, -closedDeal.pl) for deals closed within month

MetaAPI Endpoint:

GET connection.readDealsByTimeRange(from, to)

Field Mapping:

deals[].pl - AVAILABLE
Note: Filter deals by closeTime to get month-to-date deals only.
deals[].closeTime - AVAILABLE
// Get deals from start of month
const now = new Date();
const startOfMonth = new Date(now.getFullYear(), now.getMonth(), 1, 0, 0, 0, 0);

const deals = await connection.readDealsByTimeRange(
    startOfMonth.toISOString(),
    now.toISOString()
);

// Calculate realized loss MTD
const realizedLossMtd = deals
    .filter(deal => deal.pl < 0)
    .reduce((sum, deal) => sum + Math.abs(deal.pl), 0);
11 Remaining Balance Partial
Definition: Safe balance remainder after realized monthly loss.
remainingBalance = startOfMonthBalance - realizedLossMtd

Required Fields:

startOfMonthBalance - MISSING
Must be stored or reconstructed from history
realizedLossMtd - AVAILABLE
Calculated from deals (see metric #10)
12-13 Remaining Monthly/Overall Budget Partial
Definition: Remaining room to lose this month/overall.
remainingMonthlyBudgetUsd = MML_USD - realizedLossMtd
remainingOverallBudgetUsd = ODD_USD - realizedLossMtd

Required Fields:

MML_USD, ODD_USD - PARTIAL
Calculated from metrics 2-3 (require stored rates and balances)
realizedLossMtd - AVAILABLE
From deals (see metric #10)

III. Trade Activity

14 Active Orders Available
Definition: Count of currently open positions.
activeOrders = count(positionsOpen)

MetaAPI Endpoint:

GET connection.readPositions()

Field Mapping:

positions.length - AVAILABLE
const positions = await connection.readPositions();
const activeOrders = positions.length;
15 Consecutive Losing Trades Available
Definition: Number of consecutive losing closed trades (ignoring tiny volume ≤0.01 lots).

MetaAPI Endpoint:

GET connection.readDealsByTimeRange(from, to)
GET connection.readDealsByPosition(positionId)

Field Mapping:

deals[].pl - AVAILABLE
deals[].volume - AVAILABLE
Implementation: Filter deals with volume > 0.01 lots. Count consecutive deals where pl < 0, reset on first winning trade (pl > 0).
// Get all deals, sorted by close time (most recent first)
const deals = await connection.readDealsByTimeRange(
    startDate.toISOString(),
    endDate.toISOString()
);

// Calculate consecutive losing trades
let consecutiveLosingTrades = 0;
for (let i = deals.length - 1; i >= 0; i--) {
    const deal = deals[i];
    // Ignore tiny volume
    if (deal.volume <= 0.01) continue;
    
    if (deal.pl < 0) {
        consecutiveLosingTrades++;
    } else if (deal.pl > 0) {
        // Winning trade resets counter
        break;
    }
}

Summary: Field Availability Matrix

Metric Status MetaAPI Endpoint Notes
startOfMonthBalance MISSING - Store at month start or reconstruct from deals
peakBalance / peakNav MISSING - Track and update when new peak reached
startingCapital MISSING - Store when first deployed
balance AVAILABLE readAccountInformation() accountInformation.balance
equity AVAILABLE readAccountInformation() accountInformation.equity
floatingPL AVAILABLE readAccountInformation() equity - balance
positions (openPrice, stopLoss, volume) AVAILABLE readPositions() positions[].openPrice, .stopLoss, .volume
deals (pl, closeTime, volume) AVAILABLE readDealsByTimeRange() deals[].pl, .closeTime, .volume
symbolSpec (tickValue, tickSize) AVAILABLE readSymbolSpecification(symbol) spec.tickValue, spec.tickSize
MDL_RATE, MML_RATE, DD_RATE MISSING - Configuration values - store in DB/config

Implementation Checklist

Required Storage/Database Fields:
  • startOfMonthBalance - Store at 00:00 first day of month
  • peakBalance - Track maximum balance reached
  • peakNav - Track maximum equity reached
  • startingCapital - Store initial balance on deployment
  • MDL_RATE, MML_RATE, DD_RATE - Configuration values
  • Reset markers - Track when ODD hit and system reset
Available from MetaAPI (no storage needed):
  • balance, equity, floatingPL - from readAccountInformation()
  • Open positions - from readPositions()
  • Closed deals - from readDealsByTimeRange()
  • Symbol specifications - from readSymbolSpecification()