using System; using System.Collections.Generic; using TSLab.Script; using TSLab.Script.Handlers; using TSLab.DataSource; using TSLab.Script.Helpers; namespace HeikenAshi_ { public class HeikenAshi : IBar2BarHandler { // основная функция пересчёта public ISecurity Execute(ISecurity source) { var Bars = new List(source.Bars.Count); var C = source.ClosePrices; var H = source.HighPrices; var L = source.LowPrices; var O = source.OpenPrices; IList HA = new List(Bars.Count); IList haCn = new List(C.Count); IList haHn = new List(C.Count); IList haLn = new List(C.Count); IList haOn = new List(C.Count); double haOpen, haHigh, haLow, haClose; for (int i = 0; i < C.Count; i++) { if (i < 2) { haOpen = O[i]; haClose = C[i]; haLow = L[i]; haHigh = H[i]; } else { haClose = (C[i] + O[i] + L[i] + H[i]) / 4; // вот тут неверно!!! нужно использовать haOpen и haClose !!! // haOpen = ( O[i - 1] + C[i - 1] ) / 2; // должно быть как-то так haOpen = (haOn[i - 1] + haCn[i - 1]) / 2; haLow = Math.Min(L[i], Math.Min(haOpen, haClose)); haHigh = Math.Max(H[i], Math.Max(haOpen, haClose)); } haOn.Add(haOpen); haCn.Add(haClose); haLn.Add(haLow); haHn.Add(haHigh); } int j = 0; foreach (var bar in source.Bars) { var hav = new Bar(bar.Color, bar.Date, haOn[j], haHn[j], haLn[j], haCn[j], bar.Volume); HA.Add(hav); j++; } return source.CloneAndReplaceBars(HA); } public IContext Context { get; set; } } }