Fetching latest headlines…
How to Build Unbroken Candlestick Charts for US Stocks: A Three-Layer Session Tagging Approach
NORTH AMERICA
πŸ‡ΊπŸ‡Έ United Statesβ€’July 7, 2026

How to Build Unbroken Candlestick Charts for US Stocks: A Three-Layer Session Tagging Approach

1 views0 likes0 comments
Originally published byDev.to

The Problem: Candlestick Gaps That Confuse Users and Algorithms

When our team integrated US stock market data into a platform originally built for cryptocurrency traders, we ran into a persistent issue: candlestick charts exhibited ugly jumps around market open and close. Pre-market price moves would disappear from the visual timeline, and low-volume after-hours prints would create phantom volume spikes. The root cause? Most raw data feeds dump all ticks into a single undifferentiated stream, ignoring the fact that US equities trade in three distinct sessions β€” pre-market (4:00–9:30 ET), regular (9:30–16:00), and after-hours (16:00–20:00). Our users, many of whom are professional advisors and algo traders, demanded a chart that was visually continuous without sacrificing logical accuracy.

Traditional Pains: When Advisors Manually Strip Session Noise

Before we shipped our solution, we spent hours interviewing power users. A recurring complaint: they were forced to manually filter out non-regular-hours data before running technical analysis, because indicators like VWAP and RSI would be skewed by stray trades in thin markets. This manual step was error-prone and impossible to automate at scale. They needed the platform to handle session semantics transparently, leaving them to focus on strategy.

The Data Architecture That Made Continuity Possible

We tackled this by designing a three-tier tick processing pipeline:

  1. Raw Tick Ingestion – Using real-time WebSocket streams (e.g., AllTick), we capture every transaction with microsecond precision. No filtering, no judgment β€” just collection.
  2. Normalization & Session Labeling – All timestamps are converted to US Eastern Time. A simple time-window function assigns each tick a session label (pre_market, regular, after_hours). Outlier filtering happens here as well.
  3. Session-Aware OHLC Aggregation – When building K-lines, we partition ticks by session and time bucket. Crucially, we never merge volumes across session boundaries, which eliminates the phantom spike problem entirely. Bars are generated only where actual trades exist β€” we never fabricate "filler" candles.
# WebSocket tick ingestion with session labeling downstream
import websocket
import json

url = "wss://stream.alltick.co/v1/stock/realtime"

def on_message(ws, message):
    data = json.loads(message)
    # In production, session label and aggregation logic are applied here
    print(data)

def on_open(ws):
    sub_msg = {
        "action": "subscribe",
        "channel": "transaction_quote",
        "symbols": ["AAPL"]
    }
    ws.send(json.dumps(sub_msg))

ws = websocket.WebSocketApp(
    url,
    on_message=on_message,
    on_open=on_open
)
ws.run_forever()

The result: a visually seamless candlestick chart where each segment knows whether it belongs to pre-market, regular, or after-hours trading. Algorithms can optionally filter by session, but the default view is free of artificial gaps.

Service Upgrade: Making Session Intelligence a Platform Feature

We subsequently wrapped this pipeline into a dedicated market-data microservice. Product teams can now request session-aware candlestick series via a single API parameter. This has significantly reduced onboarding time for new chart features and allowed our quant community to run session-specific backtests without extra data wrangling. What started as a chart glitch turned into a key differentiator.

Comments (0)

Sign in to join the discussion

Be the first to comment!