using System; using System.Collections.Generic; using TSLab.Script; using TSLab.Script.Handlers; using TSLab.Script.Optimization; using TSLab.Script.Helpers; namespace my_first_project.Properties { public class Ind1 : IBar2DoubleHandler, IContextUses { [HandlerParameter(true, "5", Min = "1", Max = "20", Step = "1")] public int Period { get; set; } public IList Execute(ISecurity source) { var HH = Context.GetData("Highest", new[] { Period.ToString() }, () => Series.Highest(source.HighPrices, Period)); var LL = Context.GetData("Lowest", new[] { Period.ToString() }, () => Series.Lowest(source.LowPrices, Period)); var C = source.ClosePrices; IList Ind = new List(C.Count); IList Ind1 = new List(C.Count); double per1 = 0; double per2 = 0; for (int i = 0; i < C.Count; i++) { var znach = 0.5 * ((((HH[i]+LL[i]) / 2) - LL[i]) / (HH[i]-LL[i]) - 0.5) + 0.5 * per1; znach = Math.Min(Math.Max(znach, -0.999), 0.999); var buf = Math.Log((znach + 1.0) / (1 - znach)) / 2.0 + per2 / 2.0; per1 = znach; per2 = buf; } double buf2 = 0; double buf1 = 0; double cur = 0; double fut = 0; double itog = 0; bool up = true; for (int i = C.Count - 2; i >=0; i--) { cur = buf[i]; fut = buf[i+1]; if ((cur < 0 && fut > 0) || cur < 0) up = false; if ((cur > 0 && fut < 0) || cur > 0) up = true; if (!up) { buf2 = cur; buf1 = 0; } else { buf1 = cur; buf2 = 0; } Ind.Add(buf1); Ind1.Add(buf2); } return Ind1; } public IContext Context { get; set; } } }