{
  "$defs": {
    "Timeframe": {
      "description": "Bar duration. These seven are the only granularities the data layer serves.",
      "enum": [
        "1m",
        "5m",
        "15m",
        "30m",
        "1h",
        "4h",
        "1d"
      ],
      "title": "Timeframe",
      "type": "string"
    }
  },
  "additionalProperties": false,
  "description": "Distance from the current bar to an event type's next or previous occurrence.\n\n``direction=\"previous\"`` counts back to the latest occurrence at or before the\nbar: 0 on the bar the occurrence is assigned to. ``direction=\"next\"`` counts\nforward to the earliest occurrence strictly after the bar, so it is never 0\nin minutes. ``unit`` is wall-clock minutes or bars.\n\nWhen no such occurrence is known the value is infinity (present, not absent), so\n``distance <= N`` is false and ``not (distance <= N)`` is true: that is how a\n\"stay away from events\" gate is written.\n\nA ``next`` distance needs the event's date to be known in advance. Among system\nevents only those with a forward release calendar (macro.cpi,\nmacro.nonfarm_payrolls, macro.unemployment) qualify; any other system event is\nrefused with ``direction=\"next\"``, because the platform cannot anticipate it.\nCustom events are unrestricted. Use ``direction=\"previous\"`` to react after a\nsystem event.\n\nExample, within 5 bars after an event:\n  {\"kind\": \"event_distance\", \"event_type_id\": \"my-signal\", \"direction\": \"previous\",\n   \"unit\": \"bars\"}",
  "properties": {
    "direction": {
      "description": "'previous' = distance back to the latest occurrence at or before this bar. 'next' = distance forward to the earliest occurrence after this bar; needs a custom event or a system event with a forward release calendar.",
      "enum": [
        "next",
        "previous"
      ],
      "title": "Direction",
      "type": "string"
    },
    "event_type_id": {
      "description": "Event type ID from list_event_types().",
      "title": "Event Type Id",
      "type": "string"
    },
    "kind": {
      "const": "event_distance",
      "default": "event_distance",
      "title": "Kind",
      "type": "string"
    },
    "resolution": {
      "anyOf": [
        {
          "$ref": "#/$defs/Timeframe"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "description": "Optional higher-timeframe override for this value ref. Set it inside left/right refs such as {'kind': 'indicator', ..., 'resolution': '4h'} or {'kind': 'price', 'field': 'close', 'resolution': '4h'}. Do not put timeframe/source_timeframe on the parent condition. None = strategy timeframe."
    },
    "symbol": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "description": "Optional reference symbol this value ref reads from (e.g. 'SPY'). None = the traded/primary symbol. Mutually exclusive with resolution.",
      "title": "Symbol"
    },
    "unit": {
      "anyOf": [
        {
          "enum": [
            "minutes",
            "bars"
          ],
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "description": "Measure the distance in wall-clock minutes or in bars; minutes when omitted.",
      "title": "Unit"
    }
  },
  "required": [
    "event_type_id",
    "direction"
  ],
  "title": "EventDistanceValueRef",
  "type": "object"
}
