# Volume Base OHLC

**URL:** <https://forum.kx.com/t/volume-base-ohlc/8728>\
**Category:** Community Support\
**Tags:** kdb-and-q\
**Created:** [April 11, 2014, 9:43pm UTC](https://forum.kx.com/t/volume-base-ohlc/8728 "2014-04-11T21:43:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![carwilki](https://avatars.discourse-cdn.com/v4/letter/c/df705f/32.png) [@carwilki](https://forum.kx.com/u/carwilki)\
**Post date:** [April 11, 2014, 9:43pm UTC](https://forum.kx.com/t/volume-base-ohlc/8728/1 "2014-04-11T21:43:00Z")

</div>

Forgive me very new to this, but here is my question

Given my trade table&nbsp;

date &nbsp;| 2013.12.02

time &nbsp;| 12:00:09.159

sym &nbsp; | `MSFT

price | 38.2

volume| 300i

I can build an ohlc bar that is time sensitive like so&nbsp;

q)select open:first price,high:max price,low:min price,close:last price,volume:sum volume by 60 xbar time.minute from trades where time\> 14:00

minute| open &nbsp; high &nbsp; &nbsp;low &nbsp; &nbsp; close &nbsp; volume

------| --------------------------------------

14:00 | 38.15 &nbsp;38.49 &nbsp; 38.04 &nbsp; 38.37 &nbsp; 5849796

15:00 | 38.37 &nbsp;38.49 &nbsp; 38.15 &nbsp; 38.37 &nbsp; 8491338

16:00 | 38.37 &nbsp;38.54 &nbsp; 38.3498 38.533 &nbsp;4526692

17:00 | 38.535 38.78 &nbsp; 38.4984 38.515 &nbsp;5384621

18:00 | 38.51 &nbsp;38.6925 38.44 &nbsp; 38.4944 3233415

19:00 | 38.495 38.535 &nbsp;38.44 &nbsp; 38.508 &nbsp;3591717

20:00 | 38.505 38.51 &nbsp; 38.3401 38.455 &nbsp;8158938

21:00 | 38.46 &nbsp;38.659 &nbsp;38.28 &nbsp; 38.34 &nbsp; 6853541

22:00 | 38.34 &nbsp;38.45 &nbsp; 38.34 &nbsp; 38.39 &nbsp; 19570

23:00 | 38.39 &nbsp;38.4 &nbsp; &nbsp;38.36 &nbsp; 38.4 &nbsp; &nbsp;2580

My question is how would i build some sort of OHLC query that would take into account the grouping off of the sum of the volume? Allowing me to build bars that are based off of volume.

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![Attila](https://avatars.discourse-cdn.com/v4/letter/a/b9bd4f/32.png) [@Attila](https://forum.kx.com/u/Attila)\
**Post date:** [April 13, 2014, 1:09pm UTC](https://forum.kx.com/t/volume-base-ohlc/8728/2 "2014-04-13T13:09:00Z")

</div>

by 1000000 xbar sums volume

Cheers,

&nbsp; Attila

---

<div class="post-metadata">

**Author:** ![kuentang](https://avatars.discourse-cdn.com/v4/letter/k/bc8723/32.png) [@kuentang](https://forum.kx.com/u/kuentang)\
**Post date:** [April 13, 2014, 1:18pm UTC](https://forum.kx.com/t/volume-base-ohlc/8728/3 "2014-04-13T13:18:00Z")

</div>

Something like this?\<o:p\>\</o:p\>

\<o:p\> \</o:p\>

N:25\<o:p\>\</o:p\>

(::)t:`time xasc (time:N?.z.t;prx:0.01\*floor 100\*10 + N?1.0;qty:N?500)\<o:p\>\</o:p\>

select last time, o:first prx,h:max prx,l:min prx,c:last prx,qty by 1000 xbar sums qty from t\<o:p\>\</o:p\>

\<o:p\> \</o:p\>

Kim\<o:p\>\</o:p\>

\<o:p\> \</o:p\>

**Von:** [personal-kdbplus@googlegroups.com](mailto:personal-kdbplus@googlegroups.com) [[mailto:personal-kdbplus@googlegroups.com](mailto:personal-kdbplus@googlegroups.com)] **Im Auftrag von** Carson Wilkins  
**Gesendet:** Freitag, 11. April 2014 22:44  
**An:** [personal-kdbplus@googlegroups.com](mailto:personal-kdbplus@googlegroups.com)  
**Betreff:** [personal kdb+] Volume Base OHLC\<o:p\>\</o:p\>

\<o:p\> \</o:p\>

Forgive me very new to this, but here is my question\<o:p\>\</o:p\>

\<o:p\> \</o:p\>

Given my trade table&nbsp;\<o:p\>\</o:p\>

\<o:p\> \</o:p\>

date &nbsp;| 2013.12.02\<o:p\>\</o:p\>

time &nbsp;| 12:00:09.159\<o:p\>\</o:p\>

sym &nbsp; | `MSFT\<o:p\>\</o:p\>

price | 38.2\<o:p\>\</o:p\>

volume| 300i\<o:p\>\</o:p\>

\<o:p\> \</o:p\>

I can build an ohlc bar that is time sensitive like so&nbsp;\<o:p\>\</o:p\>

\<o:p\> \</o:p\>

q)select open:first price,high:max price,low:min price,close:last price,volume:sum volume by 60 xbar time.minute from trades where time\> 14:00\<o:p\>\</o:p\>

minute| open &nbsp; high &nbsp; &nbsp;low &nbsp; &nbsp; close &nbsp; volume\<o:p\>\</o:p\>

------| --------------------------------------\<o:p\>\</o:p\>

14:00 | 38.15 &nbsp;38.49 &nbsp; 38.04 &nbsp; 38.37 &nbsp; 5849796\<o:p\>\</o:p\>

15:00 | 38.37 &nbsp;38.49 &nbsp; 38.15 &nbsp; 38.37 &nbsp; 8491338\<o:p\>\</o:p\>

16:00 | 38.37 &nbsp;38.54 &nbsp; 38.3498 38.533 &nbsp;4526692\<o:p\>\</o:p\>

17:00 | 38.535 38.78 &nbsp; 38.4984 38.515 &nbsp;5384621\<o:p\>\</o:p\>

18:00 | 38.51 &nbsp;38.6925 38.44 &nbsp; 38.4944 3233415\<o:p\>\</o:p\>

19:00 | 38.495 38.535 &nbsp;38.44 &nbsp; 38.508 &nbsp;3591717\<o:p\>\</o:p\>

20:00 | 38.505 38.51 &nbsp; 38.3401 38.455 &nbsp;8158938\<o:p\>\</o:p\>

21:00 | 38.46 &nbsp;38.659 &nbsp;38.28 &nbsp; 38.34 &nbsp; 6853541\<o:p\>\</o:p\>

22:00 | 38.34 &nbsp;38.45 &nbsp; 38.34 &nbsp; 38.39 &nbsp; 19570\<o:p\>\</o:p\>

23:00 | 38.39 &nbsp;38.4 &nbsp; &nbsp;38.36 &nbsp; 38.4 &nbsp; &nbsp;2580\<o:p\>\</o:p\>

\<o:p\> \</o:p\>

My question is how would i build some sort of OHLC query that would take into account the grouping off of the sum of the volume? Allowing me to build bars that are based off of volume.\<o:p\>\</o:p\>

\<o:p\> \</o:p\>

Thanks in advance!\<o:p\>\</o:p\>

–  
Submitted via Google Groups

---

<div class="post-metadata">

**Author:** ![carwilki](https://avatars.discourse-cdn.com/v4/letter/c/df705f/32.png) [@carwilki](https://forum.kx.com/u/carwilki)\
**Post date:** [April 14, 2014, 5:38am UTC](https://forum.kx.com/t/volume-base-ohlc/8728/4 "2014-04-14T05:38:00Z")

</div>

Thank you this works to get me started in the direction that i need to go.!
