Skip to content
All library documents

Constructing Custom Candles and Indicators from Market Data

Article FMZ digest · Author: 发明者量化-小小梦

Summary

This tutorial explains how to build nonstandard candle intervals from smaller bars. It combines open from the first bar, close from the last, the maximum high, minimum low, summed volume, and the first bar’s timestamp. The example aggregates hourly cryptocurrency bars into four-hour candles and discusses alignment: the target interval must be an integral multiple of the source interval and must close cleanly within the chosen hour or day cycle. The provided implementation uses local time-zone information when determining boundaries, so timestamp conventions and alignment should be checked for the intended market.

Key ideas

  • Aggregate candle open and close from the first and last source bars, and take the maximum high and minimum low.
  • Sum source-bar volume and retain the first source bar’s timestamp for the combined candle.
  • The target interval must be an integral multiple of the source interval and align to a complete cycle.
  • To calculate an indicator from highs rather than closes, construct a corresponding array of high values first.
  • Exchange candle endpoints can return limited history, so the tutorial also demonstrates requesting a larger dataset directly from an exchange API.

Tags

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.