Esempio n. 1
0
        protected override decimal ComputeNextValue(IReadOnlyWindow <IndicatorDataPoint> window, IndicatorDataPoint input)
        {
            var stop = 0;
            var src  = input.Value;

            if (src == Src.FirstOrDefault())
            {
                return(xEma);
            }
            Src.Add(src);

            if (Src.IsReady)
            {
                //PFE = sqrt(pow(close - close[Length], 2) + 100)
                var s1    = Src.Skip(1).FirstOrDefault();
                var sL    = Src.LastOrDefault();
                var perfL = src - sL;
                PFE = Math.Sqrt((double)(perfL * perfL) + 100);

                //C2C = sum(sqrt(pow((close - close[1]), 2) + 1), Length)
                var perf1 = src - s1;
                var tosum = Math.Sqrt((double)(perf1 * perf1) + 1);
                C2C.Add(tosum);

                //xFracEff = iff(close - close[Length] > 0,  round((PFE / C2C) * 100) , round(-(PFE / C2C) * 100))
                double c2csum   = 0;
                double xFracEff = 0;
                if (C2C.IsReady)
                {
                    c2csum   = C2C.Sum();
                    xFracEff = (perfL > 0) ? Math.Round(PFE / c2csum * 100)  : Math.Round(-PFE / c2csum * 100);
                    xEma.Update(input.Time, (decimal)xFracEff);
                }
                if (xEma.IsReady)
                {
                    return(xEma);           //Math.Min(Math.Max(xEma, -100), 100);
                }
            }
            return(0);
        }