Esempio n. 1
0
        public void CandleUpdate(DateTime time, double open, double close, double high, double low, bool end)
        {
            if (CurrentCandle == null || time != CurrentCandle.Time)
            {
                if (AverageOpen > 0 && Candles.Count >= AverageOpen)
                {
                    var up = CurrentCandle.Close > CurrentCandle.Open;

                    open = Candles.Reverse().Take(AverageOpen).Average(c => (c.Close + (up ? c.Low : c.High)) / 2);
                }

                CurrentCandle = new CandleData
                {
                    Time      = time,
                    Open      = open,
                    Close     = close,
                    High      = high,
                    Low       = low,
                    LastPrice = close
                };
            }
            else
            {
                CurrentCandle.Close     = close;
                CurrentCandle.High      = high;
                CurrentCandle.Low       = low;
                CurrentCandle.LastPrice = close;
            }
        }
Esempio n. 2
0
        public void AddTick(double bid, double ask)
        {
            var price     = (bid + ask) / 2;
            var lastPrice = price;

            if (CurrentCandle == null || _currentCount >= TicksCount || (MaxSeconds > 0 && DateTime.Now.Subtract(_currentTime).TotalSeconds > MaxSeconds))
            {
                if (AverageOpen > 0 && Candles.Count >= AverageOpen)
                {
                    var up = CurrentCandle.Close > CurrentCandle.Open;

                    price = Candles.Reverse().Take(AverageOpen).Average(c => (c.Close + (up ? c.Low : c.High)) / 2);
                }

                CurrentCandle = new CandleData
                {
                    Time      = DateTime.Now,
                    Open      = price,
                    Close     = lastPrice,
                    High      = lastPrice,
                    Low       = lastPrice,
                    LastPrice = lastPrice,
                    HasBidAsk = true,
                    Bid       = bid,
                    Ask       = ask
                };

                _currentCount = 1;
                _currentTime  = DateTime.Now;
            }
            else
            {
                CurrentCandle.Close     = price;
                CurrentCandle.High      = Math.Max(Math.Max(CurrentCandle.High, lastPrice), price);
                CurrentCandle.Low       = Math.Min(Math.Min(CurrentCandle.Low, lastPrice), price);
                CurrentCandle.LastPrice = lastPrice;
                CurrentCandle.Bid       = bid;
                CurrentCandle.Ask       = ask;

                _currentCount++;
            }
        }