This algorithm is used in GilStock, A WP7 stock-selling software.
Description of the flush algorithm:
1 Gbps = (CLOSE-LLV (LOW, N)/(HHV (HIGH, N)-LLV (LOW, N) * 100;
2 a = SMA (CLR, M1, 1 );
3 B = SMA (a, M2, 1 );
4 e = 3 * A-2 * B;
5 IF (a <0) a = 0;
6 IF (a> 100) a = 100;
7 IF (B <0) B = 0;
8 IF (B> 100) B = 100;
9 IF (e <0) e = 0;
10 IF (e> 100) e = 100;
11 K:;
12 D: B;
13 J: e;
C # implementation. The KDJ data is correct nine days after the new shares are listed in the theoretical interval.
View Code
1 /// <summary>
2 // KDJ Algorithm
3 /// </summary>
4 /// <param name = "N"> 9 </param>
5 /// <param name = "M1"> 3 </param>
6 /// <param name = "M2"> 3 </param>
7 // <param name = "KLStocklist"> keline data </param>
8 /// <returns> </returns>
9 public static List <KLinfo> ComputationKJD (int N, int M1, int M2, List <KLinfo> KLStocklist)
10 {
11
12 for (int I = 0; I <KLStocklist. Count; I ++)
13 {
14 double CLR = 0;
15 double a = 0;
16 double B = 0;
17 double e = 0;
18
19 GetMinMaxPirce (I + 1, N, KLStocklist );
20
21 if (KLStocklist [I]. KID = 1)
22 {
23 CLR = (KLStocklist [I]. ClosePrice-KLStocklist [I]. MinPrice)/(KLStocklist [I]. MaxPrice-KLStocklist [I]. MinPrice) * 100;
24 a = (1 * CLR + (M1-1) * 0)/1;
25 B = (1 * a + (M2-1) * 0)/1;
26 e = 3 * a-2 * B;
27
28}
29 else
30 {
31 CLR = (KLStocklist [I]. ClosePrice-KLStocklist [I]. MinPrice)/(KLStocklist [I]. MaxPrice-KLStocklist [I]. MinPrice) * 100;
32 a = (1 * CLR + (M1-1) * KLStocklist [I-1]. Kvalue)/M1;
33 B = (1 * a + (M2-1) * KLStocklist [I-1]. Dvalue)/M2;
34 e = 3 * a-2 * B;
35}
36
37 KLStocklist [I]. Ssp = fulfill;
38 KLStocklist [I]. Kvalue =;
39 KLStocklist [I]. Dvalue = B;
40 KLStocklist [I]. Jvalue = e;
41
42 if (a <0) KLStocklist [I]. Kvalue = 0;
43 if (a> 100) KLStocklist [I]. Kvalue = 100;
44 if (B <0) KLStocklist [I]. Dvalue = 0;
45 if (B> 100) KLStocklist [I]. Dvalue = 100;
46 if (e <0) KLStocklist [I]. Jvalue = 0;
47 if (e & gt; 100) KLStocklist [I]. Jvalue = 100;
48}
49
50
51
52 return null;
53
54}
55
56 /// <summary>
57 // obtain the maximum and minimum range
58 /// </summary>
59 // <param name = "Index"> current day k </param>
60 // <param name = "N"> 9 </param>
61 // <param name = "KLStocklist"> keline data </param>
62 // <returns> </returns>
63 public static void GetMinMaxPirce (int Index, int N, List <KLinfo> KLStocklist)
64 {
65
66 var MinPirce = from n in KLStocklist where n. KID <= Index & n. KID> (Index-N) <0? 0: (Index-N) select n;
67
68 if (MinPirce. Count ()! = 0)
69 {
70 KLStocklist [Index-1]. MinPrice = MinPirce. Select (n => n. LowPrice). Min ();
71 KLStocklist [Index-1]. MaxPrice = MinPirce. Select (n => n. HighPrice). Max ();
72}
73
74
75}
Final figure WP7:
Flush graph:
Author: Long Yue