Hello:
As we'll need using the Open value from Weekly table in Daily table we have to use a different name to avoid problems, so we'll use W_Open.
[font=Courier New]EU_W1:update W_Open:Open from EU_W1
EU_W1:delete Open from EU_W1[/font]
The table with the new column name:
Cheers
Learning Kdb+/q
Moderator: moderators
Please add www.kreslik.com to your ad blocker white list.
Thank you for your support.
Thank you for your support.
Now we'll add the open data from the weekly table into the daily table using this command:
[font=Courier New]EU_D1:aj[`datetime;EU_D1;EU_W1][/font]
This is the daily table with weekly data:
Cheers
Thanks to Charles Skelton and many others in Kdb+ Personal Developers Forum.
[font=Courier New]EU_D1:aj[`datetime;EU_D1;EU_W1][/font]
This is the daily table with weekly data:
Cheers
Thanks to Charles Skelton and many others in Kdb+ Personal Developers Forum.
Last edited by frang0nve on Tue Jun 19, 2012 4:37 am, edited 3 times in total.
Hello,
We'll add a column to the Daily Data Table containing the weekday (0:Sat, 1:Sun,..., 6:Fri) with this command:
[font=Courier New]EU_D1: update Weekday:datetime mod 7 from EU_D1[/font]
Now we need to find the entry points for green rats (buyers):
The first tick (and only the first tick) every day presenting these conditions:
NewRat=1 (Daily Data Table)
askprice>=EntryLevel (Tick Data Table, Daily Data Table)
EntryLevel > Weekly Open (Daily Data Table)
Weekday: Monday, Tuesday, Wednesday, Thursday, Friday (broker allowing trading 24/7)
We'll add a column to the daily table to find out when a buy order should be issued:
[font=Courier New]EU_D1: update NewGreenRat:1 from EU_D1 where NewRat=1,EntryLevel>W_Open,Weekday within (2;6)[/font]
Then Red Rats need these conditions to short:
The first tick (and only the first tick) every day presenting these conditions:
NewRat=-1 (Daily Data Table)
bidprice<=EntryLevel (Tick Data Table, Daily Data Table)
EntryLevel < Weekly Open (Daily Data Table)
Weekday: Monday, Tuesday, Wednesday, Thursday, Friday (broker allowing trading 24/7)
We'll add a column to the daily table to find out when a sell order should be issued:
[font=Courier New]EU_D1: update NewRedRat:1 from EU_D1 where NewRat=-1,EntryLevel<W_Open,Weekday within (2;6)[/font]
The resulting daily table:
Cheers
Thanks to Rory O'Rorke, effbiae, Aaron Davies and many others from Kdb+ Personal Developers forum.
We'll add a column to the Daily Data Table containing the weekday (0:Sat, 1:Sun,..., 6:Fri) with this command:
[font=Courier New]EU_D1: update Weekday:datetime mod 7 from EU_D1[/font]
Now we need to find the entry points for green rats (buyers):
The first tick (and only the first tick) every day presenting these conditions:
NewRat=1 (Daily Data Table)
askprice>=EntryLevel (Tick Data Table, Daily Data Table)
EntryLevel > Weekly Open (Daily Data Table)
Weekday: Monday, Tuesday, Wednesday, Thursday, Friday (broker allowing trading 24/7)
We'll add a column to the daily table to find out when a buy order should be issued:
[font=Courier New]EU_D1: update NewGreenRat:1 from EU_D1 where NewRat=1,EntryLevel>W_Open,Weekday within (2;6)[/font]
Then Red Rats need these conditions to short:
The first tick (and only the first tick) every day presenting these conditions:
NewRat=-1 (Daily Data Table)
bidprice<=EntryLevel (Tick Data Table, Daily Data Table)
EntryLevel < Weekly Open (Daily Data Table)
Weekday: Monday, Tuesday, Wednesday, Thursday, Friday (broker allowing trading 24/7)
We'll add a column to the daily table to find out when a sell order should be issued:
[font=Courier New]EU_D1: update NewRedRat:1 from EU_D1 where NewRat=-1,EntryLevel<W_Open,Weekday within (2;6)[/font]
The resulting daily table:
Cheers
Thanks to Rory O'Rorke, effbiae, Aaron Davies and many others from Kdb+ Personal Developers forum.
Last edited by frang0nve on Fri Jul 20, 2012 2:12 am, edited 2 times in total.
Now we'll add NewGreenRat, NewRedRat, EntryLevel, SLLevel columns to the tick table. To do so we build and auxiliary table (EU_D1_S) only with the required columns:
[font=Courier New]EU_D1_S: select datetime,NewGreenRat,NewRedRat,EntryLevel,SLLevel from EU_D1[/font]
This is the auxiliary table:
Now we'll add those columns to the tick table:
[font=Courier New]EU:aj[`datetime;EU;EU_D1_S][/font]
Resulting this table:
[font=Courier New]EU_D1_S: select datetime,NewGreenRat,NewRedRat,EntryLevel,SLLevel from EU_D1[/font]
This is the auxiliary table:
Now we'll add those columns to the tick table:
[font=Courier New]EU:aj[`datetime;EU;EU_D1_S][/font]
Resulting this table:
Hello,
This step could be done earlier, but I forgot...
We'll add a column in the tickdata table with the date:
[font=Courier New]EU:update Date:datetime.date from EU[/font]
And in the daily table using date format instead of datetime format:
[font=Courier New]EU_D1:update Date:datetime.date from EU_D1[/font]
Now we need to find the ticks when trades are triggered:
For green rats The first tick in a day complying:
NewGreenRat=1
askprice>=EntryLevel
We'll add the column GreenEntry to show the buying ticks
[font=Courier New]EU:update GreenEntry:1 from (update f:(first i where askprice>=EntryLevel) by Date from EU lj `Date xkey select Date,NewGreenRat,EntryLevel from EU_D1) where NewGreenRat=1,f=i[/font]
This is a sparsely populated column in a tick data table, so we can select only the rows holding entry conditions:
[font=Courier New]EU_Green:select from EU where GreenEntry=1[/font]
For red rats The first tick in a day complying:
NewRedRat=1
bidprice<=EntryLevel
We'll add the column RedEntry to show the selling ticks
[font=Courier New]EU:update RedEntry:1 from (update g:(first i where bidprice<=EntryLevel) by Date from EU lj `Date xkey select Date,NewRedRat,EntryLevel from EU_D1) where NewRedRat=1,g=i[/font]
This is also a sparsely populated column in a tick data table, so we can select only the rows holding entry conditions:
[font=Courier New]EU_Red:select from EU where RedEntry=1[/font]
Cheers
Thanks to Max_18 and many others in Kdb+ Personal Developers forum.
This step could be done earlier, but I forgot...
We'll add a column in the tickdata table with the date:
[font=Courier New]EU:update Date:datetime.date from EU[/font]
And in the daily table using date format instead of datetime format:
[font=Courier New]EU_D1:update Date:datetime.date from EU_D1[/font]
Now we need to find the ticks when trades are triggered:
For green rats The first tick in a day complying:
NewGreenRat=1
askprice>=EntryLevel
We'll add the column GreenEntry to show the buying ticks
[font=Courier New]EU:update GreenEntry:1 from (update f:(first i where askprice>=EntryLevel) by Date from EU lj `Date xkey select Date,NewGreenRat,EntryLevel from EU_D1) where NewGreenRat=1,f=i[/font]
This is a sparsely populated column in a tick data table, so we can select only the rows holding entry conditions:
[font=Courier New]EU_Green:select from EU where GreenEntry=1[/font]
For red rats The first tick in a day complying:
NewRedRat=1
bidprice<=EntryLevel
We'll add the column RedEntry to show the selling ticks
[font=Courier New]EU:update RedEntry:1 from (update g:(first i where bidprice<=EntryLevel) by Date from EU lj `Date xkey select Date,NewRedRat,EntryLevel from EU_D1) where NewRedRat=1,g=i[/font]
This is also a sparsely populated column in a tick data table, so we can select only the rows holding entry conditions:
[font=Courier New]EU_Red:select from EU where RedEntry=1[/font]
Cheers
Thanks to Max_18 and many others in Kdb+ Personal Developers forum.
Last edited by frang0nve on Wed Jun 20, 2012 3:38 am, edited 2 times in total.
Please add www.kreslik.com to your ad blocker white list.
Thank you for your support.
Thank you for your support.
Please add www.kreslik.com to your ad blocker white list.
Thank you for your support.
Thank you for your support.