# Candlestick Scanner Ranking and Deduplication

`D06-F05-A09` · Price Action and Candlesticks → Candlestick Scanning and Context · archetype `record-transform` · difficulty 4/5 · verification **verified**

Full page: https://docs.thefintechbuilder.com/price-action-and-candlesticks/candlestick-scanning-and-context/candlestick-scanner-ranking-and-deduplication/
Agent skill: `npx skills add IslamBaraka90/Fintech-Algorithms-Library` — https://docs.thefintechbuilder.com/guides/agent-skill/

## Install and import

```bash
npm install fintech-algorithms
```

```ts
import { rankAndDeduplicate } from "fintech-algorithms/price-action-and-candlesticks/candlestick-scanning-and-context/candlestick-scanner-ranking-and-deduplication";
```

## Signature

```ts
rankAndDeduplicate(data)
```

calculate a traceable composite rank, keep deterministic order, and deduplicate only within an explicit identity key and bar window.

## Parameters

| Name | Type | Required | Notes |
| --- | --- | --- | --- |
| `data` | `{ recency_half_life_bars: number; dedup_window_bars: number; occurrences: { occurrence_id: string; instrument_id: string; interval: string; pattern_id: string; direction: string; end_index: number; confidence: number; age_bars: number; liquidity_score: number; priority_score: number }[] }` | yes | Topic input record; the required fields are fixed by this topic data-contract. |

## Returns

`{ state, ranked_count, suppressed_count, ranked, suppressed }`

One `ready` ranking record containing stable ranks and component traces for kept occurrences plus reason-coded duplicates and both counts.

## Complexity

Time `O(n log n) worst case; see README for topic-specific n`, space `O(n)`.

## Worked example

This is the worked example published in the article, replayed by the test suite on every run. The output cannot drift.

### Input

`data`:

```json
{
  "recency_half_life_bars": 5,
  "dedup_window_bars": 2,
  "occurrences": [
    {
      "occurrence_id": "A",
      "instrument_id": "SYNTH:AAA",
      "interval": "5m",
      "pattern_id": "D06-F03-A01",
      "direction": "bullish",
      "end_index": 10,
      "confidence": 90,
      "age_bars": 1,
      "liquidity_score": 0.8,
      "priority_score": 0.8
    },
    {
      "occurrence_id": "B",
      "instrument_id": "SYNTH:AAA",
      "interval": "5m",
      "pattern_id": "D06-F03-A01",
      "direction": "bullish",
      "end_index": 11,
      "confidence": 85,
      "age_bars": 0,
      "liquidity_score": 0.9,
      "priority_score": 0.9
    },
    {
      "occurrence_id": "C",
      "instrument_id": "SYNTH:BBB",
      "interval": "5m",
      "pattern_id": "D06-F02-A06",
      "direction": "bullish",
      "end_index": 11,
      "confidence": 70,
      "age_bars": 2,
      "liquidity_score": 1,
      "priority_score": 0.5
    }
  ]
}
```

### Call

```ts
rankAndDeduplicate(data)
```

### Returns

object with 3 fields: state, ranked_count, suppressed_count

```json
{
  "state": "ready",
  "ranked_count": 2,
  "suppressed_count": 1
}
```

## Verification and provenance

Tier: **verified** (via input-expected).

The worked example below is the figure published in this algorithm's article, replayed and asserted by the test suite on every build. The arithmetic cannot drift without the build failing.

Both tiers guarantee the signature. Full explanation: https://docs.thefintechbuilder.com/guides/verification/

Generated from the docs.json payload shipped inside fintech-algorithms@0.12.0.
The signature and parameter list are checked against the compiled implementation at build time,
so a description that contradicts the code fails the build rather than reaching this file.

## Links

- Article (how it works, step by step): https://thefintechbuilder.com/price-action-and-candlesticks/candlestick-scanning-and-context/candlestick-scanner-ranking-and-deduplication/
- Implementation source: https://github.com/IslamBaraka90/Fintech-Algorithms-Library/blob/main/src/price-action-and-candlesticks/candlestick-scanning-and-context/candlestick-scanner-ranking-and-deduplication/impl.ts
- Package on npm: https://www.npmjs.com/package/fintech-algorithms
- Domain index for agents: https://docs.thefintechbuilder.com/price-action-and-candlesticks/llms.txt
