# Is there any way to create candlestick on ODD TimeSpan from  tick

**URL:** <https://forum.kx.com/t/is-there-any-way-to-create-candlestick-on-odd-timespan-from-tick/8042>\
**Category:** Community Support\
**Tags:** kdb-and-q\
**Created:** [December 13, 2012, 4:44pm UTC](https://forum.kx.com/t/is-there-any-way-to-create-candlestick-on-odd-timespan-from-tick/8042 "2012-12-13T16:44:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![shewenhao](https://avatars.discourse-cdn.com/v4/letter/s/f17d59/32.png) [@shewenhao](https://forum.kx.com/u/shewenhao)\
**Post date:** [December 13, 2012, 4:44pm UTC](https://forum.kx.com/t/is-there-any-way-to-create-candlestick-on-odd-timespan-from-tick/8042/1 "2012-12-13T16:44:00Z")

</div>

ear All KDB+ Gurus,

I have tick Data and I know that &nbsp;I could convert it to minute bar easily by this way:

“select High: &nbsp;max Price, Low: min Price, Open: first Price, Close: last Price by &nbsp;1 xbar Time.minute from Trade where Symbol = `BAC”

And the tickdata looks like this:

Time &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Symbol &nbsp; &nbsp; &nbsp; &nbsp;Price

* * *

09:30:01.333 &nbsp; &nbsp; &nbsp; BAC &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;9.10

…

Now is my question, is &nbsp;there any possible to convert the tick data into candlestick on some weird timespan? From example, 5 seconds, 7 seconds or 55 seconds. I know it sounds &nbsp;weird but &nbsp;just curious whether here is any advance command or function I &nbsp;could use?

Thanks in advance.

Best

Wenhao

&nbsp;&nbsp;

---

<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:** [December 13, 2012, 5:23pm UTC](https://forum.kx.com/t/is-there-any-way-to-create-candlestick-on-odd-timespan-from-tick/8042/2 "2012-12-13T17:23:00Z")

</div>

Do you mean this?\<o:p\>\</o:p\>

select High: &nbsp;max Price, Low: min Price, Open: first Price, Close: last Price by &nbsp;5 xbar Time.second from Trade where Symbol = `BAC\<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** she wenhao  
**Gesendet:** Donnerstag, 13. Dezember 2012 17:44  
**An:** [personal-kdbplus@googlegroups.com](mailto:personal-kdbplus@googlegroups.com)  
**Betreff:** [personal kdb+] Is there any way to create candlestick on ODD TimeSpan from tick data by using xbar function.\<o:p\>\</o:p\>

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

ear All KDB+ Gurus,\<o:p\>\</o:p\>

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

I have tick Data and I know that &nbsp;I could convert it to minute bar easily by this way:\<o:p\>\</o:p\>

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

“select High: &nbsp;max Price, Low: min Price, Open: first Price, Close: last Price by &nbsp;1 xbar Time.minute from Trade where Symbol = `BAC”\<o:p\>\</o:p\>

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

And the tickdata looks like this:\<o:p\>\</o:p\>

Time &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Symbol &nbsp; &nbsp; &nbsp; &nbsp;Price\<o:p\>\</o:p\>

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

09:30:01.333 &nbsp; &nbsp; &nbsp; BAC &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;9.10\<o:p\>\</o:p\>

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

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

Now is my question, is &nbsp;there any possible to convert the tick data into candlestick on some weird timespan? From example, 5 seconds, 7 seconds or 55 seconds. I know it sounds &nbsp;weird but &nbsp;just curious whether here is any advance command or function I &nbsp;could use?\<o:p\>\</o:p\>

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

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

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

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

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

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

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

&nbsp;&nbsp;\<o:p\>\</o:p\>

–  
Submitted via Google Groups

---

<div class="post-metadata">

**Author:** ![shewenhao](https://avatars.discourse-cdn.com/v4/letter/s/f17d59/32.png) [@shewenhao](https://forum.kx.com/u/shewenhao)\
**Post date:** [December 13, 2012, 5:27pm UTC](https://forum.kx.com/t/is-there-any-way-to-create-candlestick-on-odd-timespan-from-tick/8042/3 "2012-12-13T17:27:00Z")

</div>

Thanks lot &nbsp;Kuentang,

Yes, it is. I tried some &nbsp;ODD timespan on this like by 7 xbar Time.second from Trade where Symbol = `BAC and it rocks. Really interesting that I could have some 7 second or 77 second bar, lol

Have a nice day~~~

Wenhao

---

<div class="post-metadata">

**Author:** ![Andras\_Bohak](https://avatars.discourse-cdn.com/v4/letter/a/9d8465/32.png) [@Andras\_Bohak](https://forum.kx.com/u/Andras_Bohak)\
**Post date:** [December 14, 2012, 8:10am UTC](https://forum.kx.com/t/is-there-any-way-to-create-candlestick-on-odd-timespan-from-tick/8042/4 "2012-12-14T08:10:00Z")

</div>

To: [personal-kdbplus@googlegroups.com](mailto:personal-kdbplus@googlegroups.com)  
X-Mailer: Apple Mail (2.1283)  
X-Gm-Message-State: ALoCoQkVtz7m3ruoVs8N7DDArk+jkwIaEL4Cn2kwHsuMfNiSJ92doR0WmsMBQGQ+C9YEIjSBxXiE

If you liked 7 seconds, how about 7.123?:)

select High: max Price, Low: min Price, Open: first Price, Close: last =  
Price by 7123 xbar Time from Trade where Symbol = `BAC

2012.12.13. d=E1tummal, 18:27 id=F5pontban she wenhao =EDrta:

\> Thanks lot Kuentang,  
\>  
\> Yes, it is. I tried some ODD timespan on this like by 7 xbar =  
Time.second from Trade where Symbol = `BAC and it rocks. Really = interesting that I could have some 7 second or 77 second bar, lol \> \> Have a nice day~~~ \> \> Wenhao \> \> On Thursday, December 13, 2012 12:23:35 PM UTC-5, kuentang wrote: \> Do you mean this? \> \> select High: max Price, Low: min Price, Open: first Price, Close: = last Price by 5 xbar Time.second from Trade where Symbol = `BAC  
\>  
\>  
\> Von: [personal...@googlegroups.com](mailto:personal...@googlegroups.com) =  
[[mailto:personal...@googlegroups.com](mailto:personal...@googlegroups.com)] Im Auftrag von she wenhao  
\> Gesendet: Donnerstag, 13. Dezember 2012 17:44  
\> An: [personal...@googlegroups.com](mailto:personal...@googlegroups.com)  
\> Betreff: [personal kdb+] Is there any way to create candlestick on ODD =  
TimeSpan from tick data by using xbar function.  
\>  
\>  
\> ear All KDB+ Gurus,  
\>  
\>  
\> I have tick Data and I know that I could convert it to minute bar =  
easily by this way:  
\>  
\>  
\> “select High: max Price, Low: min Price, Open: first Price, Close: =  
last Price by 1 xbar Time.minute from Trade where Symbol = `BAC”  
\>  
\>  
\> And the tickdata looks like this:  
\>  
\> Time Symbol Price  
\>  
\> ---------------------------------------------------  
\>  
\> 09:30:01.333 BAC 9.10  
\>  
\> …  
\>  
\>  
\> Now is my question, is there any possible to convert the tick data =  
into candlestick on some weird timespan? =46rom example, 5 seconds, 7 =  
seconds or 55 seconds. I know it sounds weird but just curious whether =  
here is any advance command or function I could use?  
\>  
\>  
\>  
\> Thanks in advance.  
\>  
\>  
\> Best  
\>  
\>  
\> Wenhao  
\>  
\>  
\> –  
\> You received this message because you are subscribed to the Google =  
Groups “Kdb+ Personal Developers” group.  
\> To view this discussion on the web visit =  
[https://groups.google.com/d/msg/personal-kdbplus/-/r9nhd2cWOQcJ](https://groups.google.com/d/msg/personal-kdbplus/-/r9nhd2cWOQcJ).  
\> To post to this group, send email to [personal...@googlegroups.com](mailto:personal...@googlegroups.com).  
\> To unsubscribe from this group, send email to =  
[personal-kdbpl...@googlegroups.com](mailto:personal-kdbpl...@googlegroups.com).  
\> For more options, visit this group at =  
[http://groups.google.com/group/personal-kdbplus?hl=en](http://groups.google.com/group/personal-kdbplus?hl=en).  
\>  
\>  
\> –  
\> You received this message because you are subscribed to the Google =  
Groups “Kdb+ Personal Developers” group.  
\> To view this discussion on the web visit =  
[https://groups.google.com/d/msg/personal-kdbplus/-/3UOlB17SVTIJ](https://groups.google.com/d/msg/personal-kdbplus/-/3UOlB17SVTIJ).  
\> To post to this group, send email to =  
[personal-kdbplus@googlegroups.com](mailto:personal-kdbplus@googlegroups.com).  
\> To unsubscribe from this group, send email to =  
[personal-kdbplus+unsubscribe@googlegroups.com](mailto:personal-kdbplus+unsubscribe@googlegroups.com).  
\> For more options, visit this group at =  
[http://groups.google.com/group/personal-kdbplus?hl=en](http://groups.google.com/group/personal-kdbplus?hl=en).

---

<div class="post-metadata">

**Author:** ![abcfoots1](https://avatars.discourse-cdn.com/v4/letter/a/96bed5/32.png) [@abcfoots1](https://forum.kx.com/u/abcfoots1)\
**Post date:** [December 14, 2012, 8:10pm UTC](https://forum.kx.com/t/is-there-any-way-to-create-candlestick-on-odd-timespan-from-tick/8042/5 "2012-12-14T20:10:00Z")

</div>

bin is useful if you want to aggregate over a non uniform gridr:`s#09:30:01.333 09:31:02.332 09:35:00.0 10:40:00.0select max[price],min[price]by Symbol,Time:r@r bin Time from tradeOn Dec 14, 3:10?am, Boh?k Andr?s <and...> wrote:&gt; If you liked 7 seconds, how about 7.123?:)&gt;&gt; select High: ?max Price, Low: min Price, Open: first Price, Close: last Price by 7123 xbar Time from Trade where Symbol = `BAC\>\> 2012.12.13. d?tummal, 18:27 id?pontban she wenhao ?rta:\>\>\>\> \> Thanks lot ?Kuentang,\>\> \> Yes, it is. I tried some ?ODD timespan on this like by 7 xbar Time.second from Trade where Symbol = `BAC and it rocks. Really interesting that I could have some 7 second or 77 second bar, lol&gt;&gt; &gt; Have a nice day~~~&gt;&gt; &gt; Wenhao&gt;&gt; &gt; On Thursday, December 13, 2012 12:23:35 PM UTC-5, kuentang wrote:&gt; &gt; Do you mean this?&gt;&gt; &gt; select High: ?max Price, Low: min Price, Open: first Price, Close: last Price by ?5 xbar Time.second from Trade where Symbol = `BAC\>\> \> Von: [personal...@googlegroups.com](mailto:personal...@googlegroups.com) [[mailto:personal...@googlegroups.com](mailto:personal...@googlegroups.com)] Im Auftrag von she wenhao\> \> Gesendet: Donnerstag, 13. Dezember 2012 17:44\> \> An: [personal...@googlegroups.com](mailto:personal...@googlegroups.com)\> \> Betreff: [personal kdb+] Is there any way to create candlestick on ODD TimeSpan from tick data by using xbar function.\>\> \> ear All KDB+ Gurus,\>\> \> I have tick Data and I know that ?I could convert it to minute bar easily by this way:\>\> \> “select High: ?max Price, Low: min Price, Open: first Price, Close: last Price by ?1 xbar Time.minute from Trade where Symbol = `BAC”\>\> \> And the tickdata looks like this:\>\> \> Time ? ? ? ? ? ? ? ?Symbol ? ? ? ?Price\>\> \> ---------------------------------------------------\>\> \> 09:30:01.333 ? ? ? BAC ? ? ? ? ? ?9.10\>\> \> …\>\> \> Now is my question, is ?there any possible to convert the tick data into candlestick on some weird timespan? From example, 5 seconds, 7 seconds or 55 seconds. I know it sounds ?weird but ?just curious whether here is any advance command or function I ?could use?\>\> \> Thanks in advance.\>\> \> Best\>\> \> Wenhao\>\> \> –\> \>

Submitted via Google Groups\</and…\>
