public void GetHeikinAshiTest()
        {
            IEnumerable <HeikinAshiResult> results = Indicator.GetHeikinAshi(history);

            // assertions

            // should always be the same number of results as there is history
            Assert.AreEqual(502, results.Count());

            // sample value
            HeikinAshiResult r = results.Where(x => x.Index == 502).FirstOrDefault();

            Assert.AreEqual(241.3018m, Math.Round(r.Open, 4));
            Assert.AreEqual(245.54m, Math.Round(r.High, 4));
            Assert.AreEqual(241.3018m, Math.Round(r.Low, 4));
            Assert.AreEqual(244.6525m, Math.Round(r.Close, 4));
        }
예제 #2
0
        public void GetHeikinAshi()
        {
            List <HeikinAshiResult> results = Indicator.GetHeikinAshi(history).ToList();

            // assertions

            // should always be the same number of results as there is history
            Assert.AreEqual(502, results.Count);

            // sample value
            HeikinAshiResult r = results[501];

            Assert.AreEqual(241.3018m, Math.Round(r.Open, 4));
            Assert.AreEqual(245.54m, Math.Round(r.High, 4));
            Assert.AreEqual(241.3018m, Math.Round(r.Low, 4));
            Assert.AreEqual(244.6525m, Math.Round(r.Close, 4));
        }
예제 #3
0
        public HeikinAshi(HeikinAshiResult rawHeikinAshi)
        {
            // Hollow or green candles with no lower "shadows" indicate a strong uptrend:
            var isGreen = rawHeikinAshi.Close > rawHeikinAshi.Open;
            var isRed   = !isGreen;

            // calculate the body length relative to total length.
            var bodyLength     = Math.Abs(rawHeikinAshi.Close - rawHeikinAshi.Open);
            var totalLength    = Math.Abs(rawHeikinAshi.High - rawHeikinAshi.Low);
            var bodyPercentage = bodyLength / totalLength;

            this.signal = HeikinAshiSignal.FLAT;
            if (bodyPercentage >= 0.5m)
            {
                if (isGreen)
                {
                    var tailLength = Math.Abs((rawHeikinAshi.Open - rawHeikinAshi.Low) / rawHeikinAshi.Open);
                    if (tailLength < epsilon)
                    {
                        // bullish
                        this.signal = HeikinAshiSignal.STRONGBUY;
                    }
                    else
                    {
                        this.signal = HeikinAshiSignal.BUY;
                    }
                }

                if (isRed)
                {
                    var headLength = Math.Abs((rawHeikinAshi.High - rawHeikinAshi.Open) / rawHeikinAshi.High);
                    if (headLength < epsilon)
                    {
                        // bearish
                        this.signal = HeikinAshiSignal.STRONGSELL;
                    }
                    else
                    {
                        this.signal = HeikinAshiSignal.SELL;
                    }
                }
            }

            //Debug.WriteLine($"{rawHeikinAshi.Open:0.0000}, {rawHeikinAshi.High:0.0000}, {rawHeikinAshi.Low:0.0000}, {rawHeikinAshi.Close:0.0000}, {bodyPercentage:0.0000}, {this.signal}");
        }
예제 #4
0
    public void Standard()
    {
        List <HeikinAshiResult> results = quotes.GetHeikinAshi().ToList();

        // assertions

        // should always be the same number of results as there is quotes
        Assert.AreEqual(502, results.Count);

        // sample value
        HeikinAshiResult r = results[501];

        Assert.AreEqual(241.3018m, Math.Round(r.Open, 4));
        Assert.AreEqual(245.54m, Math.Round(r.High, 4));
        Assert.AreEqual(241.3018m, Math.Round(r.Low, 4));
        Assert.AreEqual(244.6525m, Math.Round(r.Close, 4));
        Assert.AreEqual(147031456m, r.Volume);
    }
예제 #5
0
        public void GetHeikinAshiTest()
        {
            IEnumerable <HeikinAshiResult> results = Indicator.GetHeikinAshi(history);

            // assertions

            // should always be the same number of results as there is history
            Assert.AreEqual(502, results.Count());

            // sample value
            HeikinAshiResult result = results.Where(x => x.Date == DateTime.Parse("12/31/2018")).FirstOrDefault();

            Assert.AreEqual((decimal)241.3018, Math.Round(result.Open, 4));
            Assert.AreEqual((decimal)245.54, Math.Round(result.High, 4));
            Assert.AreEqual((decimal)241.3018, Math.Round(result.Low, 4));
            Assert.AreEqual((decimal)244.6525, Math.Round(result.Close, 4));
            Assert.AreEqual(true, result.IsBullish);
            Assert.AreEqual(0, Math.Round(result.Weakness, 4));
        }