Ejemplo n.º 1
0
    public void Removed()
    {
        int            windowPeriods = 11;
        int            offsetPeriods = 9;
        PivotPointType pointType     = PivotPointType.Standard;

        List <RollingPivotsResult> results =
            quotes.GetRollingPivots(windowPeriods, offsetPeriods, pointType)
            .RemoveWarmupPeriods()
            .ToList();

        // assertions
        Assert.AreEqual(502 - (windowPeriods + offsetPeriods), results.Count);

        RollingPivotsResult last = results.LastOrDefault();

        Assert.AreEqual(260.0267m, Math.Round((decimal)last.PP, 4));
        Assert.AreEqual(246.4633m, Math.Round((decimal)last.S1, 4));
        Assert.AreEqual(238.7767m, Math.Round((decimal)last.S2, 4));
        Assert.AreEqual(225.2133m, Math.Round((decimal)last.S3, 4));
        Assert.AreEqual(null, last.S4);
        Assert.AreEqual(267.7133m, Math.Round((decimal)last.R1, 4));
        Assert.AreEqual(281.2767m, Math.Round((decimal)last.R2, 4));
        Assert.AreEqual(288.9633m, Math.Round((decimal)last.R3, 4));
        Assert.AreEqual(null, last.R4);
    }
Ejemplo n.º 2
0
        public void PivotPointPerType(PivotPointType pointType)
        {
            var pointsHighLow = new PivotPointsHighLow(10, 20);

            for (var i = 0; i < pointsHighLow.WarmUpPeriod; i++)
            {
                Assert.IsFalse(pointsHighLow.IsReady);

                var low  = 1;
                var high = 1;
                if (i == 10)
                {
                    if (pointType == PivotPointType.Low || pointType == PivotPointType.Both)
                    {
                        low = 0;
                    }
                    if (pointType == PivotPointType.High || pointType == PivotPointType.Both)
                    {
                        high = 2;
                    }
                }

                var bar = new TradeBar(DateTime.UtcNow.AddSeconds(i), Symbols.AAPL, i, high, low, i, i);
                pointsHighLow.Update(bar);
            }

            Assert.IsTrue(pointsHighLow.IsReady);

            var bothPivotPoint = pointsHighLow.GetAllPivotPointsArray();
            var lowPivotPoint  = pointsHighLow.GetLowPivotPointsArray();
            var highPivotPoint = pointsHighLow.GetHighPivotPointsArray();

            if (pointType == PivotPointType.None)
            {
                Assert.AreEqual(0, bothPivotPoint.Length);
            }
            if (pointType == PivotPointType.Both)
            {
                Assert.AreEqual(2, bothPivotPoint.Length);
                Assert.AreEqual(1, lowPivotPoint.Length);
                Assert.AreEqual(1, highPivotPoint.Length);
                Assert.IsTrue(lowPivotPoint.Any(point => point.Value == 0));
                Assert.IsTrue(highPivotPoint.Any(point => point.Value == 2));
            }
            if (pointType == PivotPointType.High)
            {
                Assert.AreEqual(1, bothPivotPoint.Length);
                Assert.AreEqual(0, lowPivotPoint.Length);
                Assert.AreEqual(1, highPivotPoint.Length);
                Assert.IsTrue(highPivotPoint.Any(point => point.Value == 2));
            }
            if (pointType == PivotPointType.Low)
            {
                Assert.AreEqual(1, bothPivotPoint.Length);
                Assert.AreEqual(1, lowPivotPoint.Length);
                Assert.AreEqual(0, highPivotPoint.Length);
                Assert.IsTrue(lowPivotPoint.Any(point => point.Value == 0));
            }
        }
Ejemplo n.º 3
0
 internal static PivotPointsResult GetPivotPoint(
     PivotPointType type, decimal open, decimal high, decimal low, decimal close)
 {
     return(type switch
     {
         PivotPointType.Standard => GetPivotPointStandard(high, low, close),
         PivotPointType.Camarilla => GetPivotPointCamarilla(high, low, close),
         PivotPointType.Demark => GetPivotPointDemark(open, high, low, close),
         PivotPointType.Fibonacci => GetPivotPointFibonacci(high, low, close),
         PivotPointType.Woodie => GetPivotPointWoodie(open, high, low),
         _ => null
     });
Ejemplo n.º 4
0
 // pivot type lookup
 internal static TPivotPoint GetPivotPoint <TPivotPoint>(
     PivotPointType pointType, decimal open, decimal high, decimal low, decimal close)
     where TPivotPoint : IPivotPoint, new()
 {
     return(pointType switch
     {
         PivotPointType.Standard => GetPivotPointStandard <TPivotPoint>(high, low, close),
         PivotPointType.Camarilla => GetPivotPointCamarilla <TPivotPoint>(high, low, close),
         PivotPointType.Demark => GetPivotPointDemark <TPivotPoint>(open, high, low, close),
         PivotPointType.Fibonacci => GetPivotPointFibonacci <TPivotPoint>(high, low, close),
         PivotPointType.Woodie => GetPivotPointWoodie <TPivotPoint>(open, high, low),
         _ => default
     });
Ejemplo n.º 5
0
    public void Removed()
    {
        PeriodSize     periodSize = PeriodSize.Month;
        PivotPointType pointType  = PivotPointType.Standard;

        List <PivotPointsResult> results = quotes.GetPivotPoints(periodSize, pointType)
                                           .RemoveWarmupPeriods()
                                           .ToList();

        // assertions
        Assert.AreEqual(482, results.Count);

        PivotPointsResult last = results.LastOrDefault();

        Assert.AreEqual(266.6767m, Math.Round((decimal)last.PP, 4));
        Assert.AreEqual(258.9633m, Math.Round((decimal)last.S1, 4));
        Assert.AreEqual(248.9667m, Math.Round((decimal)last.S2, 4));
        Assert.AreEqual(241.2533m, Math.Round((decimal)last.S3, 4));
        Assert.AreEqual(null, last.S4);
        Assert.AreEqual(276.6733m, Math.Round((decimal)last.R1, 4));
        Assert.AreEqual(284.3867m, Math.Round((decimal)last.R2, 4));
        Assert.AreEqual(294.3833m, Math.Round((decimal)last.R3, 4));
        Assert.AreEqual(null, last.R4);
    }
Ejemplo n.º 6
0
        // PIVOT POINTS
        /// <include file='./info.xml' path='indicator/*' />
        ///
        public static IEnumerable <PivotPointsResult> GetPivotPoints <TQuote>(
            IEnumerable <TQuote> history,
            PeriodSize windowSize,
            PivotPointType pointType = PivotPointType.Standard)
            where TQuote : IQuote
        {
            // sort history
            List <TQuote> historyList = history.Sort();

            // check parameter arguments
            ValidatePivotPoints(history, windowSize);

            // initialize
            List <PivotPointsResult> results     = new(historyList.Count);
            PivotPointsResult        windowPoint = new();

            TQuote h0       = historyList[0];
            int    windowId = GetWindowNumber(h0.Date, windowSize);
            int    windowEval;
            bool   firstWindow = true;

            decimal windowHigh  = h0.High;
            decimal windowLow   = h0.Low;
            decimal windowOpen  = h0.Open;
            decimal windowClose = h0.Close;

            // roll through history
            for (int i = 0; i < historyList.Count; i++)
            {
                TQuote h = historyList[i];

                PivotPointsResult r = new()
                {
                    Date = h.Date
                };

                // new window evaluation
                windowEval = GetWindowNumber(h.Date, windowSize);

                if (windowEval != windowId)
                {
                    windowId    = windowEval;
                    firstWindow = false;

                    // set new levels
                    if (pointType == PivotPointType.Woodie)
                    {
                        windowOpen = h.Open;
                    }

                    windowPoint = GetPivotPoint(pointType, windowOpen, windowHigh, windowLow, windowClose);

                    // reset window min/max thresholds
                    windowOpen = h.Open;
                    windowHigh = h.High;
                    windowLow  = h.Low;
                }

                // add levels
                if (!firstWindow)
                {
                    // pivot point
                    r.PP = windowPoint.PP;

                    // support
                    r.S1 = windowPoint.S1;
                    r.S2 = windowPoint.S2;
                    r.S3 = windowPoint.S3;
                    r.S4 = windowPoint.S4;

                    // resistance
                    r.R1 = windowPoint.R1;
                    r.R2 = windowPoint.R2;
                    r.R3 = windowPoint.R3;
                    r.R4 = windowPoint.R4;
                }

                results.Add(r);

                // capture window threholds (for next iteration)
                windowHigh  = (h.High > windowHigh) ? h.High : windowHigh;
                windowLow   = (h.Low < windowLow) ? h.Low : windowLow;
                windowClose = h.Close;
            }

            return(results);
        }
        public void Camarilla()
        {
            PeriodSize     periodSize = PeriodSize.Week;
            PivotPointType pointType  = PivotPointType.Camarilla;

            IEnumerable <Quote>      h       = HistoryTestData.Get(38);
            List <PivotPointsResult> results = Indicator.GetPivotPoints(h, periodSize, pointType)
                                               .ToList();

            // assertions

            // proper quantities
            // should always be the same number of results as there is history
            Assert.AreEqual(38, results.Count);
            Assert.AreEqual(33, results.Where(x => x.PP != null).Count());

            // sample values
            PivotPointsResult r2 = results[4];

            Assert.AreEqual(null, r2.R4);
            Assert.AreEqual(null, r2.R3);
            Assert.AreEqual(null, r2.PP);
            Assert.AreEqual(null, r2.S1);
            Assert.AreEqual(null, r2.S2);
            Assert.AreEqual(null, r2.R1);
            Assert.AreEqual(null, r2.R2);
            Assert.AreEqual(null, r2.S3);
            Assert.AreEqual(null, r2.S4);

            PivotPointsResult r3 = results[5];

            Assert.AreEqual(271.0200m, Math.Round((decimal)r3.PP, 4));
            Assert.AreEqual(270.13725m, Math.Round((decimal)r3.S1, 5));
            Assert.AreEqual(269.2545m, Math.Round((decimal)r3.S2, 4));
            Assert.AreEqual(268.3718m, Math.Round((decimal)r3.S3, 4));
            Assert.AreEqual(265.7235m, Math.Round((decimal)r3.S4, 4));
            Assert.AreEqual(271.9028m, Math.Round((decimal)r3.R1, 4));
            Assert.AreEqual(272.7855m, Math.Round((decimal)r3.R2, 4));
            Assert.AreEqual(273.66825m, Math.Round((decimal)r3.R3, 5));
            Assert.AreEqual(276.3165m, Math.Round((decimal)r3.R4, 4));

            PivotPointsResult r4 = results[22];

            Assert.AreEqual(268.9600m, Math.Round((decimal)r4.PP, 4));
            Assert.AreEqual(267.9819m, Math.Round((decimal)r4.S1, 4));
            Assert.AreEqual(267.0038m, Math.Round((decimal)r4.S2, 4));
            Assert.AreEqual(266.0258m, Math.Round((decimal)r4.S3, 4));
            Assert.AreEqual(263.0915m, Math.Round((decimal)r4.S4, 4));
            Assert.AreEqual(269.9381m, Math.Round((decimal)r4.R1, 4));
            Assert.AreEqual(270.9162m, Math.Round((decimal)r4.R2, 4));
            Assert.AreEqual(271.89425m, Math.Round((decimal)r4.R3, 5));
            Assert.AreEqual(274.8285m, Math.Round((decimal)r4.R4, 4));

            PivotPointsResult r5 = results[23];

            Assert.AreEqual(257.1700m, Math.Round((decimal)r5.PP, 4));
            Assert.AreEqual(255.5640m, Math.Round((decimal)r5.S1, 4));
            Assert.AreEqual(253.9580m, Math.Round((decimal)r5.S2, 4));
            Assert.AreEqual(252.3520m, Math.Round((decimal)r5.S3, 4));
            Assert.AreEqual(247.5340m, Math.Round((decimal)r5.S4, 4));
            Assert.AreEqual(258.7760m, Math.Round((decimal)r5.R1, 4));
            Assert.AreEqual(260.3820m, Math.Round((decimal)r5.R2, 4));
            Assert.AreEqual(261.9880m, Math.Round((decimal)r5.R3, 4));
            Assert.AreEqual(266.8060m, Math.Round((decimal)r5.R4, 4));

            PivotPointsResult r6 = results[37];

            Assert.AreEqual(243.1500m, Math.Round((decimal)r6.PP, 4));
            Assert.AreEqual(241.56325m, Math.Round((decimal)r6.S1, 5));
            Assert.AreEqual(239.9765m, Math.Round((decimal)r6.S2, 4));
            Assert.AreEqual(238.3898m, Math.Round((decimal)r6.S3, 4));
            Assert.AreEqual(233.6295m, Math.Round((decimal)r6.S4, 4));
            Assert.AreEqual(244.7368m, Math.Round((decimal)r6.R1, 4));
            Assert.AreEqual(246.3235m, Math.Round((decimal)r6.R2, 4));
            Assert.AreEqual(247.91025m, Math.Round((decimal)r6.R3, 5));
            Assert.AreEqual(252.6705m, Math.Round((decimal)r6.R4, 4));
        }
        public void Camarilla()
        {
            int            windowPeriod = 10;
            int            offsetPeriod = 0;
            PivotPointType pointType    = PivotPointType.Camarilla;

            IEnumerable <Quote>      h       = HistoryTestData.Get(38);
            List <PivotPointsResult> results =
                Indicator.GetRollingPivots(h, windowPeriod, offsetPeriod, pointType)
                .ToList();

            // assertions

            // proper quantities
            // should always be the same number of results as there is history
            Assert.AreEqual(38, results.Count);
            Assert.AreEqual(28, results.Where(x => x.PP != null).Count());

            // sample values
            PivotPointsResult r1 = results[9];

            Assert.AreEqual(null, r1.R4);
            Assert.AreEqual(null, r1.R3);
            Assert.AreEqual(null, r1.PP);
            Assert.AreEqual(null, r1.S1);
            Assert.AreEqual(null, r1.S2);
            Assert.AreEqual(null, r1.R1);
            Assert.AreEqual(null, r1.R2);
            Assert.AreEqual(null, r1.S3);
            Assert.AreEqual(null, r1.S4);

            PivotPointsResult r2 = results[10];

            Assert.AreEqual(267.0800m, Math.Round((decimal)r2.PP, 4));
            Assert.AreEqual(265.8095m, Math.Round((decimal)r2.S1, 4));
            Assert.AreEqual(264.5390m, Math.Round((decimal)r2.S2, 4));
            Assert.AreEqual(263.2685m, Math.Round((decimal)r2.S3, 4));
            Assert.AreEqual(259.4570m, Math.Round((decimal)r2.S4, 4));
            Assert.AreEqual(268.3505m, Math.Round((decimal)r2.R1, 4));
            Assert.AreEqual(269.6210m, Math.Round((decimal)r2.R2, 4));
            Assert.AreEqual(270.8915m, Math.Round((decimal)r2.R3, 4));
            Assert.AreEqual(274.7030m, Math.Round((decimal)r2.R4, 4));

            PivotPointsResult r3 = results[22];

            Assert.AreEqual(263.2900m, Math.Round((decimal)r3.PP, 4));
            Assert.AreEqual(261.6840m, Math.Round((decimal)r3.S1, 4));
            Assert.AreEqual(260.0780m, Math.Round((decimal)r3.S2, 4));
            Assert.AreEqual(258.4720m, Math.Round((decimal)r3.S3, 4));
            Assert.AreEqual(253.6540m, Math.Round((decimal)r3.S4, 4));
            Assert.AreEqual(264.8960m, Math.Round((decimal)r3.R1, 4));
            Assert.AreEqual(266.5020m, Math.Round((decimal)r3.R2, 4));
            Assert.AreEqual(268.1080m, Math.Round((decimal)r3.R3, 4));
            Assert.AreEqual(272.9260m, Math.Round((decimal)r3.R4, 4));

            PivotPointsResult r4 = results[23];

            Assert.AreEqual(257.1700m, Math.Round((decimal)r4.PP, 4));
            Assert.AreEqual(255.5640m, Math.Round((decimal)r4.S1, 4));
            Assert.AreEqual(253.9580m, Math.Round((decimal)r4.S2, 4));
            Assert.AreEqual(252.3520m, Math.Round((decimal)r4.S3, 4));
            Assert.AreEqual(247.5340m, Math.Round((decimal)r4.S4, 4));
            Assert.AreEqual(258.7760m, Math.Round((decimal)r4.R1, 4));
            Assert.AreEqual(260.3820m, Math.Round((decimal)r4.R2, 4));
            Assert.AreEqual(261.9880m, Math.Round((decimal)r4.R3, 4));
            Assert.AreEqual(266.8060m, Math.Round((decimal)r4.R4, 4));

            PivotPointsResult r5 = results[37];

            Assert.AreEqual(243.1500m, Math.Round((decimal)r5.PP, 4));
            Assert.AreEqual(240.5650m, Math.Round((decimal)r5.S1, 4));
            Assert.AreEqual(237.9800m, Math.Round((decimal)r5.S2, 4));
            Assert.AreEqual(235.3950m, Math.Round((decimal)r5.S3, 4));
            Assert.AreEqual(227.6400m, Math.Round((decimal)r5.S4, 4));
            Assert.AreEqual(245.7350m, Math.Round((decimal)r5.R1, 4));
            Assert.AreEqual(248.3200m, Math.Round((decimal)r5.R2, 4));
            Assert.AreEqual(250.9050m, Math.Round((decimal)r5.R3, 4));
            Assert.AreEqual(258.6600m, Math.Round((decimal)r5.R4, 4));
        }
Ejemplo n.º 9
0
    // PIVOT POINTS
    /// <include file='./info.xml' path='indicator/*' />
    ///
    public static IEnumerable <PivotPointsResult> GetPivotPoints <TQuote>(
        this IEnumerable <TQuote> quotes,
        PeriodSize windowSize,
        PivotPointType pointType = PivotPointType.Standard)
        where TQuote : IQuote
    {
        // sort quotes
        List <TQuote> quotesList = quotes.SortToList();

        // initialize
        int length = quotesList.Count;
        List <PivotPointsResult> results     = new(length);
        PivotPointsResult        windowPoint = new();
        TQuote h0;

        if (length == 0)
        {
            return(results);
        }
        else
        {
            h0 = quotesList[0];
        }

        int  windowId = GetWindowNumber(h0.Date, windowSize);
        int  windowEval;
        bool firstWindow = true;

        decimal windowHigh  = h0.High;
        decimal windowLow   = h0.Low;
        decimal windowOpen  = h0.Open;
        decimal windowClose = h0.Close;

        // roll through quotes
        for (int i = 0; i < length; i++)
        {
            TQuote q = quotesList[i];

            PivotPointsResult r = new()
            {
                Date = q.Date
            };

            // new window evaluation
            windowEval = GetWindowNumber(q.Date, windowSize);

            if (windowEval != windowId)
            {
                windowId    = windowEval;
                firstWindow = false;

                // set new levels
                if (pointType == PivotPointType.Woodie)
                {
                    windowOpen = q.Open;
                }

                windowPoint = GetPivotPoint <PivotPointsResult>(
                    pointType, windowOpen, windowHigh, windowLow, windowClose);

                // reset window min/max thresholds
                windowOpen = q.Open;
                windowHigh = q.High;
                windowLow  = q.Low;
            }

            // add levels
            if (!firstWindow)
            {
                // pivot point
                r.PP = windowPoint.PP;

                // support
                r.S1 = windowPoint.S1;
                r.S2 = windowPoint.S2;
                r.S3 = windowPoint.S3;
                r.S4 = windowPoint.S4;

                // resistance
                r.R1 = windowPoint.R1;
                r.R2 = windowPoint.R2;
                r.R3 = windowPoint.R3;
                r.R4 = windowPoint.R4;
            }

            results.Add(r);

            // capture window threholds (for next iteration)
            windowHigh  = (q.High > windowHigh) ? q.High : windowHigh;
            windowLow   = (q.Low < windowLow) ? q.Low : windowLow;
            windowClose = q.Close;
        }

        return(results);
    }
Ejemplo n.º 10
0
        public void GetPivotPointsWoodie()
        {
            PeriodSize     periodSize = PeriodSize.Day;
            PivotPointType pointType  = PivotPointType.Woodie;

            IEnumerable <Quote>      h       = History.GetHistoryIntraday();
            List <PivotPointsResult> results = Indicator.GetPivotPoints(h, periodSize, pointType)
                                               .ToList();

            // assertions

            // proper quantities
            // should always be the same number of results as there is history
            Assert.AreEqual(1564, results.Count);
            Assert.AreEqual(1173, results.Where(x => x.PP != null).Count());

            // sample values
            PivotPointsResult r1 = results[1563];

            Assert.AreEqual(371.3625m, Math.Round((decimal)r1.PP, 4));
            Assert.AreEqual(370.2650m, Math.Round((decimal)r1.S1, 4));
            Assert.AreEqual(369.9525m, Math.Round((decimal)r1.S2, 4));
            Assert.AreEqual(368.8550m, Math.Round((decimal)r1.S3, 4));
            Assert.AreEqual(371.6750m, Math.Round((decimal)r1.R1, 4));
            Assert.AreEqual(372.7725m, Math.Round((decimal)r1.R2, 4));
            Assert.AreEqual(373.0850m, Math.Round((decimal)r1.R3, 4));

            PivotPointsResult r2 = results[1173];

            Assert.AreEqual(371.3625m, Math.Round((decimal)r2.PP, 4));
            Assert.AreEqual(370.2650m, Math.Round((decimal)r2.S1, 4));
            Assert.AreEqual(369.9525m, Math.Round((decimal)r2.S2, 4));
            Assert.AreEqual(368.8550m, Math.Round((decimal)r2.S3, 4));
            Assert.AreEqual(371.6750m, Math.Round((decimal)r2.R1, 4));
            Assert.AreEqual(372.7725m, Math.Round((decimal)r2.R2, 4));
            Assert.AreEqual(373.0850m, Math.Round((decimal)r2.R3, 4));

            PivotPointsResult r3 = results[1172];

            Assert.AreEqual(370.9769m, Math.Round((decimal)r3.PP, 4));
            Assert.AreEqual(370.7938m, Math.Round((decimal)r3.S1, 4));
            Assert.AreEqual(368.6845m, Math.Round((decimal)r3.S2, 4));
            Assert.AreEqual(368.5014m, Math.Round((decimal)r3.S3, 4));
            Assert.AreEqual(373.0862m, Math.Round((decimal)r3.R1, 4));
            Assert.AreEqual(373.2693m, Math.Round((decimal)r3.R2, 4));
            Assert.AreEqual(375.3786m, Math.Round((decimal)r3.R3, 4));

            PivotPointsResult r4 = results[391];

            Assert.AreEqual(368.7875m, Math.Round((decimal)r4.PP, 4));
            Assert.AreEqual(367.9850m, Math.Round((decimal)r4.S1, 4));
            Assert.AreEqual(365.1175m, Math.Round((decimal)r4.S2, 4));
            Assert.AreEqual(364.3150m, Math.Round((decimal)r4.S3, 4));
            Assert.AreEqual(371.6550m, Math.Round((decimal)r4.R1, 4));
            Assert.AreEqual(372.4575m, Math.Round((decimal)r4.R2, 4));
            Assert.AreEqual(375.3250m, Math.Round((decimal)r4.R3, 4));

            PivotPointsResult r5 = results[390];

            Assert.AreEqual(null, r5.R4);
            Assert.AreEqual(null, r5.R3);
            Assert.AreEqual(null, r5.PP);
            Assert.AreEqual(null, r5.S1);
            Assert.AreEqual(null, r5.S2);
            Assert.AreEqual(null, r5.R1);
            Assert.AreEqual(null, r5.R2);
            Assert.AreEqual(null, r5.S3);
            Assert.AreEqual(null, r5.S4);
        }
Ejemplo n.º 11
0
        public void GetPivotPointsDemark()
        {
            PeriodSize     periodSize = PeriodSize.Month;
            PivotPointType pointType  = PivotPointType.Demark;

            List <PivotPointsResult> results = Indicator.GetPivotPoints(history, periodSize, pointType)
                                               .ToList();

            // assertions

            // proper quantities
            // should always be the same number of results as there is history
            Assert.AreEqual(502, results.Count);
            Assert.AreEqual(482, results.Where(x => x.PP != null).Count());

            // sample values
            PivotPointsResult r1 = results[501];

            Assert.AreEqual(null, r1.R4);
            Assert.AreEqual(null, r1.R3);
            Assert.AreEqual(268.6050m, Math.Round((decimal)r1.PP, 4));
            Assert.AreEqual(262.8200m, Math.Round((decimal)r1.S1, 4));
            Assert.AreEqual(null, r1.S2);
            Assert.AreEqual(280.5300m, Math.Round((decimal)r1.R1, 4));
            Assert.AreEqual(null, r1.R2);
            Assert.AreEqual(null, r1.S3);
            Assert.AreEqual(null, r1.S4);

            PivotPointsResult r2 = results[251];

            Assert.AreEqual(null, r2.R4);
            Assert.AreEqual(null, r2.R3);
            Assert.AreEqual(256.0725m, Math.Round((decimal)r2.PP, 4));
            Assert.AreEqual(253.4450m, Math.Round((decimal)r2.S1, 4));
            Assert.AreEqual(null, r2.S2);
            Assert.AreEqual(262.2750m, Math.Round((decimal)r2.R1, 4));
            Assert.AreEqual(null, r2.R2);
            Assert.AreEqual(null, r2.S3);
            Assert.AreEqual(null, r2.S4);

            PivotPointsResult r3 = results[250];

            Assert.AreEqual(null, r3.R4);
            Assert.AreEqual(null, r3.R3);
            Assert.AreEqual(252.1925m, Math.Round((decimal)r3.PP, 4));
            Assert.AreEqual(249.4450m, Math.Round((decimal)r3.S1, 4));
            Assert.AreEqual(null, r3.S2);
            Assert.AreEqual(259.4350m, Math.Round((decimal)r3.R1, 4));
            Assert.AreEqual(null, r3.R2);
            Assert.AreEqual(null, r3.S3);
            Assert.AreEqual(null, r3.S4);

            PivotPointsResult r4 = results[149];

            Assert.AreEqual(null, r4.R4);
            Assert.AreEqual(null, r4.R3);
            Assert.AreEqual(234.3475m, Math.Round((decimal)r4.PP, 4));
            Assert.AreEqual(232.2250m, Math.Round((decimal)r4.S1, 4));
            Assert.AreEqual(null, r4.S2);
            Assert.AreEqual(239.5350m, Math.Round((decimal)r4.R1, 4));
            Assert.AreEqual(null, r4.R2);
            Assert.AreEqual(null, r4.S3);
            Assert.AreEqual(null, r4.S4);

            PivotPointsResult r5 = results[20];

            Assert.AreEqual(null, r5.R4);
            Assert.AreEqual(null, r5.R3);
            Assert.AreEqual(215.1300m, Math.Round((decimal)r5.PP, 4));
            Assert.AreEqual(213.2400m, Math.Round((decimal)r5.S1, 4));
            Assert.AreEqual(null, r5.S2);
            Assert.AreEqual(218.7400m, Math.Round((decimal)r5.R1, 4));
            Assert.AreEqual(null, r5.R2);
            Assert.AreEqual(null, r5.S3);
            Assert.AreEqual(null, r5.S4);

            PivotPointsResult r6 = results[19];

            Assert.AreEqual(null, r6.R4);
            Assert.AreEqual(null, r6.R3);
            Assert.AreEqual(null, r6.PP);
            Assert.AreEqual(null, r6.S1);
            Assert.AreEqual(null, r6.S2);
            Assert.AreEqual(null, r6.R1);
            Assert.AreEqual(null, r6.R2);
            Assert.AreEqual(null, r6.S3);
            Assert.AreEqual(null, r6.S4);
        }
Ejemplo n.º 12
0
        public void Standard()
        {
            int            windowPeriod = 11;
            int            offsetPeriod = 9;
            PivotPointType pointType    = PivotPointType.Standard;

            List <PivotPointsResult> results =
                history.GetRollingPivots(windowPeriod, offsetPeriod, pointType)
                .ToList();

            // assertions

            // proper quantities
            // should always be the same number of results as there is history
            Assert.AreEqual(502, results.Count);
            Assert.AreEqual(482, results.Where(x => x.PP != null).Count());

            // sample values
            PivotPointsResult r1 = results[19];

            Assert.AreEqual(null, r1.R4);
            Assert.AreEqual(null, r1.R3);
            Assert.AreEqual(null, r1.PP);
            Assert.AreEqual(null, r1.S1);
            Assert.AreEqual(null, r1.S2);
            Assert.AreEqual(null, r1.R1);
            Assert.AreEqual(null, r1.R2);
            Assert.AreEqual(null, r1.S3);
            Assert.AreEqual(null, r1.S4);

            PivotPointsResult r2 = results[20];

            Assert.AreEqual(null, r2.R4);
            Assert.AreEqual(null, r2.R3);
            Assert.AreEqual(213.6367m, Math.Round((decimal)r2.PP, 4));
            Assert.AreEqual(212.1033m, Math.Round((decimal)r2.S1, 4));
            Assert.AreEqual(209.9867m, Math.Round((decimal)r2.S2, 4));
            Assert.AreEqual(215.7533m, Math.Round((decimal)r2.R1, 4));
            Assert.AreEqual(217.2867m, Math.Round((decimal)r2.R2, 4));
            Assert.AreEqual(null, r2.S3);
            Assert.AreEqual(null, r2.S4);

            PivotPointsResult r3 = results[149];

            Assert.AreEqual(null, r3.R4);
            Assert.AreEqual(null, r3.R3);
            Assert.AreEqual(233.6333m, Math.Round((decimal)r3.PP, 4));
            Assert.AreEqual(231.3567m, Math.Round((decimal)r3.S1, 4));
            Assert.AreEqual(227.3733m, Math.Round((decimal)r3.S2, 4));
            Assert.AreEqual(237.6167m, Math.Round((decimal)r3.R1, 4));
            Assert.AreEqual(239.8933m, Math.Round((decimal)r3.R2, 4));
            Assert.AreEqual(null, r3.S3);
            Assert.AreEqual(null, r3.S4);

            PivotPointsResult r4 = results[249];

            Assert.AreEqual(null, r4.R4);
            Assert.AreEqual(null, r4.R3);
            Assert.AreEqual(253.9533m, Math.Round((decimal)r4.PP, 4));
            Assert.AreEqual(251.5267m, Math.Round((decimal)r4.S1, 4));
            Assert.AreEqual(247.4433m, Math.Round((decimal)r4.S2, 4));
            Assert.AreEqual(258.0367m, Math.Round((decimal)r4.R1, 4));
            Assert.AreEqual(260.4633m, Math.Round((decimal)r4.R2, 4));
            Assert.AreEqual(null, r4.S3);
            Assert.AreEqual(null, r4.S4);

            PivotPointsResult r5 = results[501];

            Assert.AreEqual(null, r5.R4);
            Assert.AreEqual(null, r5.R3);
            Assert.AreEqual(260.0267m, Math.Round((decimal)r5.PP, 4));
            Assert.AreEqual(246.4633m, Math.Round((decimal)r5.S1, 4));
            Assert.AreEqual(238.7767m, Math.Round((decimal)r5.S2, 4));
            Assert.AreEqual(267.7133m, Math.Round((decimal)r5.R1, 4));
            Assert.AreEqual(281.2767m, Math.Round((decimal)r5.R2, 4));
            Assert.AreEqual(null, r5.S3);
            Assert.AreEqual(null, r5.S4);
        }
Ejemplo n.º 13
0
    // PIVOT POINTS
    /// <include file='./info.xml' path='indicator/*' />
    ///
    public static IEnumerable <RollingPivotsResult> GetRollingPivots <TQuote>(
        this IEnumerable <TQuote> quotes,
        int windowPeriods,
        int offsetPeriods,
        PivotPointType pointType = PivotPointType.Standard)
        where TQuote : IQuote
    {
        // sort quotes
        List <TQuote> quotesList = quotes.SortToList();

        // check parameter arguments
        ValidateRollingPivots(windowPeriods, offsetPeriods);

        // initialize
        List <RollingPivotsResult> results = new(quotesList.Count);

        // roll through quotes
        for (int i = 0; i < quotesList.Count; i++)
        {
            TQuote q = quotesList[i];

            RollingPivotsResult r = new()
            {
                Date = q.Date
            };

            if (i >= windowPeriods + offsetPeriods)
            {
                // window values
                int    s  = i - windowPeriods - offsetPeriods;
                TQuote hi = quotesList[s];

                decimal windowHigh  = hi.High;
                decimal windowLow   = hi.Low;
                decimal windowClose = quotesList[i - offsetPeriods - 1].Close;

                for (int p = s; p <= i - offsetPeriods - 1; p++)
                {
                    TQuote d = quotesList[p];
                    windowHigh = (d.High > windowHigh) ? d.High : windowHigh;
                    windowLow  = (d.Low < windowLow) ? d.Low : windowLow;
                }

                // pivot points
                RollingPivotsResult wp = GetPivotPoint <RollingPivotsResult>(
                    pointType, q.Open, windowHigh, windowLow, windowClose);

                r.PP = wp.PP;
                r.S1 = wp.S1;
                r.S2 = wp.S2;
                r.S3 = wp.S3;
                r.S4 = wp.S4;
                r.R1 = wp.R1;
                r.R2 = wp.R2;
                r.R3 = wp.R3;
                r.R4 = wp.R4;
            }

            results.Add(r);
        }

        return(results);
    }
Ejemplo n.º 14
0
        // PIVOT POINTS
        /// <include file='./info.xml' path='indicator/*' />
        ///
        public static IEnumerable <PivotPointsResult> GetRollingPivots <TQuote>(
            IEnumerable <TQuote> history,
            int windowPeriod,
            int offsetPeriod,
            PivotPointType pointType = PivotPointType.Standard)
            where TQuote : IQuote
        {
            // sort history
            List <TQuote> historyList = history.Sort();

            // check parameter arguments
            ValidateRollingPivots(history, windowPeriod, offsetPeriod);

            // initialize
            List <PivotPointsResult> results = new(historyList.Count);

            // roll through history
            for (int i = 0; i < historyList.Count; i++)
            {
                TQuote h = historyList[i];

                PivotPointsResult r = new()
                {
                    Date = h.Date
                };

                if (i >= windowPeriod + offsetPeriod)
                {
                    // window values
                    int    s  = i - windowPeriod - offsetPeriod;
                    TQuote hi = historyList[s];

                    decimal windowHigh  = hi.High;
                    decimal windowLow   = hi.Low;
                    decimal windowClose = historyList[i - offsetPeriod - 1].Close;

                    for (int p = s; p <= i - offsetPeriod - 1; p++)
                    {
                        TQuote d = historyList[p];
                        windowHigh = (d.High > windowHigh) ? d.High : windowHigh;
                        windowLow  = (d.Low < windowLow) ? d.Low : windowLow;
                    }

                    // pivot points
                    PivotPointsResult wp =
                        GetPivotPoint(pointType, h.Open, windowHigh, windowLow, windowClose);

                    r.PP = wp.PP;
                    r.S1 = wp.S1;
                    r.S2 = wp.S2;
                    r.S3 = wp.S3;
                    r.S4 = wp.S4;
                    r.R1 = wp.R1;
                    r.R2 = wp.R2;
                    r.R3 = wp.R3;
                    r.R4 = wp.R4;
                }

                results.Add(r);
            }
            return(results);
        }
Ejemplo n.º 15
0
        public void GetPivotPointsCamarilla()
        {
            PeriodSize     periodSize = PeriodSize.Week;
            PivotPointType pointType  = PivotPointType.Camarilla;

            IEnumerable <Quote>      h       = History.GetHistory(38);
            List <PivotPointsResult> results = Indicator.GetPivotPoints(h, periodSize, pointType)
                                               .ToList();

            // assertions

            // proper quantities
            // should always be the same number of results as there is history
            Assert.AreEqual(38, results.Count);
            Assert.AreEqual(33, results.Where(x => x.PP != null).Count());

            // sample values
            PivotPointsResult r1 = results[37];

            Assert.AreEqual(239.7667m, Math.Round((decimal)r1.PP, 4));
            Assert.AreEqual(224.3975m, Math.Round((decimal)r1.S1, 4));
            Assert.AreEqual(222.9550m, Math.Round((decimal)r1.S2, 4));
            Assert.AreEqual(221.5125m, Math.Round((decimal)r1.S3, 4));
            Assert.AreEqual(217.1850m, Math.Round((decimal)r1.S4, 4));
            Assert.AreEqual(261.9025m, Math.Round((decimal)r1.R1, 4));
            Assert.AreEqual(263.3450m, Math.Round((decimal)r1.R2, 4));
            Assert.AreEqual(264.7875m, Math.Round((decimal)r1.R3, 4));
            Assert.AreEqual(269.1150m, Math.Round((decimal)r1.R4, 4));

            PivotPointsResult r2 = results[23];

            Assert.AreEqual(262.2767m, Math.Round((decimal)r2.PP, 4));
            Assert.AreEqual(238.1900m, Math.Round((decimal)r2.S1, 4));
            Assert.AreEqual(236.7300m, Math.Round((decimal)r2.S2, 4));
            Assert.AreEqual(235.2700m, Math.Round((decimal)r2.S3, 4));
            Assert.AreEqual(230.8900m, Math.Round((decimal)r2.S4, 4));
            Assert.AreEqual(276.1500m, Math.Round((decimal)r2.R1, 4));
            Assert.AreEqual(277.6100m, Math.Round((decimal)r2.R2, 4));
            Assert.AreEqual(279.0700m, Math.Round((decimal)r2.R3, 4));
            Assert.AreEqual(283.4500m, Math.Round((decimal)r2.R4, 4));

            PivotPointsResult r3 = results[22];

            Assert.AreEqual(265.8100m, Math.Round((decimal)r3.PP, 4));
            Assert.AreEqual(257.4008m, Math.Round((decimal)r3.S1, 4));
            Assert.AreEqual(256.5117m, Math.Round((decimal)r3.S2, 4));
            Assert.AreEqual(255.6225m, Math.Round((decimal)r3.S3, 4));
            Assert.AreEqual(252.9550m, Math.Round((decimal)r3.S4, 4));
            Assert.AreEqual(280.5192m, Math.Round((decimal)r3.R1, 4));
            Assert.AreEqual(281.4083m, Math.Round((decimal)r3.R2, 4));
            Assert.AreEqual(282.2975m, Math.Round((decimal)r3.R3, 4));
            Assert.AreEqual(284.9650m, Math.Round((decimal)r3.R4, 4));

            PivotPointsResult r4 = results[5];

            Assert.AreEqual(270.0567m, Math.Round((decimal)r4.PP, 4));
            Assert.AreEqual(260.5875m, Math.Round((decimal)r4.S1, 4));
            Assert.AreEqual(259.7850m, Math.Round((decimal)r4.S2, 4));
            Assert.AreEqual(258.9825m, Math.Round((decimal)r4.S3, 4));
            Assert.AreEqual(256.5750m, Math.Round((decimal)r4.S4, 4));
            Assert.AreEqual(281.4525m, Math.Round((decimal)r4.R1, 4));
            Assert.AreEqual(282.2550m, Math.Round((decimal)r4.R2, 4));
            Assert.AreEqual(283.0575m, Math.Round((decimal)r4.R3, 4));
            Assert.AreEqual(285.4650m, Math.Round((decimal)r4.R4, 4));

            PivotPointsResult r5 = results[4];

            Assert.AreEqual(null, r5.R4);
            Assert.AreEqual(null, r5.R3);
            Assert.AreEqual(null, r5.PP);
            Assert.AreEqual(null, r5.S1);
            Assert.AreEqual(null, r5.S2);
            Assert.AreEqual(null, r5.R1);
            Assert.AreEqual(null, r5.R2);
            Assert.AreEqual(null, r5.S3);
            Assert.AreEqual(null, r5.S4);
        }
Ejemplo n.º 16
0
        public void GetPivotPointsStandard()
        {
            PeriodSize     periodSize = PeriodSize.Month;
            PivotPointType pointType  = PivotPointType.Standard;

            List <PivotPointsResult> results = Indicator.GetPivotPoints(history, periodSize, pointType)
                                               .ToList();

            // assertions

            // proper quantities
            // should always be the same number of results as there is history
            Assert.AreEqual(502, results.Count);
            Assert.AreEqual(482, results.Where(x => x.PP != null).Count());

            // sample values
            PivotPointsResult r1 = results[501];

            Assert.AreEqual(null, r1.R4);
            Assert.AreEqual(null, r1.R3);
            Assert.AreEqual(266.6767m, Math.Round((decimal)r1.PP, 4));
            Assert.AreEqual(258.9633m, Math.Round((decimal)r1.S1, 4));
            Assert.AreEqual(248.9667m, Math.Round((decimal)r1.S2, 4));
            Assert.AreEqual(276.6733m, Math.Round((decimal)r1.R1, 4));
            Assert.AreEqual(284.3867m, Math.Round((decimal)r1.R2, 4));
            Assert.AreEqual(null, r1.S3);
            Assert.AreEqual(null, r1.S4);

            PivotPointsResult r2 = results[251];

            Assert.AreEqual(null, r2.R4);
            Assert.AreEqual(null, r2.R3);
            Assert.AreEqual(255.1967m, Math.Round((decimal)r2.PP, 4));
            Assert.AreEqual(251.6933m, Math.Round((decimal)r2.S1, 4));
            Assert.AreEqual(246.3667m, Math.Round((decimal)r2.S2, 4));
            Assert.AreEqual(260.5233m, Math.Round((decimal)r2.R1, 4));
            Assert.AreEqual(264.0267m, Math.Round((decimal)r2.R2, 4));
            Assert.AreEqual(null, r2.S3);
            Assert.AreEqual(null, r2.S4);

            PivotPointsResult r3 = results[250];

            Assert.AreEqual(null, r3.R4);
            Assert.AreEqual(null, r3.R3);
            Assert.AreEqual(251.2767m, Math.Round((decimal)r3.PP, 4));
            Assert.AreEqual(247.6133m, Math.Round((decimal)r3.S1, 4));
            Assert.AreEqual(241.2867m, Math.Round((decimal)r3.S2, 4));
            Assert.AreEqual(257.6033m, Math.Round((decimal)r3.R1, 4));
            Assert.AreEqual(261.2667m, Math.Round((decimal)r3.R2, 4));
            Assert.AreEqual(null, r3.S3);
            Assert.AreEqual(null, r3.S4);

            PivotPointsResult r4 = results[149];

            Assert.AreEqual(null, r4.R4);
            Assert.AreEqual(null, r4.R3);
            Assert.AreEqual(233.6400m, Math.Round((decimal)r4.PP, 4));
            Assert.AreEqual(230.8100m, Math.Round((decimal)r4.S1, 4));
            Assert.AreEqual(226.3300m, Math.Round((decimal)r4.S2, 4));
            Assert.AreEqual(238.1200m, Math.Round((decimal)r4.R1, 4));
            Assert.AreEqual(240.9500m, Math.Round((decimal)r4.R2, 4));
            Assert.AreEqual(null, r4.S3);
            Assert.AreEqual(null, r4.S4);

            PivotPointsResult r5 = results[20];

            Assert.AreEqual(null, r5.R4);
            Assert.AreEqual(null, r5.R3);
            Assert.AreEqual(214.5000m, Math.Round((decimal)r5.PP, 4));
            Assert.AreEqual(211.9800m, Math.Round((decimal)r5.S1, 4));
            Assert.AreEqual(209.0000m, Math.Round((decimal)r5.S2, 4));
            Assert.AreEqual(217.4800m, Math.Round((decimal)r5.R1, 4));
            Assert.AreEqual(220.0000m, Math.Round((decimal)r5.R2, 4));
            Assert.AreEqual(null, r5.S3);
            Assert.AreEqual(null, r5.S4);

            PivotPointsResult r6 = results[19];

            Assert.AreEqual(null, r6.R4);
            Assert.AreEqual(null, r6.R3);
            Assert.AreEqual(null, r6.PP);
            Assert.AreEqual(null, r6.S1);
            Assert.AreEqual(null, r6.S2);
            Assert.AreEqual(null, r6.R1);
            Assert.AreEqual(null, r6.R2);
            Assert.AreEqual(null, r6.S3);
            Assert.AreEqual(null, r6.S4);
        }
Ejemplo n.º 17
0
        public void Demark()
        {
            int            windowPeriod = 10;
            int            offsetPeriod = 10;
            PivotPointType pointType    = PivotPointType.Demark;

            List <PivotPointsResult> results =
                Indicator.GetRollingPivots(history, windowPeriod, offsetPeriod, pointType)
                .ToList();

            // assertions

            // proper quantities
            // should always be the same number of results as there is history
            Assert.AreEqual(502, results.Count);
            Assert.AreEqual(482, results.Where(x => x.PP != null).Count());

            // sample values
            PivotPointsResult r1 = results[19];

            Assert.AreEqual(null, r1.PP);
            Assert.AreEqual(null, r1.S1);
            Assert.AreEqual(null, r1.S2);
            Assert.AreEqual(null, r1.S3);
            Assert.AreEqual(null, r1.S4);
            Assert.AreEqual(null, r1.R1);
            Assert.AreEqual(null, r1.R2);
            Assert.AreEqual(null, r1.R3);
            Assert.AreEqual(null, r1.R4);

            PivotPointsResult r2 = results[20];

            Assert.AreEqual(212.9900m, Math.Round((decimal)r2.PP, 4));
            Assert.AreEqual(210.8100m, Math.Round((decimal)r2.S1, 4));
            Assert.AreEqual(214.4600m, Math.Round((decimal)r2.R1, 4));
            Assert.AreEqual(null, r2.R2);
            Assert.AreEqual(null, r2.R3);
            Assert.AreEqual(null, r2.R4);
            Assert.AreEqual(null, r2.S2);
            Assert.AreEqual(null, r2.S3);
            Assert.AreEqual(null, r2.S4);

            PivotPointsResult r3 = results[149];

            Assert.AreEqual(232.6525m, Math.Round((decimal)r3.PP, 4));
            Assert.AreEqual(229.3950m, Math.Round((decimal)r3.S1, 4));
            Assert.AreEqual(235.6550m, Math.Round((decimal)r3.R1, 4));
            Assert.AreEqual(null, r3.R2);
            Assert.AreEqual(null, r3.R3);
            Assert.AreEqual(null, r3.R4);
            Assert.AreEqual(null, r3.S2);
            Assert.AreEqual(null, r3.S3);
            Assert.AreEqual(null, r3.S4);

            PivotPointsResult r4 = results[250];

            Assert.AreEqual(252.9325m, Math.Round((decimal)r4.PP, 4));
            Assert.AreEqual(249.4850m, Math.Round((decimal)r4.S1, 4));
            Assert.AreEqual(255.9950m, Math.Round((decimal)r4.R1, 4));
            Assert.AreEqual(null, r4.R2);
            Assert.AreEqual(null, r4.R3);
            Assert.AreEqual(null, r4.R4);
            Assert.AreEqual(null, r4.S2);
            Assert.AreEqual(null, r4.S3);
            Assert.AreEqual(null, r4.S4);

            PivotPointsResult r5 = results[251];

            Assert.AreEqual(252.6700m, Math.Round((decimal)r5.PP, 4));
            Assert.AreEqual(248.9600m, Math.Round((decimal)r5.S1, 4));
            Assert.AreEqual(255.4700m, Math.Round((decimal)r5.R1, 4));
            Assert.AreEqual(null, r5.R2);
            Assert.AreEqual(null, r5.R3);
            Assert.AreEqual(null, r5.R4);
            Assert.AreEqual(null, r5.S2);
            Assert.AreEqual(null, r5.S3);
            Assert.AreEqual(null, r5.S4);

            PivotPointsResult r6 = results[501];

            Assert.AreEqual(264.6125m, Math.Round((decimal)r6.PP, 4));
            Assert.AreEqual(255.6350m, Math.Round((decimal)r6.S1, 4));
            Assert.AreEqual(276.8850m, Math.Round((decimal)r6.R1, 4));
            Assert.AreEqual(null, r6.R2);
            Assert.AreEqual(null, r6.R3);
            Assert.AreEqual(null, r6.R4);
            Assert.AreEqual(null, r6.S2);
            Assert.AreEqual(null, r6.S3);
            Assert.AreEqual(null, r6.S4);
        }
Ejemplo n.º 18
0
        public void GetPivotPointsFibonacci()
        {
            PeriodSize     periodSize = PeriodSize.Hour;
            PivotPointType pointType  = PivotPointType.Fibonacci;

            IEnumerable <Quote>      h       = History.GetHistoryIntraday(300);
            List <PivotPointsResult> results = Indicator.GetPivotPoints(h, periodSize, pointType)
                                               .ToList();

            // assertions

            // proper quantities
            // should always be the same number of results as there is history
            Assert.AreEqual(300, results.Count);
            Assert.AreEqual(241, results.Where(x => x.PP != null).Count());

            // sample values
            PivotPointsResult r1 = results[299];

            Assert.AreEqual(368.8200m, Math.Round((decimal)r1.PP, 4));
            Assert.AreEqual(367.5632m, Math.Round((decimal)r1.S1, 4));
            Assert.AreEqual(366.7868m, Math.Round((decimal)r1.S2, 4));
            Assert.AreEqual(365.5300m, Math.Round((decimal)r1.S3, 4));
            Assert.AreEqual(370.0768m, Math.Round((decimal)r1.R1, 4));
            Assert.AreEqual(370.8532m, Math.Round((decimal)r1.R2, 4));
            Assert.AreEqual(372.1100m, Math.Round((decimal)r1.R3, 4));

            PivotPointsResult r2 = results[149];

            Assert.AreEqual(369.0000m, Math.Round((decimal)r2.PP, 4));
            Assert.AreEqual(368.5760m, Math.Round((decimal)r2.S1, 4));
            Assert.AreEqual(368.3140m, Math.Round((decimal)r2.S2, 4));
            Assert.AreEqual(367.8900m, Math.Round((decimal)r2.S3, 4));
            Assert.AreEqual(369.4240m, Math.Round((decimal)r2.R1, 4));
            Assert.AreEqual(369.6860m, Math.Round((decimal)r2.R2, 4));
            Assert.AreEqual(370.1100m, Math.Round((decimal)r2.R3, 4));

            PivotPointsResult r3 = results[119];

            Assert.AreEqual(369.0000m, Math.Round((decimal)r3.PP, 4));
            Assert.AreEqual(368.5760m, Math.Round((decimal)r3.S1, 4));
            Assert.AreEqual(368.3140m, Math.Round((decimal)r3.S2, 4));
            Assert.AreEqual(367.8900m, Math.Round((decimal)r3.S3, 4));
            Assert.AreEqual(369.4240m, Math.Round((decimal)r3.R1, 4));
            Assert.AreEqual(369.6860m, Math.Round((decimal)r3.R2, 4));
            Assert.AreEqual(370.1100m, Math.Round((decimal)r3.R3, 4));

            PivotPointsResult r4 = results[118];

            Assert.AreEqual(368.4967m, Math.Round((decimal)r4.PP, 4));
            Assert.AreEqual(367.9237m, Math.Round((decimal)r4.S1, 4));
            Assert.AreEqual(367.5697m, Math.Round((decimal)r4.S2, 4));
            Assert.AreEqual(366.9967m, Math.Round((decimal)r4.S3, 4));
            Assert.AreEqual(369.0697m, Math.Round((decimal)r4.R1, 4));
            Assert.AreEqual(369.4237m, Math.Round((decimal)r4.R2, 4));
            Assert.AreEqual(369.9967m, Math.Round((decimal)r4.R3, 4));

            PivotPointsResult r5 = results[59];

            Assert.AreEqual(368.4967m, Math.Round((decimal)r5.PP, 4));
            Assert.AreEqual(367.9237m, Math.Round((decimal)r5.S1, 4));
            Assert.AreEqual(367.5697m, Math.Round((decimal)r5.S2, 4));
            Assert.AreEqual(366.9967m, Math.Round((decimal)r5.S3, 4));
            Assert.AreEqual(369.0697m, Math.Round((decimal)r5.R1, 4));
            Assert.AreEqual(369.4237m, Math.Round((decimal)r5.R2, 4));
            Assert.AreEqual(369.9967m, Math.Round((decimal)r5.R3, 4));

            PivotPointsResult r6 = results[58];

            Assert.AreEqual(null, r6.R4);
            Assert.AreEqual(null, r6.R3);
            Assert.AreEqual(null, r6.PP);
            Assert.AreEqual(null, r6.S1);
            Assert.AreEqual(null, r6.S2);
            Assert.AreEqual(null, r6.R1);
            Assert.AreEqual(null, r6.R2);
            Assert.AreEqual(null, r6.S3);
            Assert.AreEqual(null, r6.S4);
        }
Ejemplo n.º 19
0
        public void Fibonacci()
        {
            int            windowPeriod = 44;
            int            offsetPeriod = 15;
            PivotPointType pointType    = PivotPointType.Fibonacci;

            IEnumerable <Quote>      h       = HistoryTestData.GetIntraday(300);
            List <PivotPointsResult> results =
                Indicator.GetRollingPivots(h, windowPeriod, offsetPeriod, pointType)
                .ToList();

            // assertions

            // proper quantities
            // should always be the same number of results as there is history
            Assert.AreEqual(300, results.Count);
            Assert.AreEqual(241, results.Where(x => x.PP != null).Count());

            // sample values
            PivotPointsResult r1 = results[58];

            Assert.AreEqual(null, r1.R4);
            Assert.AreEqual(null, r1.R3);
            Assert.AreEqual(null, r1.PP);
            Assert.AreEqual(null, r1.S1);
            Assert.AreEqual(null, r1.S2);
            Assert.AreEqual(null, r1.R1);
            Assert.AreEqual(null, r1.R2);
            Assert.AreEqual(null, r1.S3);
            Assert.AreEqual(null, r1.S4);

            PivotPointsResult r2 = results[59];

            Assert.AreEqual(368.4283m, Math.Round((decimal)r2.PP, 4));
            Assert.AreEqual(367.8553m, Math.Round((decimal)r2.S1, 4));
            Assert.AreEqual(367.5013m, Math.Round((decimal)r2.S2, 4));
            Assert.AreEqual(366.9283m, Math.Round((decimal)r2.S3, 4));
            Assert.AreEqual(369.0013m, Math.Round((decimal)r2.R1, 4));
            Assert.AreEqual(369.3553m, Math.Round((decimal)r2.R2, 4));
            Assert.AreEqual(369.9283m, Math.Round((decimal)r2.R3, 4));

            PivotPointsResult r3 = results[118];

            Assert.AreEqual(369.1573m, Math.Round((decimal)r3.PP, 4));
            Assert.AreEqual(368.7333m, Math.Round((decimal)r3.S1, 4));
            Assert.AreEqual(368.4713m, Math.Round((decimal)r3.S2, 4));
            Assert.AreEqual(368.0473m, Math.Round((decimal)r3.S3, 4));
            Assert.AreEqual(369.5813m, Math.Round((decimal)r3.R1, 4));
            Assert.AreEqual(369.8433m, Math.Round((decimal)r3.R2, 4));
            Assert.AreEqual(370.2673m, Math.Round((decimal)r3.R3, 4));

            PivotPointsResult r4 = results[119];

            Assert.AreEqual(369.1533m, Math.Round((decimal)r4.PP, 4));
            Assert.AreEqual(368.7293m, Math.Round((decimal)r4.S1, 4));
            Assert.AreEqual(368.4674m, Math.Round((decimal)r4.S2, 4));
            Assert.AreEqual(368.0433m, Math.Round((decimal)r4.S3, 4));
            Assert.AreEqual(369.5774m, Math.Round((decimal)r4.R1, 4));
            Assert.AreEqual(369.8393m, Math.Round((decimal)r4.R2, 4));
            Assert.AreEqual(370.2633m, Math.Round((decimal)r4.R3, 4));

            PivotPointsResult r5 = results[149];

            Assert.AreEqual(369.0183m, Math.Round((decimal)r5.PP, 4));
            Assert.AreEqual(368.6593m, Math.Round((decimal)r5.S1, 4));
            Assert.AreEqual(368.4374m, Math.Round((decimal)r5.S2, 4));
            Assert.AreEqual(368.0783m, Math.Round((decimal)r5.S3, 4));
            Assert.AreEqual(369.3774m, Math.Round((decimal)r5.R1, 4));
            Assert.AreEqual(369.5993m, Math.Round((decimal)r5.R2, 4));
            Assert.AreEqual(369.9583m, Math.Round((decimal)r5.R3, 4));

            PivotPointsResult r6 = results[299];

            Assert.AreEqual(367.7567m, Math.Round((decimal)r6.PP, 4));
            Assert.AreEqual(367.3174m, Math.Round((decimal)r6.S1, 4));
            Assert.AreEqual(367.0460m, Math.Round((decimal)r6.S2, 4));
            Assert.AreEqual(366.6067m, Math.Round((decimal)r6.S3, 4));
            Assert.AreEqual(368.1960m, Math.Round((decimal)r6.R1, 4));
            Assert.AreEqual(368.4674m, Math.Round((decimal)r6.R2, 4));
            Assert.AreEqual(368.9067m, Math.Round((decimal)r6.R3, 4));
        }
Ejemplo n.º 20
0
 /// <summary>
 /// Creates a new instance of <see cref="PivotPoint"/>
 /// </summary>
 public PivotPoint(PivotPointType type, decimal price, DateTime time)
 {
     PivotPointType = type;
     Value          = price;
     Time           = time;
 }
Ejemplo n.º 21
0
        public void Woodie()
        {
            int            windowPeriod = 375;
            int            offsetPeriod = 16;
            PivotPointType pointType    = PivotPointType.Woodie;

            IEnumerable <Quote>      h       = HistoryTestData.GetIntraday(1564);
            List <PivotPointsResult> results =
                Indicator.GetRollingPivots(h, windowPeriod, offsetPeriod, pointType)
                .ToList();

            // assertions

            // proper quantities
            // should always be the same number of results as there is history
            Assert.AreEqual(1564, results.Count);
            Assert.AreEqual(1173, results.Where(x => x.PP != null).Count());

            // sample values
            PivotPointsResult r2 = results[390];

            Assert.AreEqual(null, r2.R4);
            Assert.AreEqual(null, r2.R3);
            Assert.AreEqual(null, r2.PP);
            Assert.AreEqual(null, r2.S1);
            Assert.AreEqual(null, r2.S2);
            Assert.AreEqual(null, r2.R1);
            Assert.AreEqual(null, r2.R2);
            Assert.AreEqual(null, r2.S3);
            Assert.AreEqual(null, r2.S4);

            PivotPointsResult r3 = results[391];

            Assert.AreEqual(368.7850m, Math.Round((decimal)r3.PP, 4));
            Assert.AreEqual(367.9901m, Math.Round((decimal)r3.S1, 4));
            Assert.AreEqual(365.1252m, Math.Round((decimal)r3.S2, 4));
            Assert.AreEqual(364.3303m, Math.Round((decimal)r3.S3, 4));
            Assert.AreEqual(371.6499m, Math.Round((decimal)r3.R1, 4));
            Assert.AreEqual(372.4448m, Math.Round((decimal)r3.R2, 4));
            Assert.AreEqual(375.3097m, Math.Round((decimal)r3.R3, 4));

            PivotPointsResult r4 = results[1172];

            Assert.AreEqual(371.75m, Math.Round((decimal)r4.PP, 4));
            Assert.AreEqual(371.04m, Math.Round((decimal)r4.S1, 4));
            Assert.AreEqual(369.35m, Math.Round((decimal)r4.S2, 4));
            Assert.AreEqual(368.64m, Math.Round((decimal)r4.S3, 4));
            Assert.AreEqual(373.44m, Math.Round((decimal)r4.R1, 4));
            Assert.AreEqual(374.15m, Math.Round((decimal)r4.R2, 4));
            Assert.AreEqual(375.84m, Math.Round((decimal)r4.R3, 4));

            PivotPointsResult r5 = results[1173];

            Assert.AreEqual(371.3625m, Math.Round((decimal)r5.PP, 4));
            Assert.AreEqual(370.2650m, Math.Round((decimal)r5.S1, 4));
            Assert.AreEqual(369.9525m, Math.Round((decimal)r5.S2, 4));
            Assert.AreEqual(368.8550m, Math.Round((decimal)r5.S3, 4));
            Assert.AreEqual(371.6750m, Math.Round((decimal)r5.R1, 4));
            Assert.AreEqual(372.7725m, Math.Round((decimal)r5.R2, 4));
            Assert.AreEqual(373.0850m, Math.Round((decimal)r5.R3, 4));

            PivotPointsResult r6 = results[1563];

            Assert.AreEqual(369.38m, Math.Round((decimal)r6.PP, 4));
            Assert.AreEqual(366.52m, Math.Round((decimal)r6.S1, 4));
            Assert.AreEqual(364.16m, Math.Round((decimal)r6.S2, 4));
            Assert.AreEqual(361.30m, Math.Round((decimal)r6.S3, 4));
            Assert.AreEqual(371.74m, Math.Round((decimal)r6.R1, 4));
            Assert.AreEqual(374.60m, Math.Round((decimal)r6.R2, 4));
            Assert.AreEqual(376.96m, Math.Round((decimal)r6.R3, 4));
        }