/// <summary> /// 计算涨跌速度,计算好的速度设置在ChangeSpeed属性上。 /// 对下跌幅度计算方法进行了更改: 假设s为开始值,e为结束值,原本算法为 (e-s)/s*100%,修改后算法为 (s-e)/e*100%。 /// 目的: 修正原本算法下涨幅、跌幅的不公平性,例如经历涨幅100%再经历跌幅50%,已经回到原价,这样相同的涨跌幅就不具备比较性 /// </summary> /// <param name="k">K线数据</param> public static void CalChangeSpeed(KTrend trend) { if (trend.TxDays <= 1 || trend.StartValue==0) return; int dr = trend.StartValue < trend.EndValue ? 1 : -1; decimal lo = trend.StartValue < trend.EndValue ? trend.StartValue : trend.EndValue; decimal hi = trend.EndValue > trend.StartValue ? trend.EndValue : trend.StartValue; trend.ChangeSpeed = Convert.ToDecimal(Math.Pow(Convert.ToDouble(hi / lo), Convert.ToDouble(1.0 / (trend.TxDays - 1))) - 1) * 100 * dr; }
public KTrendMALong(KTrend trend) { this.Id = 0; this.StockId = trend.StockId; this.StartDate = trend.StartDate; this.StartValue = trend.StartValue; this.EndDate = trend.EndDate; this.EndValue = trend.EndValue; this.TxDays = trend.TxDays; this.ChangeSpeed = trend.ChangeSpeed; }
/// <summary> /// 计算区间最大值、最小值、振幅,计算好的结果直接设置在trend上 /// </summary> /// <param name="trend">Trend.</param> /// <param name="lk">Lk.</param> /// <param name="start">Start.</param> /// <param name="end">End.</param> public static void CalHighLowValue(KTrend trend, MAType type, IList<KJapaneseData> lk, int start, int end) { decimal hi = trend.StartValue, lo = trend.StartValue; for (int i = start + 1; i <= end; i++){ decimal v = 0; switch (type){ case MAType.MAShort: case MAType.MALong: v = lk[i].ClosePrice; break; case MAType.VMAShort: case MAType.VMALong: v = lk[i].Volume; break; } if (lk[i].ClosePrice > hi) hi = lk[i].ClosePrice; if (lk[i].ClosePrice < lo) lo = lk[i].ClosePrice; } trend.HighValue = hi; trend.LowValue = lo; trend.Amplitude = CalNetChange(lo, hi); }