I’m trying to get the DI+ and DI- from High Low and Close as described here:
But I don’t know how to calculate differently the first rows than the remaining rows.
Please can any of the experts help me?
Best regards
Francisco
I’m trying to get the DI+ and DI- from High Low and Close as described here:
But I don’t know how to calculate differently the first rows than the remaining rows.
Please can any of the experts help me?
Best regards
Francisco
I have a table CandlesList with market data:
| instrument | granularity | time | openMid | highMid | lowMid | closeMid |
| EUR_USD | D | 2015.08.13D21:00:00.000000000 | 1.114905 | 1.11888 | 1.110965 | 1.109775 |
| EUR_USD | D | 2015.08.16D21:00:00.000000000 | 1.11206 | 1.1125 | 1.10765 | 1.105865 |
| EUR_USD | D | 2015.08.17D21:00:00.000000000 | 1.10782 | 1.10941 | 1.10256 | 1.101735 |
| EUR_USD | D | 2015.08.18D21:00:00.000000000 | 1.10241 | 1.113435 | 1.112065 | 1.101775 |
| EUR_USD | D | 2015.08.19D21:00:00.000000000 | 1.11209 | 1.124495 | 1.124105 | 1.11073 |
| EUR_USD | D | 2015.08.20D21:00:00.000000000 | 1.12396 | 1.138895 | 1.138715 | 1.12294 |
| EUR_USD | D | 2015.08.23D21:00:00.000000000 | 1.137755 | 1.17141 | 1.161975 | 1.13696 |
| EUR_USD | D | 2015.08.24D21:00:00.000000000 | 1.16216 | 1.162185 | 1.151625 | 1.13969 |
| EUR_USD | D | 2015.08.25D21:00:00.000000000 | 1.152115 | 1.156145 | 1.13147 | 1.129195 |
| EUR_USD | D | 2015.08.26D21:00:00.000000000 | 1.13122 | 1.13646 | 1.124615 | 1.120315 |
| EUR_USD | D | 2015.08.27D21:00:00.000000000 | 1.12441 | 1.131 | 1.124215 | 1.12322 |
| GBP_USD | D | 2013.09.23D21:00:00.000000000 | 1.60424 | 1.604485 | 1.600405 | 1.595555 |
| GBP_USD | D | 2013.09.24D21:00:00.000000000 | 1.60036 | 1.60881 | 1.608055 | 1.59797 |
| GBP_USD | D | 2013.09.25D21:00:00.000000000 | 1.60808 | 1.6096 | 1.604125 | 1.59996 |
| GBP_USD | D | 2013.09.26D21:00:00.000000000 | 1.60413 | 1.614685 | 1.61392 | 1.603015 |
| GBP_USD | D | 2013.09.29D21:00:00.000000000 | 1.61435 | 1.620265 | 1.618555 | 1.61284 |
| GBP_USD | D | 2013.09.30D21:00:00.000000000 | 1.618545 | 1.626045 | 1.61953 | 1.618235 |
| GBP_USD | D | 2013.10.01D21:00:00.000000000 | 1.61953 | 1.625105 | 1.622305 | 1.616275 |
| GBP_USD | D | 2013.10.02D21:00:00.000000000 | 1.622295 | 1.624125 | 1.61558 | 1.61548 |
| GBP_USD | D | 2013.10.03D21:00:00.000000000 | 1.61559 | 1.617795 | 1.600985 | 1.600665 |
| GBP_USD | D | 2013.10.06D21:00:00.000000000 | 1.60236 | 1.610015 | 1.609665 | 1.601625 |
| GBP_USD | D | 2013.10.07D21:00:00.000000000 | 1.60967 | 1.612435 | 1.60834 | 1.602015 |
| GBP_USD | D | 2013.10.08D21:00:00.000000000 | 1.60832 | 1.61219 | 1.595395 | 1.59163 |
| GBP_USD | D | 2013.10.09D21:00:00.000000000 | 1.59539 | 1.5979 | 1.596775 | 1.59139 |
To find the Directional indicators first I add the columns UpMove, DownMove, DM1plus, DM1minus and TR as defined in the referenced document:
CandlesList:update UpMove:highMid-prev(highMid) by instrument from CandlesList
CandlesList:update DownMove:lowMid-prev(lowMid) by instrument from CandlesList
CandlesList:update DM1plus:UpMove by instrument from CandlesList where UpMove>DownMove,UpMove>0
CandlesList:update DM1minus:DownMove by instrument from CandlesList where DownMove>UpMove,DownMove>0
CandlesList:update TR:(highMid-lowMid)|abs(highMid-prev(closeMid))|abs(lowMid-prev(closeMid)) by instrument from CandlesList
Now
TRn:TR+(prev TRn)-(prev TRn)%n by instrument from CandlesList
but for the first n rows
TRn: n msum TR by instrument from CandlesList
Now
DMnplus:DM1plus+(prev DMnplus)-(prev DMnplus)%n by instrument from CandlesList
but for the first n rows
DMnplus:n msum DM1plus by instrument from CandlesList
Now
DM8minus:DMnminus+(prev DMnminus)-(prev DMnminus)%n by instrument from CandlesList
but for the first n rows
DMnminus:n msum DM1minus by instrument from CandlesList
How to write the functions to achieve that?
Cheers
Francisco
I think what you want is something along the lines of: (I’m looking at the DM1 and DM14 numbers in your original link)
tab:(DM1:.4 .47 .31 .0 .0 .0 .45 .5 .22 .12 .36 .26 .0 .0 .0 .7 .0 .29 .0 .0 .34 .0 .0 .0 .0 .0 .67 .04 .0)
update DM14:{#[y-1;0n],s,(s:sum[y#x])(1-1%y)\y _x}[DM1;14] from tab
Note that this is a “shorthand” version of the commonly used exponential moving average solution
{z+x*y}[3.09;1-1%14;0.0 0.7 0.0 0.29 0.0 0.0 0.34]
2.8692857 3.3643367 3.124027 3.1908822 2.962962 2.7513219 2.8947989f
Terry
Are you trying to calculate the stuff in this spreadsheet?
Thanks a lot… I’ll try to understand the function
El jueves, 3 de septiembre de 2015, 17:07:55 (UTC+2), TerryLynch escribió:
I think what you want is something along the lines of: (I’m looking at the DM1 and DM14 numbers in your original link)
tab:(DM1:.4 .47 .31 .0 .0 .0 .45 .5 .22 .12 .36 .26 .0 .0 .0 .7 .0 .29 .0 .0 .34 .0 .0 .0 .0 .0 .67 .04 .0)
update DM14:{#[y-1;0n],s,(s:sum[y#x])(1-1%y)\y _x}[DM1;14] from tab
Note that this is a “shorthand” version of the commonly used exponential moving average solution{z+x*y}[3.09;1-1%14;0.0 0.7 0.0 0.29 0.0 0.0 0.34]
2.8692857 3.3643367 3.124027 3.1908822 2.962962 2.7513219 2.8947989f
Terry
Yes
El viernes, 4 de septiembre de 2015, 1:34:48 (UTC+2), Yan Yan escribió:
Are you trying to calculate the stuff in this spreadsheet?
Is the backslash used as the iterate operator? How does “1(0.5)\ til 5” work? It works when a float is within the brackets, but not when a long is within the brackets.
http://code.kx.com/wiki/Reference/BackSlash#iterate
update DM14:{#[y-1;0n],s,(s:sum[y#x])(1-1%y)</font>y _x}[DM1;14] from tab
1(0.5)\ til 5
0.5 1.25 2.625 4.3125 6.15625
deltas deltas 1(0.5)\ til 5
0.5 0.25 0.625 0.3125 0.15625
deltas deltas 1(2 )\ til 5
ERROR: 'type
deltas deltas 1(2.0)\ til 5
2 1 4 8 16f
Yes, it is an (optimized?) shorthand for a particular type of iterate, as mentioned in my previous email.
It was introduced in one of the 3.x versions.
Terry