using System; using System.Collections.Generic; using System.Globalization; using System.Linq; using RusAlgo.Helper; using TSLab.Script; using TSLab.Script.Handlers; using TSLab.Script.Helpers; namespace RusAlgo.Handlers.Public.Adaptive { [HandlerCategory("RusAlgo")] [HandlerName("Adaptive StochK")] [InputInfo(0, "Инструмент")] [InputInfo(1, "Период")] public class aStochK : ITwoSourcesHandler, ISecurityInput0, IDoubleInput1, IDoubleReturns, IStreamHandler, IValuesHandlerWithNumber, IContextUses { public IContext Context { set; private get; } // потоковый public IList Execute(ISecurity sec, IList period) { if (CollectionHelper.LengthDiffer(sec.ClosePrices, period)) throw new Exception("Разное число элементов в списках. Возможно используется сжатие одного из входов."); var values = new double[sec.Bars.Count]; for (var i = 0; i < sec.Bars.Count; i++) { var currPeriod = Math.Max(Convert.ToInt32(period[i]), 1); var key = TradeHelper.MakeUniqueScriptKey("AdaptiveStochKRusAlgo", currPeriod, sec.MakeSecurityKey()); var value = Context.GetData(key, new string[0], () => { var hnd = new StochK() {Context = Context, Period = currPeriod}; return hnd.Execute(sec); }); values[i] = value[i]; } return values; } // последовательный public double Execute(ISecurity sec, double period, int barNum) { var currPeriod = Math.Max(Convert.ToInt32(period), 1); var key = TradeHelper.MakeUniqueScriptKey("AdaptiveStochKRusAlgo", currPeriod, sec.MakeSecurityKey()); var values = Context.GetData(key, new string[0], () => { var hnd = new StochK() { Context = Context, Period = currPeriod }; return hnd.Execute(sec); }); return values[barNum]; } } }