Esempio n. 1
0
        private List <CandleData> GetCandles(BarSettings timeframe, string symbol, DateTime date, int candlesCount)
        {
            var startTime     = timeframe.GetDistanceTime(candlesCount, -1, date);
            var minuteCandles = AtomCandleStorage.Instance.GetAllMinuteCandles(symbol, startTime, date) ?? new List <CandleData>();

            var packer  = new CandlePacker(timeframe);
            var candles = new List <CandleData>();

            foreach (var minuteCandle in minuteCandles)
            {
                var candle = packer.UpdateCandle(minuteCandle);
                if (candle != null)
                {
                    candles.Add(candle);
                }
            }

            var tail = minuteCandles.Where(x => x.timeOpen > candles.Last().timeClose).ToArray();

            if (tail.Length > 0)
            {
                float open  = tail.First().open;
                float close = tail.Last().close;
                float high  = tail.Max(x => x.high);
                float low   = tail.Min(x => x.low);

                DateTime timeOpen  = tail.First().timeOpen;
                DateTime timeClose = tail.Last().timeClose;

                var currentCandel = new CandleData(open, high, low, close, timeOpen, timeClose);
                candles.Add(currentCandel);
            }

            return(candles);
        }
Esempio n. 2
0
            public CandleDataBidAsk UpdateCandle(QuoteData q)
            {
                var candleBid = packerBid.UpdateCandle(q.bid, q.time) ?? packerBid.CurrentCandle;
                var candleAsk = packerAsk.UpdateCandle(q.ask, q.time) ?? packerAsk.CurrentCandle;

                return(new CandleDataBidAsk(candleBid, candleAsk)
                {
                    timeClose = q.time
                });
            }
        /// <summary>
        /// упаковать котировки в свечки
        /// </summary>
        public void UpdateCandles(List<CandleData> minuteCandles)
        {
            chart.StockSeries.Data.Clear();
            // родной интервал равен m1 - не производить никаких действий
            if (Timeframe.IsAtomic)
            {
                foreach (var candle in minuteCandles)
                    chart.StockSeries.Data.Candles.Add(new CandleData(candle));
                return;
            }

            // упаковать m1 в свечи нужного ТФ
            candlePacker = new CandlePacker(chart.Timeframe);
            foreach (var minuteCandle in minuteCandles)
            {
                var candle = candlePacker.UpdateCandle(minuteCandle);
                if (candle != null) chart.StockSeries.Data.Candles.Add(candle);
            }
            // добавить незавершенную свечу
            var shouldAdd = true;
            if (chart.StockSeries.Data.Candles.Count > 0)
                if (chart.StockSeries.Data.Candles[chart.StockSeries.Data.Candles.Count - 1].timeOpen ==
                    candlePacker.CurrentCandle.timeOpen) shouldAdd = false;
            if (shouldAdd && candlePacker.CurrentCandle != null)
                chart.StockSeries.Data.Candles.Add(candlePacker.CurrentCandle);
        }
Esempio n. 4
0
        private List<float> GetTargetCandlesLengths(int candleLength)
        {
            var candlesM1 = AtomCandleStorage.Instance.GetAllMinuteCandles(chart.Symbol);
            if (candlesM1.Count < candleLength * 50) return null;

            var packer = new CandlePacker(new BarSettings { Intervals = new List<int> { candleLength } });
            var lengths = new List<float>();
            foreach (var cm1 in candlesM1)
            {
                var candle = packer.UpdateCandle(cm1);
                if (candle != null)
                    lengths.Add((float)Math.Log(candle.close / candle.open));
            }

            return lengths;
        }
Esempio n. 5
0
        private List<CandleData> MakeCandlesFromM1(BarSettings timeframe, string ticker, DateTime timeStart)
        {
            var result = new List<CandleData>();
            var minutes = candles[barSettingsCodeM1][ticker];
            var packer = new CandlePacker(timeframe);

            foreach (var canM1 in minutes)
            {
                var candle = packer.UpdateCandle(canM1);
                if (candle != null)
                    result.Add(candle);
            }

            return result.Where(c => c.timeOpen >= timeStart).ToList();
        }