有点复杂,但还是基本能够搞定!不过那个解释器也算牛B了
原公式:
A:(H+L+C)/3 NODRAW;
DIFF:A-MA(A,N1) NODRAW;
MD:MA(ABS(DIFF),N1) NODRAW;
CCI:DIFF/MD* 66.7;
MCCI:MA(CCI,N2);
写成C#,一开始想了很久,后来用个笨办法,循环了
List<float[]> re = new List<float[]>(); for (int i = 0; i < lsd.Count; i++) { float [] fp=new float[]{0,0,0,0,0}; re.Add(fp); StockDayData sd=lsd[i]; fp[0] = (sd.High + sd.Low + sd.Close) / 3; //A if (i < n1-1) continue ; fp[1] = fp[0] - MA(re.Select(it => it[0]).ToList() , n1); //DIFF if (i < n1-1 + n1-1) continue; fp[2]=MA(re.Select(it=>Math.Abs (it[1]) ).ToList(),n1); //MD fp[3] = fp[1] / fp[2] * 66.7f; //CCI if (i < n1-1 + n1-1 + n2-1) continue; fp[4]=MA(re.Select (it=>it[3]).ToList (),n2); //MCCI Console.WriteLine("CCI:{0} MCCI:{1}",fp[3],fp[4]);