{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/tradingpal-io/json-schema/tradingpal-io-scan-schema.json",
  "title": "Scan",
  "description": "What the last nightly scan found across the whole market, ranked.",
  "x-generated": "2026-11-27",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/tradingpal-io-openapi.json#/components/schemas/Scan",
  "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."
    },
    "available": {
      "type": "boolean",
      "description": "True when the nightly has a current book. False when no book exists for the session; setups is then empty."
    },
    "status": {
      "type": "string",
      "description": "The status filter applied: forming, in_progress or all.",
      "enum": [
        "forming",
        "in_progress",
        "all"
      ]
    },
    "filters": {
      "type": "object",
      "description": "The other filters as applied, null where none was sent.",
      "properties": {
        "family": {
          "type": [
            "string",
            "null"
          ],
          "description": "The family filter."
        },
        "direction": {
          "type": [
            "string",
            "null"
          ],
          "description": "The direction filter."
        },
        "max_distance_pct": {
          "type": [
            "number",
            "null"
          ],
          "description": "The distance cap."
        },
        "tier": {
          "type": [
            "array",
            "null"
          ],
          "items": {
            "type": "string"
          },
          "description": "The Edge Filter tiers kept, null when none was sent."
        },
        "predicates": {
          "type": "array",
          "items": {
            "type": "object"
          },
          "description": "The screener predicates as applied, in canonical form and order; empty when none was sent."
        }
      }
    },
    "sort": {
      "type": "string",
      "description": "The order applied: rank (the screener order) or edge (the Edge Filter order).",
      "enum": [
        "rank",
        "edge"
      ]
    },
    "count": {
      "type": "integer",
      "description": "How many setups matched the filters, before paging."
    },
    "limit": {
      "type": "integer",
      "description": "The page size applied (1 to 200)."
    },
    "offset": {
      "type": "integer",
      "description": "The offset applied."
    },
    "setups": {
      "type": "array",
      "description": "This page of the ranked setups, best rank first.",
      "items": {
        "$ref": "#/$defs/ScanSetup",
        "description": "One ranked setup."
      }
    }
  },
  "required": [
    "api_version",
    "as_of_session",
    "source",
    "disclaimer",
    "available",
    "status",
    "count",
    "limit",
    "offset",
    "setups"
  ],
  "$defs": {
    "ScanSetup": {
      "type": "object",
      "title": "ScanSetup",
      "description": "One row of the nightly scan: the same Setup object the per-ticker route returns, plus its place in the ranking.",
      "properties": {
        "rank": {
          "type": "integer",
          "description": "Position in the screener's ranking for this status on this session: 1 is the best-ranked forming setup of the night (or the first in-progress trade). Ranks are assigned over the whole book before any filter, so rank 7 stays rank 7 when the request narrows by family."
        },
        "expected_gain_pct": {
          "type": [
            "number",
            "null"
          ],
          "description": "Typical return, as the TradingPal screener labels it, and the value the ranking sorts by: the typical winning move for this pattern on this ticker in percent, blended with the family's record (ticker evidence weighted by its trade count). Null when the setup is not ranked; unranked rows sort last."
        },
        "win_rate_pct": {
          "type": [
            "number",
            "null"
          ],
          "description": "The win rate the TradingPal screener shows on this setup, in percent: the share of past trades of this pattern that reached the target. Null without a track record."
        },
        "win_rate_trades": {
          "type": [
            "integer",
            "null"
          ],
          "description": "How many past trades win_rate_pct counts. Null without a track record."
        },
        "distance_to_trigger_pct": {
          "type": [
            "number",
            "null"
          ],
          "description": "How far the last close is from the trigger price, in percent of the close, signed: positive when price must rise to reach the trigger. Small is \"about to break out\". Null without a last close or plan."
        },
        "setup_id": {
          "type": "string",
          "description": "Identifier of this pattern occurrence in the current nightly book. Pass it as setup_id to the chart.png route. It is stable while the setup stays current and is not valid across nights, so re-read the patterns when the chart route answers setup_not_found."
        },
        "lineage_id": {
          "type": [
            "string",
            "null"
          ],
          "description": "Key of the candidate lineage this occurrence belongs to, shared by the revisions of the same detected pattern. Null when the stored candidate carries none."
        },
        "page_url": {
          "type": [
            "string",
            "null"
          ],
          "description": "Link that opens this setup on the TradingPal site: the Screener quick view, focused on the ticker, naming this exact setup. Free to read. Give it to the user when the chat app cannot show the chart image."
        },
        "symbol": {
          "type": "string",
          "description": "Exchange symbol, upper case."
        },
        "interval": {
          "type": "string",
          "description": "Bar interval. Always D: daily bars.",
          "const": "D"
        },
        "family": {
          "type": "string",
          "description": "The display family of the pattern, one of rising_wedge, falling_wedge, bullish_pennant, bearish_pennant, triangle.",
          "enum": [
            "rising_wedge",
            "falling_wedge",
            "bullish_pennant",
            "bearish_pennant",
            "triangle"
          ]
        },
        "family_label": {
          "type": "string",
          "description": "Human-readable family name, for example \"Falling wedge\"."
        },
        "pattern_type": {
          "type": [
            "string",
            "null"
          ],
          "description": "The detector's own pattern type, which can be more specific than family (for example a triangle subtype). Null when the artifact carries none."
        },
        "direction": {
          "type": [
            "string",
            "null"
          ],
          "description": "The side the pattern is expected to resolve to: bullish or bearish. Null when the pattern has no single direction, such as a symmetrical triangle that carries a plan for each side.",
          "enum": [
            "bullish",
            "bearish",
            null
          ]
        },
        "status": {
          "type": "string",
          "description": "Lifecycle stage of the setup: forming until the trigger rule fires, in_progress once a daily close has triggered it (entered is then present). Defaults to forming when the artifact stores no stage."
        },
        "pattern_start": {
          "type": [
            "string",
            "null"
          ],
          "description": "Session date of the first bar of the pattern, as an ISO date. Null when unknown.",
          "format": "date"
        },
        "pattern_end": {
          "type": [
            "string",
            "null"
          ],
          "description": "Session date of the last bar of the detected pattern, as an ISO date; the lines run on past it to the last session. Null when unknown.",
          "format": "date"
        },
        "as_of_session": {
          "type": [
            "string",
            "null"
          ],
          "description": "The session this setup is valid for, as an ISO date; the same value as the envelope's as_of_session.",
          "format": "date"
        },
        "last_close": {
          "type": [
            "number",
            "null"
          ],
          "description": "The close of the last session before as_of_session, in dollars, so a caller can place the trigger relative to price without another quote; every route reports the same value for the same setup. Null when no price is stored."
        },
        "price_scale": {
          "type": "string",
          "description": "Always log: the lines are straight in log price, so draw them on a log-scale price axis.",
          "const": "log"
        },
        "lines": {
          "type": "object",
          "description": "The two boundary lines of the pattern.",
          "properties": {
            "upper": {
              "type": [
                "object",
                "null"
              ],
              "description": "The upper boundary. Bullish plans trigger on a daily close above it. Null when the stored pattern has no upper line.",
              "properties": {
                "start": {
                  "type": "object",
                  "description": "The earlier endpoint: the session and price where the line begins.",
                  "properties": {
                    "date": {
                      "type": "string",
                      "description": "Session date of the bar, as an ISO date.",
                      "format": "date"
                    },
                    "price": {
                      "type": "number",
                      "description": "Price in dollars, rounded to four decimals."
                    }
                  },
                  "required": [
                    "date",
                    "price"
                  ]
                },
                "end": {
                  "type": "object",
                  "description": "The later endpoint, at the end of the pattern geometry. The trigger price sits on the extension of the line past this point.",
                  "properties": {
                    "date": {
                      "type": "string",
                      "description": "Session date of the bar, as an ISO date.",
                      "format": "date"
                    },
                    "price": {
                      "type": "number",
                      "description": "Price in dollars, rounded to four decimals."
                    }
                  },
                  "required": [
                    "date",
                    "price"
                  ]
                },
                "touch_count": {
                  "type": [
                    "integer",
                    "null"
                  ],
                  "description": "How many bars touched the line, as the detector counted them; the length of touches when no count is stored."
                },
                "touches": {
                  "type": "array",
                  "description": "The bars that touched the line, in the order the detector recorded them, so a charting tool can reproduce the fit. May be empty.",
                  "items": {
                    "type": "object",
                    "description": "One touch: the session date and the bar high (upper line) or bar low (lower line).",
                    "properties": {
                      "date": {
                        "type": "string",
                        "description": "Session date of the touching bar, as an ISO date.",
                        "format": "date"
                      },
                      "price": {
                        "type": [
                          "number",
                          "null"
                        ],
                        "description": "The bar high (upper line) or low (lower line) in dollars. Null when that bar is not in the stored candle tail."
                      }
                    },
                    "required": [
                      "date",
                      "price"
                    ]
                  }
                }
              }
            },
            "lower": {
              "type": [
                "object",
                "null"
              ],
              "description": "The lower boundary. Bearish plans trigger on a daily close below it. Null when the stored pattern has no lower line.",
              "properties": {
                "start": {
                  "type": "object",
                  "description": "The earlier endpoint: the session and price where the line begins.",
                  "properties": {
                    "date": {
                      "type": "string",
                      "description": "Session date of the bar, as an ISO date.",
                      "format": "date"
                    },
                    "price": {
                      "type": "number",
                      "description": "Price in dollars, rounded to four decimals."
                    }
                  },
                  "required": [
                    "date",
                    "price"
                  ]
                },
                "end": {
                  "type": "object",
                  "description": "The later endpoint, at the end of the pattern geometry. The trigger price sits on the extension of the line past this point.",
                  "properties": {
                    "date": {
                      "type": "string",
                      "description": "Session date of the bar, as an ISO date.",
                      "format": "date"
                    },
                    "price": {
                      "type": "number",
                      "description": "Price in dollars, rounded to four decimals."
                    }
                  },
                  "required": [
                    "date",
                    "price"
                  ]
                },
                "touch_count": {
                  "type": [
                    "integer",
                    "null"
                  ],
                  "description": "How many bars touched the line, as the detector counted them; the length of touches when no count is stored."
                },
                "touches": {
                  "type": "array",
                  "description": "The bars that touched the line, in the order the detector recorded them, so a charting tool can reproduce the fit. May be empty.",
                  "items": {
                    "type": "object",
                    "description": "One touch: the session date and the bar high (upper line) or bar low (lower line).",
                    "properties": {
                      "date": {
                        "type": "string",
                        "description": "Session date of the touching bar, as an ISO date.",
                        "format": "date"
                      },
                      "price": {
                        "type": [
                          "number",
                          "null"
                        ],
                        "description": "The bar high (upper line) or low (lower line) in dollars. Null when that bar is not in the stored candle tail."
                      }
                    },
                    "required": [
                      "date",
                      "price"
                    ]
                  }
                }
              }
            }
          }
        },
        "trigger_rule": {
          "type": [
            "string",
            "null"
          ],
          "description": "The trigger rule in one sentence, chosen by direction: a daily close above the upper line, below the lower line, or through either line when the pattern carries a plan per side. Always present."
        },
        "edge_filter": {
          "type": [
            "object",
            "null"
          ],
          "description": "The setup's Edge Filter tier and night rank: its best order's, the tier its card shows; each plan carries its own. The TradingPal Edge Filter's grade from the night's run, as the card's tier ribbon shows it. Null when the night did not grade it.",
          "properties": {
            "tier": {
              "type": [
                "string",
                "null"
              ],
              "description": "S, A, B, C, or F (refused). Null only when locked.",
              "enum": [
                "S",
                "A",
                "B",
                "C",
                "F",
                null
              ]
            },
            "rank": {
              "type": [
                "integer",
                "null"
              ],
              "description": "The place among the night's graded orders the Edge Filter keeps, 1 = best (S with rank 3 reads S3). Null on F."
            },
            "refused": {
              "type": [
                "boolean",
                "null"
              ],
              "description": "True on F: the Edge Filter and Autopilot skip it. Null when locked."
            },
            "reason": {
              "type": [
                "string",
                "null"
              ],
              "description": "Why the grade refused it, when it said (for example similar_trades_floor, or short: every short is F). Null otherwise."
            },
            "session": {
              "type": [
                "string",
                "null"
              ],
              "description": "The session the grade is for, as an ISO date.",
              "format": "date"
            },
            "locked": {
              "type": "boolean",
              "description": "True for a reader without Premium (the keyless demo): the tier is served as null."
            }
          }
        },
        "plans": {
          "type": "array",
          "description": "One trade plan per direction the pattern can resolve in: usually one, two for a symmetrical triangle. Empty when the stored candidate has no eligible branch.",
          "items": {
            "type": "object",
            "description": "The trade plan for one direction: the close that confirms the pattern, the stop and the target.",
            "properties": {
              "direction": {
                "type": "string",
                "description": "The side this plan trades: bullish (a close above the upper line) or bearish (a close below the lower line).",
                "enum": [
                  "bullish",
                  "bearish"
                ]
              },
              "trigger_price": {
                "type": [
                  "number",
                  "null"
                ],
                "description": "The daily close that confirms the pattern, in dollars, as of the last session. It sits on the boundary line, so it moves a little each session. Null when the stored branch has none."
              },
              "stop_price": {
                "type": [
                  "number",
                  "null"
                ],
                "description": "The stop level in dollars. The backtest freezes it at entry and fills it on a touch, or at the open after an adverse gap. Null when the stored branch has none."
              },
              "target_price": {
                "type": [
                  "number",
                  "null"
                ],
                "description": "The measured-move target in dollars: the pattern height projected from the trigger. Null when the stored branch has none."
              },
              "edge_filter": {
                "type": [
                  "object",
                  "null"
                ],
                "description": "This order's own Edge Filter tier and night rank. The TradingPal Edge Filter's grade from the night's run, as the card's tier ribbon shows it. Null when the night did not grade it.",
                "properties": {
                  "tier": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "description": "S, A, B, C, or F (refused). Null only when locked.",
                    "enum": [
                      "S",
                      "A",
                      "B",
                      "C",
                      "F",
                      null
                    ]
                  },
                  "rank": {
                    "type": [
                      "integer",
                      "null"
                    ],
                    "description": "The place among the night's graded orders the Edge Filter keeps, 1 = best (S with rank 3 reads S3). Null on F."
                  },
                  "refused": {
                    "type": [
                      "boolean",
                      "null"
                    ],
                    "description": "True on F: the Edge Filter and Autopilot skip it. Null when locked."
                  },
                  "reason": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "description": "Why the grade refused it, when it said (for example similar_trades_floor, or short: every short is F). Null otherwise."
                  },
                  "session": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "description": "The session the grade is for, as an ISO date.",
                    "format": "date"
                  },
                  "locked": {
                    "type": "boolean",
                    "description": "True for a reader without Premium (the keyless demo): the tier is served as null."
                  }
                }
              },
              "estimates": {
                "type": [
                  "object",
                  "null"
                ],
                "description": "The TradingPal model's estimates for this order, as the setup card shows them, from the night it was graded. Null when the grade gave the order none (a sell, or an order the grade does not hold). Quote them as estimates, under their labels.",
                "properties": {
                  "win_chance_pct": {
                    "type": [
                      "number",
                      "null"
                    ],
                    "description": "Win chance: the estimated chance the trade wins, as a percent."
                  },
                  "avg_return_pct": {
                    "type": [
                      "number",
                      "null"
                    ],
                    "description": "Est. avg return: the estimated average return per trade, net %, over wins and losses."
                  },
                  "est_win_pct": {
                    "type": [
                      "number",
                      "null"
                    ],
                    "description": "Est. win: the estimated median winning move from the trigger, as a percent; target_price is this move from the trigger."
                  },
                  "labels": {
                    "type": "object",
                    "description": "The site's label for each number."
                  },
                  "locked": {
                    "type": "array",
                    "description": "The estimates served as null because the reader is not on Premium (the keyless demo).",
                    "items": {
                      "type": "string",
                      "description": "A field name."
                    }
                  },
                  "summary": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "description": "The estimates in one sentence, under their labels."
                  },
                  "source": {
                    "type": "string",
                    "description": "How the estimates are made, in one sentence."
                  }
                }
              },
              "similar_trades": {
                "$ref": "#/$defs/SimilarRecord",
                "description": "The record of the earlier look-alike trades for this order, as the site's Similar trades panel states it. Null when the evening search holds no answer for the order (it is rebuilt each evening)."
              }
            }
          }
        },
        "track_record": {
          "type": "object",
          "description": "The backtest records behind this setup, at family scope and at ticker scope.",
          "properties": {
            "family": {
              "$ref": "#/$defs/StatBlock",
              "description": "The family's record over the served universe. Null when no record is sealed for the family."
            },
            "ticker": {
              "$ref": "#/$defs/StatBlock",
              "description": "The record of this family on this ticker. Null when the ticker has no resolved history for the family, or too few trades to display."
            }
          }
        },
        "entered": {
          "type": "object",
          "description": "The fill, present only once the trigger has fired (status in_progress). Absent while forming.",
          "properties": {
            "entry_date": {
              "type": [
                "string",
                "null"
              ],
              "description": "Session date of the bar that triggered the setup, as an ISO date. Null when the artifact stores no entry time.",
              "format": "date"
            },
            "entry_price": {
              "type": [
                "number",
                "null"
              ],
              "description": "The entry price in dollars, recorded when the trigger fired."
            },
            "stop_price": {
              "type": [
                "number",
                "null"
              ],
              "description": "The stop in dollars, frozen at entry."
            },
            "target_price": {
              "type": [
                "number",
                "null"
              ],
              "description": "The target in dollars, fixed at entry."
            }
          }
        }
      },
      "required": [
        "rank",
        "setup_id",
        "symbol",
        "family",
        "status",
        "lines",
        "plans",
        "track_record"
      ]
    },
    "SimilarRecord": {
      "type": [
        "object",
        "null"
      ],
      "title": "SimilarRecord",
      "description": "How the earlier trades whose pattern looked most like this order's did: each on any stock, same side, entered and exited before this order. Quote summary whole; never the win rate alone.",
      "properties": {
        "count": {
          "type": "integer",
          "description": "How many similar trades were found (up to 50)."
        },
        "wins": {
          "type": [
            "integer",
            "null"
          ],
          "description": "How many of them won."
        },
        "losses": {
          "type": [
            "integer",
            "null"
          ],
          "description": "How many of them lost."
        },
        "win_rate_pct": {
          "type": [
            "number",
            "null"
          ],
          "description": "wins / count as a percent."
        },
        "avg_return_pct": {
          "type": [
            "number",
            "null"
          ],
          "description": "Their average return per trade, in percent before costs."
        },
        "avg_r": {
          "type": [
            "number",
            "null"
          ],
          "description": "Their average R multiple."
        },
        "locked": {
          "type": "boolean",
          "description": "True when the record is held back because the reader is not on Premium."
        },
        "floor": {
          "type": "object",
          "description": "The Edge Filter similar-trades check on this order: state none, judged or refused, with count and wins."
        },
        "summary": {
          "type": "string",
          "description": "The record in one sentence, to quote whole."
        }
      }
    },
    "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."
        }
      }
    }
  }
}