{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/tradingpal-io/json-schema/tradingpal-io-filter-track-record-schema.json",
  "title": "FilterTrackRecord",
  "description": "The backtest of one screener filter set: the screener's Track record panel.",
  "x-generated": "2026-11-27",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/tradingpal-io-openapi.json#/components/schemas/FilterTrackRecord",
  "type": "object",
  "properties": {
    "api_version": {
      "type": "string",
      "const": "v1",
      "description": "The contract version, always v1. Field names in v1 do not change, and v1 stays available at least 12 months after a v2 ships."
    },
    "as_of_session": {
      "type": [
        "string",
        "null"
      ],
      "description": "The last trading session the data describes, as an ISO date. Setups change nightly, so say it when presenting data and do not cache setups across days. Null on routes that do not read a dated artifact (account, tickers, history, families, universe and the demo index).",
      "format": "date"
    },
    "data_version": {
      "type": [
        "string",
        "null"
      ],
      "description": "Identifier of the stored artifact the answer came from: the candidate-book generation for patterns, the sealed manifest for family records. Null when the route reads no versioned artifact."
    },
    "source": {
      "type": "object",
      "description": "Who produced the data. Constant on every response.",
      "properties": {
        "name": {
          "type": "string",
          "description": "Always \"TradingPal\"."
        },
        "url": {
          "type": "string",
          "description": "Always https://tradingpal.io.",
          "format": "uri"
        }
      }
    },
    "disclaimer": {
      "type": "string",
      "const": "Educational breakout-pattern analysis from TradingPal, not investment advice. Past results do not guarantee future outcomes.",
      "description": "The educational-use disclaimer, constant on every response. Repeat it when presenting a setup as something the user might act on."
    },
    "family": {
      "type": [
        "string",
        "null"
      ],
      "description": "The family asked for (rising_wedge, falling_wedge, bullish_pennant, bearish_pennant, triangle); null for all five."
    },
    "label": {
      "type": "string",
      "description": "The family's display name, or All patterns."
    },
    "edge": {
      "type": "object",
      "description": "The Edge Filter side the record was cut from.",
      "properties": {
        "requested": {
          "type": "string",
          "description": "off or on, as asked.",
          "enum": [
            "off",
            "on"
          ]
        },
        "applied": {
          "type": "boolean",
          "description": "False when on was asked of a ledger that seals no Edge Filter tiers; the record is then every trade's."
        }
      }
    },
    "filters": {
      "type": "object",
      "description": "How the filters were used.",
      "properties": {
        "applied": {
          "type": "array",
          "description": "The predicates that cut the past trades, canonical.",
          "items": {
            "type": "object"
          }
        },
        "left_out": {
          "type": "array",
          "description": "Predicates the record ignores, each with its reason: they describe today (market cap, security type, exchange, sector, country, phase, distance, the model's estimates) or the ledger holds no values for them.",
          "items": {
            "type": "object"
          }
        }
      }
    },
    "matched_trades": {
      "type": "integer",
      "description": "Past trades that matched every applied filter."
    },
    "too_few": {
      "type": "boolean",
      "description": "True under minimum_trades matched trades; track_record is then null."
    },
    "minimum_trades": {
      "type": "integer",
      "description": "The fewest matched trades a record is given for."
    },
    "track_record": {
      "$ref": "#/$defs/StatBlock",
      "description": "The record of the matched trades (scope filtered). Null when too_few."
    },
    "unfiltered": {
      "$ref": "#/$defs/StatBlock",
      "description": "The same family's record without the filters, on the same Edge Filter side, for comparison (scope unfiltered)."
    },
    "note": {
      "type": [
        "string",
        "null"
      ],
      "description": "Why no win rate is given, when too_few."
    }
  },
  "required": [
    "api_version",
    "as_of_session",
    "source",
    "disclaimer"
  ],
  "$defs": {
    "StatBlock": {
      "type": [
        "object",
        "null"
      ],
      "title": "StatBlock",
      "description": "A track record: how one pattern family resolved over the last 20 years of the served universe, or how it resolved on one ticker. Null where a record would go when none is stored; never a partial block. Never present win_rate_pct without sample_size and avg_loss_pct; quote summary whole.",
      "properties": {
        "scope": {
          "type": "string",
          "description": "family when the record covers every ticker in the served universe, ticker when it covers one symbol; on /track-record, filtered for the trades a filter set kept and unfiltered for the same family's record without the filters.",
          "enum": [
            "family",
            "ticker",
            "filtered",
            "unfiltered"
          ]
        },
        "family": {
          "type": "string",
          "description": "The pattern family the record is for (rising_wedge, falling_wedge, bullish_pennant, bearish_pennant, triangle; patterns for all five on /track-record)."
        },
        "symbol": {
          "type": [
            "string",
            "null"
          ],
          "description": "The ticker at ticker scope; null at family scope."
        },
        "win_rate_pct": {
          "type": [
            "number",
            "null"
          ],
          "description": "Share of resolved trades that reached the target, as a percent (54.0 means 54%), one decimal. At ticker scope the stored rate is shrunk toward the family rate so a handful of trades cannot read as 0% or 100%; wins and losses stay raw. Never quote it without sample_size and avg_loss_pct."
        },
        "sample_size": {
          "type": "integer",
          "description": "Number of trades in the record: the stored trade count, or wins plus losses when no count is stored. The summary sentence quotes it as resolved trades."
        },
        "wins": {
          "type": "integer",
          "description": "Resolved trades that reached the target."
        },
        "losses": {
          "type": "integer",
          "description": "Resolved trades that hit the stop. A bar that reaches both target and stop counts as a loss."
        },
        "avg_win_pct": {
          "type": [
            "number",
            "null"
          ],
          "description": "Mean price move of the winning trades from entry to exit, as a percent of the entry price (positive), two decimals."
        },
        "avg_loss_pct": {
          "type": [
            "number",
            "null"
          ],
          "description": "Mean price move of the losing trades from entry to exit, as a percent of the entry price (negative), two decimals."
        },
        "median_win_pct": {
          "type": [
            "number",
            "null"
          ],
          "description": "Median winning move as a percent of the entry price: the typical win, less sensitive to outliers than avg_win_pct."
        },
        "avg_trade_pct": {
          "type": [
            "number",
            "null"
          ],
          "description": "Mean price move over all resolved trades, wins and losses together, as a percent of the entry price."
        },
        "avg_r": {
          "type": [
            "number",
            "null"
          ],
          "description": "Mean R multiple over resolved trades, where one R is the entry-to-stop distance; 0.41 means the average trade made 0.41 times its risk."
        },
        "expected_r": {
          "type": [
            "number",
            "null"
          ],
          "description": "Per-trade expectancy in R: win rate times the average winning R plus loss rate times the average losing R. Equals avg_r when both come from the same trades."
        },
        "profit_factor": {
          "type": [
            "number",
            "null"
          ],
          "description": "Gross R of the winning trades divided by gross R of the losing trades; above 1 means the wins outweigh the losses. Null when the record has no losses."
        },
        "avg_hold_bars": {
          "type": [
            "number",
            "null"
          ],
          "description": "Mean number of daily bars (sessions) from entry to exit over resolved trades, one decimal."
        },
        "backtest_range": {
          "type": [
            "array",
            "null"
          ],
          "items": {
            "type": "string",
            "description": "An ISO date.",
            "format": "date"
          },
          "minItems": 2,
          "maxItems": 2,
          "description": "The window the trades were taken from, as [first date, last date] in ISO format, at most the last 20 years. Null when the record carries no dates."
        },
        "measured": {
          "type": "string",
          "description": "The measurement rule in one paragraph: how entries, stops, targets and exits are counted. Identical on every block."
        },
        "summary": {
          "type": "string",
          "description": "One sentence with the sample size, the window, the win rate, the average win, the average loss and the median win. Quote it whole rather than picking numbers out of it."
        }
      }
    }
  }
}