← लेखों की सूची पर वापस जाएँ
May 16, 2025
5 मिनट का पठन

Trading Candles Demystified: How Raw Trades Become the Foundation of Market Analysis

Trading Candles Demystified: How Raw Trades Become the Foundation of Market Analysis
#candles
#trading
#aggregation
#visualization
#research

Trading Candles Demystified Data to Visuals: The algorithmic aggregation of raw high-speed trade streams into structured market candlesticks.

Candlestick charts are everywhere in trading — from professional terminals to meme crypto bots. But what exactly is a "candle," and how do we build them from the raw, chaotic stream of trades? In this article, we'll break down the process, highlight the tricky edge-cases, and share an interactive visualizer so you can see candles form in real time.

Try the visualizer here: candle-trade-visualizer.vercel.app


TL;DR

  • A trading candle is a compact summary of price and volume for a fixed time interval (like 1 minute).
  • Aggregation is the process of turning a stream of trades into these candles.
  • Edge-cases (duplicates, gaps, out-of-order trades) matter for accuracy.
  • Visualizer: Play with trades and see candles form live!

What is a Trading Candle?

A candle (or candlestick) is a summary of market activity over a specific period (e.g., 1 minute, 1 hour, 1 day). Each candle contains:

  • Open — price of the first trade in the interval
  • High — highest price
  • Low — lowest price
  • Close — price of the last trade
  • Volume — total traded amount
  • Trade count — number of trades

It looks simple, but the devil is in the details.


From Trades to Candles: The Aggregation Process

1. The Raw Trade Stream

Every millisecond, exchanges generate trades:

{
  "timestamp": 1714000000000,
  "price": 50000.0,
  "amount": 0.1,
  "side": "Buy"
}

There can be thousands of trades per second, each just a record of a buy or sell.

2. Time-Based Grouping

To build candles, we group trades by time. For example, all trades from 12:00:00 to 12:00:59 go into the same 1-minute (m1) candle.

Algorithm:

  • For each trade, determine which interval it belongs to (truncate timestamp).
  • If a candle for that interval exists, update its high/low/close/volume.
  • If not, start a new candle.

3. Edge-Cases: Why It's Not So Simple

  • Out-of-order trades: Trades may arrive out of sequence (due to network delays, etc.).
  • Duplicates: The same trade might appear more than once.
  • Boundary trades: What if a trade lands exactly on the interval boundary?
  • Gaps: What if there are intervals with no trades?

A robust aggregation must handle all these cases. In the industry, this is critical for accurate analytics and algorithmic trading.


Example: Candle Aggregation in Code

Here's a minimal Rust example (the logic is the same in any language):

for trade in trades {
    let ts = truncate_to_tf(trade.timestamp, timeframe);
    if let Some(candle) = current_candle {
        if candle.timestamp == ts {
            // update high/low/close/volume
        } else {
            // save the current candle, start a new one
        }
    } else {
        // first candle
    }
}

Note: For correct aggregation, the trade stream should be sorted by time. If not, you need to sort first or use an algorithm that's robust to out-of-order data.


Why Does This Matter?

  • Charts: All your favorite platforms (TradingView, Binance, etc.) build their charts from candles.
  • Algorithmic trading: Strategies operate on candles, not raw trades.
  • Analytics: Indicators, signals, and statistics are all based on OHLCV data.
  • AGI and automation: For machine analysis, you need strict, unambiguous data.

Try It Yourself: Interactive Candle Visualizer

We built an interactive visualizer:
👉 candle-trade-visualizer.vercel.app

  • Add trades manually or randomly.
  • Watch how they aggregate into candles.
  • Experiment with different timeframes and edge-cases.

Conclusion

Candles are the foundation of all market analysis. Behind every simple chart is a complex aggregation process, designed to be robust against errors and edge-cases. If you're building your own systems, make sure to handle all the nuances — otherwise, your charts and strategies might be misleading.

Try the visualizer, dig into the details, and make your candles honest!


Links:


If you found this article useful, share it with your colleagues and let's make market data more transparent for everyone!

Citation

@software{soloviov2025tradingcandlesdemystified,
  author = {Soloviov, Eugen},
  title = {Trading Candles Demystified: How Raw Trades Become the Foundation of Market Analysis},
  year = {2025},
  url = {https://marketmaker.cc/en/blog/post/trading-candles-demystified},
  version = {0.1.0},
  description = {How are trading candles built from raw trades? This article explains the aggregation process, edge-cases, and offers an interactive visualizer to see candles form in real time.}
}
blog.disclaimer

MarketMaker.cc Team

क्वांटिटेटिव रिसर्च और स्ट्रैटेजी

Telegram पर चर्चा करें
Newsletter

बाज़ार से आगे रहें

AI ट्रेडिंग इनसाइट्स, मार्केट एनालिसिस और प्लेटफ़ॉर्म अपडेट के लिए हमारे न्यूज़लेटर को सब्सक्राइब करें।

हम आपकी गोपनीयता का सम्मान करते हैं। किसी भी समय अनसब्सक्राइब करें।