I have ticks data in format: Date, Time, Open, High, Low, Close, Volume. 11/09/2014,17:00:00,2019.00,2019.00,2019.00,2019.00,5 11/09/2014,17:00:00,2020.00,2020.00,2020.00,2020.00,25 11/09/2014,17:00:00,2028.00,2028.00,2028.00,2028.00,20 11/09/2014,17:00:00,2030.00,2030.00,2030.00,2030.00,10 11/09/2014,17:00:00,2035.00,2035.00,2035.00,2035.00,30 11/09/2014,17:00:00,2037.00,2037.00,2037.00,2037.00,15 11/09/2014,17:00:00,2038.00,2038.00,2038.00,2038.00,10 11/09/2014,17:00:00,2040.00,2040.00,2040.00,2040.00,40

I am trying to construct range bars from this data with range 2.00. It is clear for me how to built that if difference between high and low reaches strictly 2.00. But there are some cases when that difference becomes more than 2.00. So how many bars will be present in this case? What open, high, low, close, volume values will these bars have? I would very appreciate if somebody give me an explanation and convert data I provided to Open, High, Low, Close, Volume format.

  • $\begingroup$ Hi Andrii, can you clarify exactly what you mean? Are you looking for code how to aggregate range bars or more of a general concept of how to do it? If you share a diagram to explain the question that would also be helpful. $\endgroup$ Jan 5, 2017 at 11:46
  • 1
    $\begingroup$ @Dr.ABT, basically I am looking for a concept. As I understand to display bar chart we need convert tick data to OHLC data. It is look obvious how to do this with certain timeframe (e.g 1 min, 5 min...). But I don't know how to construct OHLC data if there is range limit for bars. Sometimes we might have situation when difference between ticks is bigger than range limit. Then probably there is a need to build a couple of bars but I'm not sure. $\endgroup$ Jan 5, 2017 at 18:28
  • $\begingroup$ Did you ever find a solution for this? Looking for the same thing $\endgroup$
    – user41244
    May 31, 2019 at 12:46
  • $\begingroup$ Any working example for this? Looking for the same solution $\endgroup$
    – Karun
    Mar 8, 2021 at 23:02

1 Answer 1


if you are using OHLC data, you are not sure if High is first or low is first.

you have to convert data to numpy series first e.g. H -L- C- H- L- C-H-L-C create numpy range from maximum to minimum value in the range with bin size as your range bar size use numpy.digitize function to fill the bins.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.