Ejemplo n.º 1
0
        private void AddToBarList(OhlcvData newBar)
        {
            var length = BarList.Length;
            if (BarList[length - 1] != null) //Array Dolu
            {
                // Shift
                for (var i = 1; i < length; i++)
                {
                    BarList[i - 1] = BarList[i];
                }

                BarList[length - 1] = newBar;
            }
            else
            {
                for (var i = 0; i < length; i++)
                {
                    if (BarList[i] != null)
                        continue;

                    BarList[i] = newBar;
                    break;
                }
            }
        }
Ejemplo n.º 2
0
        private void AddToBarList(OhlcvData newBar)
        {
            var length = BarList.Length;

            if (BarList[length - 1] != null) //Array Dolu
            {
                // Shift
                for (var i = 1; i < length; i++)
                {
                    BarList[i - 1] = BarList[i];
                }

                BarList[length - 1] = newBar;
            }
            else
            {
                for (var i = 0; i < length; i++)
                {
                    if (BarList[i] != null)
                    {
                        continue;
                    }

                    BarList[i] = newBar;
                    break;
                }
            }
        }
Ejemplo n.º 3
0
        private bool PatternExists(OhlcvData[] barList)
        {
            var bar1 = barList[1];
            var bar2 = barList[2];
            var bar3 = barList[3];
            var candleStickHelper = new CandleStickHelper(_mqlApi, _symbol);

            if (bar3.Close - bar3.Open > candleStickHelper.AverageBody(1)
                && Math.Abs(bar2.Close - bar2.Open) < candleStickHelper.AverageBody(1) * 0.5
                    && bar2.Close > bar3.Close
                    && bar2.Open > bar3.Open
                    && bar1.Close < candleStickHelper.MidOpenClose(3)
                )
            {
                return true;
            }

            //if (bar3.Close - bar3.Open > candleStickHelper.AverageBody(1)
            //    && candleStickHelper.AverageBody(2) < candleStickHelper.AverageBody(1) * 0.1
            //        && bar2.Close > bar3.Close
            //        && bar2.Open > bar3.Open
            //        && bar1.Open < bar2.Close
            //        && bar1.Close < bar2.Close
            //    )
            //{
            //    return true;
            //}

            return false;
        }
Ejemplo n.º 4
0
        public OrderType GetOrderType(OhlcvData[] BarList)
        {
            var patternExists = PatternExists(BarList);
            if (patternExists)
            {
                return OrderType.Buy;
            }

            return OrderType.NoOrder;
        }
Ejemplo n.º 5
0
        private void PopulateBarList(string symbol)
        {
            for (int i = 0; i < BarList.Length; i++)
            {
                var open  = iOpen(symbol, 0, i);
                var high  = iHigh(symbol, 0, i);
                var low   = iLow(symbol, 0, i);
                var close = iClose(symbol, 0, i);

                BarList[i] = new OhlcvData
                {
                    Open  = open,
                    High  = high,
                    Low   = low,
                    Close = close
                };
            }
        }
Ejemplo n.º 6
0
        private bool PatternExists(OhlcvData[] barList)
        {
            var bar1 = barList[1];
            var bar2 = barList[2];
            var bar3 = barList[3];
            var candleStickHelper = new CandleStickHelper(_mqlApi, _symbol);

            if (bar3.Close - bar3.Open > candleStickHelper.AverageBody(1)
                && candleStickHelper.AverageBody(2) < candleStickHelper.AverageBody(1) * 0.1
                    && bar2.Close > bar3.Close
                    && bar2.Open > bar3.Open
                    && bar1.Open < bar2.Close
                    && bar1.Close < bar2.Close
                )
            {
                return true;
            }

            return false;
        }
Ejemplo n.º 7
0
        private bool PatternExists(OhlcvData[] barList)
        {
            var lastBar = barList[1];
            var previousBar = barList[2];

            if (lastBar == null || previousBar == null)
            {
                return false;
            }

            if (lastBar.Open < lastBar.Close
                 && previousBar.Open > previousBar.Close
                 && lastBar.Open < previousBar.Close
                 && lastBar.Close > previousBar.Open
                 && lastBar.Low < previousBar.Low
                 && lastBar.High > previousBar.High
                )
            {
                return true;
            }

            return false;
        }
Ejemplo n.º 8
0
        private void PopulateBarList(string symbol)
        {
            for (int i = 0; i < BarList.Length; i++)
            {
                var open = iOpen(symbol, 0, i);
                var high = iHigh(symbol, 0, i);
                var low = iLow(symbol, 0, i);
                var close = iClose(symbol, 0, i);

                BarList[i] = new OhlcvData
                {
                    Open = open,
                    High = high,
                    Low = low,
                    Close = close
                };
            }
        }
Ejemplo n.º 9
0
        private void GetData2(Info.CryptoCompare.HistoType type)
        {
            string exchange = "Cryptopia";

            canvas.Children.Clear();
            MarketPair mp = GetMarketPair();
            List <Info.CryptoCompare.HistoMinuteData> dat;
            string histoLimit = txtlimit.Text;
            int    period     = Convert.ToInt32(txtPeriod.Text);

            string cacheKey = exchange + "-" + type.ToString() + "-" + histoLimit + ":" + mp.MarketCurrency + "-" + mp.BaseCurrency;

            if (cache.ContainsKey(cacheKey))
            {
                dat = cache[cacheKey];
            }
            else
            {
                Info.CryptoCompare.Api api = new Info.CryptoCompare.Api();
                dat = api.GetHistoData(mp.MarketCurrency, mp.BaseCurrency, exchange, type, histoLimit);
                cache.Add(cacheKey, dat);
            }

            List <OhlcvData> data      = new List <OhlcvData>();
            OhlcvData        tempOhlcv = new OhlcvData();
            int    periodCounter       = 0;
            double s = 100000000;

            foreach (Info.CryptoCompare.HistoMinuteData d in dat)
            {
                DateTime time = Info.CryptoCompare.Dates.FromUnixTime(d.Time);
                if (period == 1)
                {
                    data.Add(new OhlcvData(d.Open * s, d.High * s, d.Low * s, d.Close * s, d.VolumeFrom, d.VolumeTo, time));
                }
                else
                {
                    if (periodCounter == 0)
                    {
                        tempOhlcv = new OhlcvData(d.Open * s, d.High * s, d.Low * s, d.Close * s, d.VolumeFrom, d.VolumeTo, time);
                        periodCounter++;
                    }
                    else
                    {
                        if (periodCounter == period - 1)
                        {
                            OhlcvData dd = new OhlcvData(d.Open * s, d.High * s, d.Low * s, d.Close * s, d.VolumeFrom, d.VolumeTo, time);
                            if (tempOhlcv.High < dd.High)
                            {
                                tempOhlcv.High = dd.High;
                            }
                            if (tempOhlcv.Low > dd.Low)
                            {
                                tempOhlcv.Low = dd.Low;
                            }
                            tempOhlcv.Close      = dd.Close;
                            tempOhlcv.VolumeTo   = dd.VolumeTo;
                            tempOhlcv.VolumeFrom = dd.VolumeFrom;
                            data.Add(tempOhlcv);
                            periodCounter = 0;
                        }
                        else
                        {
                            periodCounter++;
                        }
                    }
                }
            }


            Rectangle rect = new Rectangle();

            rect.Stroke          = new SolidColorBrush(Colors.Gray);
            rect.StrokeThickness = 2;
            rect.Fill            = new SolidColorBrush(Colors.GhostWhite);
            rect.Width           = canvas.Width;
            rect.Height          = canvas.Height;
            Canvas.SetLeft(rect, 0);
            Canvas.SetTop(rect, 0);
            canvas.Children.Add(rect);
            Bounds bounds = GetBounds(data);

            int height    = Convert.ToInt32(Math.Ceiling(RoundUp(bounds.High) - RoundDown(bounds.Low)));
            int volheight = Convert.ToInt32(Math.Ceiling(RoundUp(bounds.VolHigh) - RoundDown(bounds.VolLow)));

            if (volheight == 0)
            {
                volheight = 1;
            }
            if (volheight > 10)
            {
                volheight = (volheight % 10) * 1000;
            }
            if (volheight == 0)
            {
                volheight = 1000;
            }
            if (volheight == 10)
            {
                volheight = 10;
            }
            if (height == 0)
            {
                height = 1;
            }
            double horizontalMargin = 30;
            double scale            = (canvas.Height - horizontalMargin) / height;
            double volscale         = (canvas.Height - horizontalMargin) / volheight;
            double linespace        = Math.Floor((double)height / 10);

            if (linespace == 0)
            {
                linespace = 1;
            }

            double       left        = 0;
            int          space       = 5;
            double       candlewidth = Math.Floor(canvas.Width / data.Count) - 5;
            int          wickwidth   = 1;
            List <Label> labels      = new List <Label>();

            double chartHeight = canvas.Height - horizontalMargin;

            for (double i = bounds.High; i >= bounds.Low; i -= linespace)
            {
                double top = (bounds.High - i) / height * chartHeight;
                top += horizontalMargin;
                Rectangle l = new Rectangle();
                l.Stroke          = new SolidColorBrush(Color.FromArgb(200, 128, 128, 128));
                l.StrokeThickness = 1;
                l.Fill            = new SolidColorBrush(Color.FromArgb(200, 128, 128, 128));
                l.Width           = canvas.Width;
                l.Height          = 1;
                Canvas.SetLeft(l, 0);
                Canvas.SetTop(l, top);
                canvas.Children.Add(l);
                Label label = new Label();
                label.Content    = (i / s).ToString("F8");
                label.Foreground = new SolidColorBrush(Colors.Gray);
                Canvas.SetLeft(label, canvas.Width - 75);
                Canvas.SetTop(label, top - 10 - 10);
                //Canvas.SetTop(label, (bounds.High - i + horizontalMargin - linespace + (linespace * 0.3)) / height * chartHeight);
                labels.Add(label);
            }

            foreach (OhlcvData d in data)
            {
                left = left + space + candlewidth;
                Rectangle r    = new Rectangle();
                Rectangle wick = new Rectangle();
                r.StrokeThickness    = 1;
                wick.StrokeThickness = 1;
                double top;

                //volume stuff...
                Rectangle vol = new Rectangle();
                vol.StrokeThickness = 1;
                vol.Stroke          = new SolidColorBrush(Color.FromArgb(128, 128, 128, 128));
                vol.Fill            = new SolidColorBrush(Color.FromArgb(128, 128, 128, 128));
                vol.Width           = candlewidth;
                double scaledVolume = GetScaledVolume(d.VolumeTo);
                vol.Height = volscale * scaledVolume;

                Canvas.SetLeft(vol, left);
                Canvas.SetTop(vol, canvas.Height - (volscale * scaledVolume));
                canvas.Children.Add(vol);

                //candles and wicks
                if (d.Close != d.Open)
                {
                    if (d.Close > d.Open)
                    {
                        r.Stroke    = new SolidColorBrush(Colors.Green);
                        r.Fill      = new SolidColorBrush(Colors.Green);
                        wick.Stroke = new SolidColorBrush(Colors.Green);
                        wick.Fill   = new SolidColorBrush(Colors.Green);
                        top         = (bounds.High - d.Close) / height * chartHeight;
                        top        += horizontalMargin;
                        Canvas.SetTop(r, top);
                    }
                    else
                    {
                        r.Stroke    = new SolidColorBrush(Colors.Red);
                        r.Fill      = new SolidColorBrush(Colors.Red);
                        wick.Stroke = new SolidColorBrush(Colors.Red);
                        wick.Fill   = new SolidColorBrush(Colors.Red);
                        top         = (bounds.High - d.Open) / height * chartHeight;
                        top        += horizontalMargin;
                        Canvas.SetTop(r, top);
                    }

                    r.Width  = candlewidth;
                    r.Height = scale * Math.Abs(d.Open - d.Close);
                }
                else
                {
                    r.Stroke    = new SolidColorBrush(Colors.CornflowerBlue);
                    r.Fill      = new SolidColorBrush(Colors.CornflowerBlue);
                    wick.Stroke = new SolidColorBrush(Colors.CornflowerBlue);
                    wick.Fill   = new SolidColorBrush(Colors.CornflowerBlue);

                    if (height != 0 && bounds.High - d.Close != 0)
                    {
                        top  = (bounds.High - d.Close) / height * chartHeight;
                        top += horizontalMargin;
                    }
                    else
                    {
                        top = canvas.Height / 2;
                    }
                    Canvas.SetTop(r, top);

                    if (height != 0 && bounds.High - d.High != 0)
                    {
                        top  = (bounds.High - d.High) / height * chartHeight;
                        top += horizontalMargin;
                    }
                    else
                    {
                        top = canvas.Height / 2;
                    }

                    Canvas.SetTop(wick, top);
                    r.Width  = candlewidth;
                    r.Height = 1;
                }

                wick.Width = wickwidth;

                if (d.High != d.Low)
                {
                    wick.Height = scale * Math.Abs(d.High - d.Low);
                }
                else
                {
                    wick.Height = 1;
                }

                if (height != 0)
                {
                    top  = (bounds.High - d.High) / height * chartHeight;
                    top += horizontalMargin;
                }
                else
                {
                    top = canvas.Height / 2;
                }

                Canvas.SetTop(wick, top);

                Canvas.SetLeft(r, left);
                Canvas.SetLeft(wick, left + (candlewidth / 2));

                canvas.Children.Add(r);
                canvas.Children.Add(wick);
            }

            foreach (Label l in labels)
            {
                canvas.Children.Add(l);
            }
        }